<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*
* @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);
CRM_Core_DAO::executeQuery($query);
}
- $optionGroup->id = CRM_Utils_Array::value('optionGroup', $ids);
$optionGroup->save();
return $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;
- }
- }
}