Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-08-19-00-06-22
[civicrm-core.git] / CRM / Core / BAO / OptionGroup.php
index 872f4b79e6d5ed3dc3c8a7ec4b0ccc2e9818f1cf..09592e0cfd6fe3ed872824f6ce736e2534f628c3 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -89,7 +89,11 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup {
    *
    * @return object
    */
-  static function add(&$params, &$ids) {
+  static function add(&$params, $ids = array()) {
+    if(empty($params['id'])){
+      $params['id'] = CRM_Utils_Array::value('optionGroup', $ids);
+    }
+
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
 
@@ -102,7 +106,6 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup {
       CRM_Core_DAO::executeQuery($query);
     }
 
-    $optionGroup->id = CRM_Utils_Array::value('optionGroup', $ids);
     $optionGroup->save();
     return $optionGroup;
   }
@@ -144,93 +147,5 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup {
     $optionGroup->find(TRUE);
     return $optionGroup->name;
   }
-
-  /**
-   * Function to copy the option group and values
-   *
-   * @param  String $component      - component page for which custom
-   *                                  option group and values need to be copied
-   * @param  int    $fromId         - component page id on which
-   *                                  basis copy is to be made
-   * @param  int    $toId           - component page id to be copied onto
-   * @param  int    $defaultId      - default custom value id on the
-   *                                  component page
-   * @param  String $discountSuffix - discount suffix for the discounted
-   *                                  option group
-   *
-   * @return int   $id              - default custom value id for the
-   *                                 copied component page
-   *
-   * @access public
-   * @static
-   */
-  static function copyValue($component, $fromId, $toId, $defaultId = FALSE, $discountSuffix = NULL) {
-    $page = '_page';
-    if ($component == 'event') {
-      //fix for CRM-3391.
-      //as for event we remove 'page' from group name.
-      $page = NULL;
-    }
-    elseif ($component == 'price') {
-      $page = '_field';
-    }
-
-    $fromGroupName = 'civicrm_' . $component . $page . '.amount.' . $fromId . $discountSuffix;
-    $toGroupName = 'civicrm_' . $component . $page . '.amount.' . $toId . $discountSuffix;
-
-    $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
-      $fromGroupName,
-      'id',
-      'name'
-    );
-    if ($optionGroupId) {
-      $copyOptionGroup = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionGroup',
-        array('name' => $fromGroupName),
-        array('name' => $toGroupName)
-      );
-
-      $copyOptionValue = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionValue',
-        array('option_group_id' => $optionGroupId),
-        array('option_group_id' => $copyOptionGroup->id)
-      );
-
-      if ($discountSuffix) {
-        $copyDiscount =& CRM_Core_DAO::copyGeneric( 'CRM_Core_DAO_Discount',
-          array(
-            'entity_id' => $fromId,
-            'entity_table' => 'civicrm_' . $component,
-            'option_group_id' => $optionGroupId,
-          ),
-          array(
-            'entity_id' => $toId,
-            'option_group_id' => $copyOptionGroup->id,
-          )
-        );
-      }
-
-      if ($defaultId) {
-        $query = "
-SELECT second.id default_id
-FROM civicrm_option_value first, civicrm_option_value second
-WHERE second.option_group_id =%1
-AND first.option_group_id =%2
-AND first.weight = second.weight
-AND first.id =%3
-";
-        $params = array(1 => array($copyOptionGroup->id, 'Int'),
-          2 => array($optionGroupId, 'Int'),
-          3 => array($defaultId, 'Int'),
-        );
-
-        $dao = CRM_Core_DAO::executeQuery($query, $params);
-
-        while ($dao->fetch()) {
-          $id = $dao->default_id;
-        }
-        return $id;
-      }
-      return FALSE;
-    }
-  }
 }