/**
  * Creates a new entry in the database.
  *
  * @param array $params (reference), array $ids
  *
  * @return object CRM_Price_DAO_FieldValue object
  * @access public
  * @static
  */
 static function create(&$params, $ids)
 {
     if (!is_array($params) || empty($params)) {
         return;
     }
     if ($id = CRM_Utils_Array::value('id', $ids)) {
         if (isset($params['name'])) {
             unset($params['name']);
         }
         $oldWeight = null;
         if ($id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $id, 'weight', 'id');
         }
         $fieldValues = array('price_field_id' => CRM_Utils_Array::value('price_field_id', $params, 0));
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_FieldValue', $oldWeight, $params['weight'], $fieldValues);
     } else {
         if (!CRM_Utils_Array::value('name', $params)) {
             $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
         }
         $params['weight'] = 1;
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
     return self::add($params, $ids);
 }
Exemple #2
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
     $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
     if (isset($params['active_on'])) {
         $params['active_on'] = CRM_Utils_Date::processDate($params['active_on'], CRM_Utils_Array::value('active_on_time', $params), TRUE);
     }
     if (isset($params['expire_on'])) {
         $params['expire_on'] = CRM_Utils_Date::processDate($params['expire_on'], CRM_Utils_Array::value('expire_on_time', $params), TRUE);
     }
     $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
     $params['count'] = CRM_Utils_Array::value('count', $params, FALSE);
     // need the FKEY - price set id
     $params['price_set_id'] = $this->_sid;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $oldWeight = NULL;
         if ($this->_fid) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', $oldWeight, $params['weight'], $fieldValues);
     }
     // make value <=> name consistency.
     if (isset($params['option_name'])) {
         $params['option_value'] = $params['option_name'];
     }
     $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE);
     if ($params['html_type'] == 'Text') {
         // if html type is Text, force is_enter_qty on
         $params['is_enter_qty'] = 1;
         // modify params values as per the option group and option
         // value
         $params['option_amount'] = array(1 => $params['price']);
         $params['option_label'] = array(1 => $params['label']);
         $params['option_count'] = array(1 => $params['count']);
         $params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params));
         //$params['option_description']  = array( 1 => $params['description'] );
         $params['option_weight'] = array(1 => $params['weight']);
         $params['option_financial_type_id'] = array(1 => $params['financial_type_id']);
     }
     if ($this->_fid) {
         $params['id'] = $this->_fid;
     }
     $params['membership_num_terms'] = !empty($params['membership_type_id']) ? CRM_Utils_Array::value('membership_num_terms', $params, 1) : NULL;
     $priceField = CRM_Price_BAO_PriceField::create($params);
     if (!is_a($priceField, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)), ts('Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another price set field.'), '', 'info');
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
     }
 }
Exemple #3
0
 /**
  * Automatically determine one weight and modify others.
  *
  * @param array $params
  *   UFField record, e.g. with 'weight', 'uf_group_id', and 'field_id'.
  * @return int
  */
 public static function autoWeight($params)
 {
     // fix for CRM-316
     $oldWeight = NULL;
     if (!empty($params['field_id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $params['field_id'], 'weight', 'id');
     }
     $fieldValues = array('uf_group_id' => $params['group_id']);
     return CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_UFField', $oldWeight, CRM_Utils_Array::value('weight', $params, 0), $fieldValues);
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         try {
             CRM_Member_BAO_MembershipType::del($this->_id);
         } catch (CRM_Core_Exception $e) {
             CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Membership Type Not Deleted'));
         }
         CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $buttonName = $this->controller->getButtonName();
         $submitted = $this->controller->exportValues($this->_name);
         $fields = array('name', 'weight', 'is_active', 'member_of_contact_id', 'visibility', 'period_type', 'minimum_fee', 'description', 'auto_renew', 'duration_unit', 'duration_interval', 'financial_type_id', 'fixed_period_start_day', 'fixed_period_rollover_day', 'month_fixed_period_rollover_day', 'max_related');
         $params = $ids = array();
         foreach ($fields as $fld) {
             $params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
         }
         //clean money.
         if ($params['minimum_fee']) {
             $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
         }
         $hasRelTypeVal = FALSE;
         if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) {
             // To insert relation ids and directions with value separator
             $relTypeDirs = $submitted['relationship_type_id'];
             $relIds = $relDirection = array();
             foreach ($relTypeDirs as $key => $value) {
                 $relationId = explode('_', $value);
                 if (count($relationId) == 3 && is_numeric($relationId[0])) {
                     $relIds[] = $relationId[0];
                     $relDirection[] = $relationId[1] . '_' . $relationId[2];
                 }
             }
             if (!empty($relIds)) {
                 $hasRelTypeVal = TRUE;
                 $params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds);
                 $params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection);
             }
         }
         if (!$hasRelTypeVal) {
             $params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'NULL';
         }
         if ($params['duration_unit'] == 'lifetime' && empty($params['duration_interval'])) {
             $params['duration_interval'] = 1;
         }
         $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
         foreach ($periods as $per) {
             if (!empty($params[$per]['M']) && !empty($params[$per]['d'])) {
                 $mon = $params[$per]['M'];
                 $dat = $params[$per]['d'];
                 $mon = $mon < 10 ? '0' . $mon : $mon;
                 $dat = $dat < 10 ? '0' . $dat : $dat;
                 $params[$per] = $mon . $dat;
             } elseif ($per == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
                 $params['fixed_period_rollover_day'] = $params['month_fixed_period_rollover_day']['d'];
                 unset($params['month_fixed_period_rollover_day']);
             } else {
                 $params[$per] = 'NULL';
             }
         }
         $oldWeight = NULL;
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipType'] = $this->_id;
         }
         $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name)), ts('Saved'), 'success');
         $session = CRM_Core_Session::singleton();
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/member/membershipType/add', 'action=add&reset=1'));
         }
     }
 }
 /**
  * Add/edit option-value of a particular group
  *
  * @param array $params
  *   Array containing exported values from the invoking form.
  * @param array $groupParams
  *   Array containing group fields whose option-values is to retrieved/saved.
  * @param $action
  * @param int $optionValueID Has the id of the optionValue being edited, disabled ..etc.
  *   Has the id of the optionValue being edited, disabled ..etc.
  *
  * @return CRM_Core_DAO_OptionValue
  *
  */
 public static function addOptionValue(&$params, &$groupParams, &$action, &$optionValueID)
 {
     $ids = array();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     // checking if the group name with the given id or name (in $groupParams) exists
     if (!empty($groupParams)) {
         $config = CRM_Core_Config::singleton();
         $groupParams['is_active'] = 1;
         $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults);
     }
     // if the corresponding group doesn't exist, create one, provided $groupParams has 'name' in it.
     if (!$optionGroup->id) {
         if ($groupParams['name']) {
             $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams, $defaults);
             $params['weight'] = 1;
             $optionGroupID = $newOptionGroup->id;
         }
     } else {
         $optionGroupID = $optionGroup->id;
         $oldWeight = NULL;
         if ($optionValueID) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $optionValueID, 'weight', 'id');
         }
         $fieldValues = array('option_group_id' => $optionGroupID);
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues);
     }
     $params['option_group_id'] = $optionGroupID;
     if ($action & CRM_Core_Action::ADD && empty($params['value'])) {
         $fieldValues = array('option_group_id' => $optionGroupID);
         // use the next available value
         /* CONVERT(value, DECIMAL) is used to convert varchar
            field 'value' to decimal->integer                    */
         $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
     }
     if (!$params['label'] && $params['name']) {
         $params['label'] = $params['name'];
     }
     // set name to label if it's not set - but *only* for ADD action (CRM-3522)
     if ($action & CRM_Core_Action::ADD && empty($params['name']) && $params['label']) {
         $params['name'] = $params['label'];
     }
     if ($action & CRM_Core_Action::UPDATE) {
         $ids['optionValue'] = $optionValueID;
     }
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue;
 }
 /**
  * function to add the UF Field
  *
  * @param array $params (reference) array containing the values submitted by the form
  * @param array $ids    (reference) array containing the id
  *
  * @return object CRM_Core_BAO_UFField object
  *
  * @access public
  * @static
  *
  */
 static function add(&$params, &$ids)
 {
     // set values for uf field properties and save
     $ufField = new CRM_Core_DAO_UFField();
     $ufField->field_type = $params['field_name'][0];
     $ufField->field_name = $params['field_name'][1];
     //should not set location type id for Primary
     $locationTypeId = CRM_Utils_Array::value(2, $params['field_name']);
     if ($locationTypeId) {
         $ufField->location_type_id = $locationTypeId;
     } else {
         $ufField->location_type_id = 'null';
     }
     $ufField->phone_type_id = CRM_Utils_Array::value(3, $params['field_name'], 'NULL');
     $ufField->listings_title = CRM_Utils_Array::value('listings_title', $params);
     $ufField->visibility = CRM_Utils_Array::value('visibility', $params);
     $ufField->help_pre = CRM_Utils_Array::value('help_pre', $params);
     $ufField->help_post = CRM_Utils_Array::value('help_post', $params);
     $ufField->label = CRM_Utils_Array::value('label', $params);
     $ufField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE);
     $ufField->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
     $ufField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
     $ufField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
     $ufField->is_registration = CRM_Utils_Array::value('is_registration', $params, FALSE);
     $ufField->is_match = CRM_Utils_Array::value('is_match', $params, FALSE);
     $ufField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
     // fix for CRM-316
     $oldWeight = NULL;
     if (CRM_Utils_Array::value('field_id', $params)) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $params['field_id'], 'weight', 'id');
     }
     $fieldValues = array('uf_group_id' => $params['group_id']);
     $ufField->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_UFField', $oldWeight, $params['weight'], $fieldValues);
     // need the FKEY - uf group id
     $ufField->uf_group_id = CRM_Utils_Array::value('uf_group', $ids, FALSE);
     $ufField->id = CRM_Utils_Array::value('uf_field', $ids, FALSE);
     return $ufField->save();
 }
Exemple #7
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $urlParams = 'civicrm/admin/contribute/premium';
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         $single = $session->get('singleForm');
         CRM_Utils_System::redirect($url);
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         $dao = new CRM_Contribute_DAO_PremiumsProduct();
         $dao->id = $this->_pid;
         $dao->delete();
         CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success');
         CRM_Utils_System::redirect($url);
     } else {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         if ($this->_pid) {
             $params['id'] = $this->_pid;
         }
         $dao = new CRM_Contribute_DAO_Premium();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $premiumID = $dao->id;
         $params['premiums_id'] = $premiumID;
         $oldWeight = NULL;
         if ($this->_pid) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $this->_pid, 'weight', 'id');
         }
         // updateOtherWeights needs to filter on premiums_id
         $filter = array('premiums_id' => $params['premiums_id']);
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Contribute_DAO_PremiumsProduct', $oldWeight, $params['weight'], $filter);
         $dao = new CRM_Contribute_DAO_PremiumsProduct();
         $dao->copyValues($params);
         $dao->save();
         CRM_Utils_System::redirect($url);
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $this->_id);
         CRM_Member_BAO_MembershipType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'));
     } else {
         $buttonName = $this->controller->getButtonName();
         $submitted = $this->controller->exportValues($this->_name);
         $this->set('searchDone', 0);
         if ($buttonName == '_qf_MembershipType_refresh') {
             $this->search($submitted);
             $this->set('searchDone', 1);
             return;
         }
         $fields = array('name', 'weight', 'is_active', 'member_org', 'visibility', 'period_type', 'minimum_fee', 'description', 'auto_renew', 'autorenewal_msg_id', 'duration_unit', 'renewal_msg_id', 'duration_interval', 'renewal_reminder_day', 'contribution_type_id', 'fixed_period_start_day', 'fixed_period_rollover_day');
         $params = $ids = array();
         foreach ($fields as $fld) {
             $params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
         }
         //clean money.
         if ($params['minimum_fee']) {
             $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
         }
         $hasRelTypeVal = FALSE;
         if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) {
             // To insert relation ids and directions with value separator
             $relTypeDirs = $submitted['relationship_type_id'];
             $relIds = $relDirection = array();
             foreach ($relTypeDirs as $key => $value) {
                 $relationId = explode('_', $value);
                 if (count($relationId) == 3 && is_numeric($relationId[0])) {
                     $relIds[] = $relationId[0];
                     $relDirection[] = $relationId[1] . '_' . $relationId[2];
                 }
             }
             if (!empty($relIds)) {
                 $hasRelTypeVal = TRUE;
                 $params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds);
                 $params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection);
             }
         }
         if (!$hasRelTypeVal) {
             $params['relationship_type_id'] = $params['relationship_direction'] = 'NULL';
         }
         if ($params['duration_unit'] == 'lifetime' && empty($params['duration_interval'])) {
             $params['duration_interval'] = 1;
         }
         $config = CRM_Core_Config::singleton();
         $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
         foreach ($periods as $per) {
             if (CRM_Utils_Array::value('M', $params[$per]) && CRM_Utils_Array::value('d', $params[$per])) {
                 $mon = $params[$per]['M'];
                 $dat = $params[$per]['d'];
                 $mon = $mon < 9 ? '0' . $mon : $mon;
                 $dat = $dat < 9 ? '0' . $dat : $dat;
                 $params[$per] = $mon . $dat;
             } else {
                 $params[$per] = 'NULL';
             }
         }
         $oldWeight = NULL;
         $ids['memberOfContact'] = CRM_Utils_Array::value('contact_check', $submitted);
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipType'] = $this->_id;
         }
         $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name)));
         $session = CRM_Core_Session::singleton();
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             CRM_Core_Session::setStatus(ts(' You can add another membership type.'));
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/member/membershipType', 'action=add&reset=1'));
         }
     }
 }
Exemple #9
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/MembershipType.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $this->_id);
         CRM_Member_BAO_MembershipType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'));
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         $this->set('searchDone', 0);
         if (CRM_Utils_Array::value('_qf_MembershipType_refresh', $_POST)) {
             $this->search($params);
             $this->set('searchDone', 1);
             return;
         }
         $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
         if (CRM_Utils_Array::value('relationship_type_id', $params)) {
             $relationId = explode('_', $params['relationship_type_id']);
             $params['relationship_type_id'] = $relationId[0];
             $params['relationship_direction'] = $relationId[1] . '_' . $relationId[2];
         }
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipType'] = $this->_id;
         }
         if ($params['duration_unit'] == 'lifetime' and empty($params['duration_interval'])) {
             $params['duration_interval'] = 1;
         }
         $config =& CRM_Core_Config::singleton();
         $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
         foreach ($periods as $per) {
             if ($params[$per][$config->dateformatMonthVar] && $params[$per]['d']) {
                 $mon = $params[$per][$config->dateformatMonthVar];
                 $dat = $params[$per]['d'];
                 $mon = $mon < 9 ? '0' . $mon : $mon;
                 $dat = $dat < 9 ? '0' . $dat : $dat;
                 $params[$per] = $mon . $dat;
             } else {
                 $params[$per] = 'null';
             }
         }
         $oldWeight = null;
         $ids['memberOfContact'] = CRM_Utils_Array::value('contact_check', $params);
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']);
         $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name)));
     }
 }
 /**
  * takes an associative array and creates a custom group object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Core_DAO_CustomGroup object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     // create custom group dao, populate fields and then save.
     $group = new CRM_Core_DAO_CustomGroup();
     $group->title = $params['title'];
     require_once 'CRM/Utils/String.php';
     if (isset($params['name'])) {
         $group->name = $params['name'];
     } else {
         $maxLength = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'name');
         $group->name = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $maxLength));
     }
     if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) {
         $group->extends = 'Participant';
     } else {
         $group->extends = $params['extends'][0];
     }
     $group->extends_entity_column_id = null;
     if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') {
         $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
     }
     //this is format when form get submit.
     $extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
     //lets allow user to pass direct child type value, CRM-6893
     if (CRM_Utils_Array::value('extends_entity_column_value', $params)) {
         $extendsChildType = $params['extends_entity_column_value'];
     }
     if (!CRM_Utils_System::isNull($extendsChildType)) {
         $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
         if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
             $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType);
         }
         if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) {
             $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $extendsChildType = 'null';
     }
     $group->extends_entity_column_value = $extendsChildType;
     if (isset($params['id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     require_once 'CRM/Utils/Weight.php';
     $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, false));
     $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple');
     foreach ($fields as $field) {
         $group->{$field} = CRM_Utils_Array::value($field, $params, false);
     }
     $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null';
     $tableName = null;
     if (isset($params['id'])) {
         $group->id = $params['id'];
         //check whether custom group was changed from single-valued to multiple-valued
         $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple');
         if ($params['is_multiple'] != $isMultiple && (CRM_Utils_Array::value('is_multiple', $params) || $isMultiple)) {
             $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         }
     } else {
         $group->created_id = CRM_Utils_Array::value('created_id', $params);
         $group->created_date = CRM_Utils_Array::value('created_date', $params);
         require_once 'CRM/Utils/String.php';
         // lets create the table associated with the group and save it
         $tableName = $group->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group->title, '_', 32));
         // we do this only once, so name never changes
         $group->name = CRM_Utils_String::munge($params['title'], '_', 64);
     }
     // enclose the below in a transaction
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $group->save();
     if ($tableName) {
         // now append group id to table name, this prevent any name conflicts
         // like CRM-2742
         $tableName .= "_{$group->id}";
         $group->table_name = $tableName;
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName);
         // now create the table associated with this group
         self::createTable($group);
     } elseif ($oldTableName) {
         require_once 'CRM/Core/BAO/SchemaHandler.php';
         CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
     }
     if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
         $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         require_once 'CRM/Core/BAO/SchemaHandler.php';
         CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
     }
     $transaction->commit();
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     require_once 'CRM/Utils/Hook.php';
     if ($tableName) {
         CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group);
     }
     return $group;
 }
Exemple #11
0
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $dataTypeKey = $this->_defaultDataType[0];
         $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]];
         $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]];
     } else {
         $dataTypeKey = $params['data_type'][0];
         $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]];
         $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]];
     }
     //fix for 'is_search_range' field.
     if (in_array($dataTypeKey, array(1, 2, 3, 5))) {
         if (!CRM_Utils_Array::value('is_searchable', $params)) {
             $params['is_search_range'] = 0;
         }
     } else {
         $params['is_search_range'] = 0;
     }
     // fix for CRM-316
     $oldWeight = null;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('custom_group_id' => $this->_gid);
         if ($this->_id) {
             $oldWeight = $this->_values['weight'];
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues);
     }
     //store the primary key for State/Province or Country as default value.
     if (strlen(trim($params['default_value']))) {
         switch ($params['data_type']) {
             case 'StateProvince':
                 $fieldStateProvince = strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_state_province \n WHERE LOWER(name) = '{$fieldStateProvince}' \n    OR abbreviation = '{$fieldStateProvince}'";
                 $dao =& CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
             case 'Country':
                 $fieldCountry = strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}' \n    OR iso_code = '{$fieldCountry}'";
                 $dao =& CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
         }
     }
     // need the FKEY - custom group id
     $params['custom_group_id'] = $this->_gid;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $customField = CRM_Core_BAO_CustomField::create($params);
     // reset the cache
     require_once 'CRM/Core/BAO/Cache.php';
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)));
     $buttonName = $this->controller->getButtonName();
     $session =& CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another custom field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=add&gid=' . $this->_gid));
     }
 }
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected participant status has been deleted.'), ts('Record Deleted'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts('Selected participant status has <strong>NOT</strong> been deleted; there are still participants with this status.'), ts('Sorry'), 'error');
         }
         return;
     }
     $formValues = $this->controller->exportValues($this->_name);
     $params = array('name' => CRM_Utils_Array::value('name', $formValues), 'label' => CRM_Utils_Array::value('label', $formValues), 'class' => CRM_Utils_Array::value('class', $formValues), 'is_active' => CRM_Utils_Array::value('is_active', $formValues, FALSE), 'is_counted' => CRM_Utils_Array::value('is_counted', $formValues, FALSE), 'weight' => CRM_Utils_Array::value('weight', $formValues), 'visibility_id' => CRM_Utils_Array::value('visibility_id', $formValues));
     // make sure a malicious POST does not change these on reserved statuses
     if ($this->_isReserved) {
         unset($params['name'], $params['class'], $params['is_active']);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     if ($this->_id) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id, 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']);
     $participantStatus = CRM_Event_BAO_ParticipantStatusType::create($params);
     if ($participantStatus->id) {
         if ($this->_action & CRM_Core_Action::UPDATE) {
             CRM_Core_Session::setStatus(ts('The Participant Status has been updated.'), ts('Saved'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success');
         }
     } else {
         CRM_Core_Session::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success');
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $this->_id);
         CRM_Member_BAO_MembershipStatus::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'));
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipStatus'] = $this->_id;
         }
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
         // only for add mode, set label to name.
         if ($this->_action & CRM_Core_Action::ADD) {
             $params['name'] = $params['label'];
         }
         $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label)));
     }
 }
 /**
  * Creates a new entry in the database.
  *
  * @param array $params
  *   (reference), array $ids.
  *
  * @param $ids
  *
  * @return CRM_Price_DAO_PriceFieldValue
  */
 public static function create(&$params, $ids = array())
 {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     if (!is_array($params) || empty($params)) {
         return NULL;
     }
     if (!$id && empty($params['name'])) {
         $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
     }
     if ($id && !empty($params['weight'])) {
         if (isset($params['name'])) {
             unset($params['name']);
         }
         $oldWeight = NULL;
         if ($id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'weight', 'id');
         }
         $fieldValues = array('price_field_id' => CRM_Utils_Array::value('price_field_id', $params, 0));
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceFieldValue', $oldWeight, $params['weight'], $fieldValues);
     } else {
         if (!$id) {
             CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
             if (empty($params['name'])) {
                 $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
             }
         }
     }
     return self::add($params, $ids);
 }
Exemple #15
0
 public function upgrade_1105()
 {
     $this->ctx->log->info('Applying update 1105');
     $groups = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', 'custom_group_id', array('labelColumn' => 'name'));
     $customFieldID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'Is_Visa_Required', 'id', 'name');
     $customGroupID = array_search('Extended_Demographics', $groups);
     if ($customFieldID && $customGroupID) {
         CRM_Core_BAO_CustomField::moveField($customFieldID, $customGroupID);
         $result = civicrm_api3('CustomField', 'get', array('sequential' => 1, 'name' => 'Is_Visa_Required'));
         $weight = $result['values']['weight'];
         //fix the weight so that the field is next to nationality
         $fieldValues['custom_group_id'] = $customGroupID;
         CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $weight, 2, $fieldValues);
         $params = array('sequential' => 1, 'id' => $result['id'], 'is_active' => 1, 'html_type' => 'Radio', 'data_type' => 'Boolean', 'weight' => 2);
         $result = civicrm_api3('CustomField', 'create', $params);
     }
     return TRUE;
 }
Exemple #16
0
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Option');
     // set values for custom field properties and save
     require_once 'CRM/Core/DAO/OptionValue.php';
     require_once 'CRM/Utils/String.php';
     $customOption =& new CRM_Core_DAO_OptionValue();
     $customOption->label = $params['label'];
     $customOption->name = CRM_Utils_String::titleToVar($params['label']);
     $customOption->weight = $params['weight'];
     $customOption->value = $params['value'];
     $customOption->is_active = CRM_Utils_Array::value('is_active', $params, false);
     if ($this->_action == CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_optionGroupID);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         CRM_Core_BAO_CustomOption::del($this->_id);
         CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted', array(1 => $customOption->label)));
         return;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $customOption->id = $this->_id;
         CRM_Core_BAO_CustomOption::updateCustomValues($params);
     }
     if ($this->_id) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id');
     }
     $fieldValues = array('option_group_id' => $this->_optionGroupID);
     $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues);
     $customOption->option_group_id = $this->_optionGroupID;
     $customField =& new CRM_Core_DAO_CustomField();
     $customField->id = $this->_fid;
     if ($customField->find(true) && ($customField->html_type == 'CheckBox' || $customField->html_type == 'AdvMulti-Select' || $customField->html_type == 'Multi-Select')) {
         $defVal = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($customField->default_value, 1, -1));
         if (CRM_Utils_Array::value('default_value', $params)) {
             if (!in_array($customOption->value, $defVal)) {
                 if (empty($defVal[0])) {
                     $defVal = array($customOption->value);
                 } else {
                     $defVal[] = $customOption->value;
                 }
                 $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
                 $customField->save();
             }
         } else {
             if (in_array($customOption->value, $defVal)) {
                 $tempVal = array();
                 foreach ($defVal as $v) {
                     if ($v != $customOption->value) {
                         $tempVal[] = $v;
                     }
                 }
                 $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $tempVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
                 $customField->save();
             }
         }
     } else {
         switch ($customField->data_type) {
             case 'Money':
                 require_once 'CRM/Utils/Rule.php';
                 $customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value);
                 break;
             case 'Int':
                 $customOption->value = intval($customOption->value);
                 break;
             case 'Float':
                 $customOption->value = floatval($customOption->value);
                 break;
         }
         if (CRM_Utils_Array::value('default_value', $params)) {
             $customField->default_value = $customOption->value;
             $customField->save();
         } else {
             if ($customField->find(true) && $customField->default_value == $customOption->value) {
                 // this is the case where this option is the current default value and we have been reset
                 $customField->default_value = 'null';
                 $customField->save();
             }
         }
     }
     $customOption->save();
     CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label)));
     $buttonName = $this->controller->getButtonName();
     $session =& CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another option.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option', 'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid));
     }
 }
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         if ($this->_id && !empty($params['member_price_set_id'])) {
             CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
             if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(TRUE));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (empty($editedResults['id'])) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 if (empty($params['mem_price_field_id'])) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
             $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (!empty($fieldParams['id'])) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
             }
             foreach ($options as $priceFieldID => $memType) {
                 CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
             }
             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
         } elseif (!$priceSetID) {
             $deletePriceSet = 1;
         }
         $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
         if ($priceSetID) {
             $params['membership_types'] = 'null';
             $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
             $params['membership_types'] = serialize($membershipTypes);
             $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
             $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
         }
         $params['entity_table'] = 'civicrm_contribution_page';
         $params['entity_id'] = $this->_id;
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->copyValues($params);
         $dao->save();
         if ($priceSetID && $params['is_active']) {
             CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
         }
         if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
             if ($this->_memPriceSetId) {
                 $pFIDs = array();
                 $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
                 CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
                 if (empty($pFIDs['id'])) {
                     CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
                 } else {
                     CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
                 }
             }
         }
     }
     parent::endPostProcess();
 }
 /**
  * Process the form submission.
  *
  * @param array $params
  * @param string $type
  * @param array $linkedEntities
  *
  * @throws \CiviCRM_API3_Exception
  */
 public static function postProcess($params = array(), $type, $linkedEntities = array())
 {
     //Check entity_id not present in params take it from class variable
     if (empty($params['entity_id'])) {
         $params['entity_id'] = self::$_entityId;
     }
     //Process this function only when you get this variable
     if ($params['allowRepeatConfigToSubmit'] == 1) {
         if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) {
             $params['used_for'] = $type;
             if (empty($params['parent_entity_id'])) {
                 $params['parent_entity_id'] = self::$_parentEntityId;
             }
             if (!empty($params['schedule_reminder_id'])) {
                 $params['id'] = $params['schedule_reminder_id'];
             } else {
                 $params['id'] = self::$_scheduleReminderID;
             }
             //Save post params to the schedule reminder table
             $recurobj = new CRM_Core_BAO_RecurringEntity();
             $dbParams = $recurobj->mapFormValuesToDB($params);
             //Delete repeat configuration and rebuild
             if (!empty($params['id'])) {
                 CRM_Core_BAO_ActionSchedule::del($params['id']);
                 unset($params['id']);
             }
             $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
             //exclude dates
             $excludeDateList = array();
             if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
                 //Since we get comma separated values lets get them in array
                 $excludeDates = explode(",", $params['exclude_date_list']);
                 //Check if there exists any values for this option group
                 $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name');
                 if ($optionGroupIdExists) {
                     CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
                 }
                 $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1);
                 $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
                 if ($opGroup->id) {
                     $oldWeight = 0;
                     $fieldValues = array('option_group_id' => $opGroup->id);
                     foreach ($excludeDates as $val) {
                         $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1);
                         $excludeDateList[] = $optionGroupValue['value'];
                         CRM_Core_BAO_OptionValue::create($optionGroupValue);
                     }
                 }
             }
             //Set type for API
             $apiEntityType = explode("_", $type);
             if (!empty($apiEntityType[1])) {
                 $apiType = $apiEntityType[1];
             }
             //Delete relations if any from recurring entity tables before inserting new relations for this entity id
             if ($params['entity_id']) {
                 //If entity has any pre delete function, consider that first
                 if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id']));
                     if (!empty($preDeleteResult)) {
                         call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult));
                     }
                 }
                 //Ready to execute delete on entities if it has delete function set
                 if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     //Check if pre delete function has some ids to be deleted
                     if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
                         foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     } else {
                         $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
                         foreach ($getRelatedEntities as $key => $value) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id']));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     }
                 }
                 // find all entities from the recurring set. At this point we 'll get entities which were not deleted
                 // for e.g due to participants being present. We need to delete them from recurring tables anyway.
                 $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']);
                 foreach ($pRepeatingEntities as $val) {
                     CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE);
                 }
             }
             $recursion = new CRM_Core_BAO_RecurringEntity();
             $recursion->dateColumns = $params['dateColumns'];
             $recursion->scheduleId = $actionScheduleObj->id;
             if (!empty($excludeDateList)) {
                 $recursion->excludeDates = $excludeDateList;
                 $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns'];
             }
             if (!empty($params['intervalDateColumns'])) {
                 $recursion->intervalDateColumns = $params['intervalDateColumns'];
             }
             $recursion->entity_id = $params['entity_id'];
             $recursion->entity_table = $params['entity_table'];
             if (!empty($linkedEntities)) {
                 $recursion->linkedEntities = $linkedEntities;
             }
             $recursion->generate();
             $status = ts('Repeat Configuration has been saved');
             CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
         }
     }
 }
Exemple #19
0
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $dataTypeKey = $this->_defaultDataType[0];
         $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]];
         $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]];
     } else {
         $dataTypeKey = $params['data_type'][0];
         $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]];
         $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]];
     }
     //fix for 'is_search_range' field.
     if (in_array($dataTypeKey, array(1, 2, 3, 5))) {
         if (!CRM_Utils_Array::value('is_searchable', $params)) {
             $params['is_search_range'] = 0;
         }
     } else {
         $params['is_search_range'] = 0;
     }
     $filter = 'null';
     if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) {
         if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) {
             $filter = trim($params['filter']);
         } elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) {
             $filter = 'action=lookup&group=' . implode(',', $params['group_id']);
         }
     }
     $params['filter'] = $filter;
     // fix for CRM-316
     $oldWeight = NULL;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('custom_group_id' => $this->_gid);
         if ($this->_id) {
             $oldWeight = $this->_values['weight'];
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues);
     }
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     //store the primary key for State/Province or Country as default value.
     if (strlen(trim($params['default_value']))) {
         switch ($params['data_type']) {
             case 'StateProvince':
                 $fieldStateProvince = $strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_state_province\n WHERE LOWER(name) = '{$fieldStateProvince}'\n    OR abbreviation = '{$fieldStateProvince}'";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
             case 'Country':
                 $fieldCountry = $strtolower($params['default_value']);
                 $query = "\nSELECT id\n  FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}'\n    OR iso_code = '{$fieldCountry}'";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $params['default_value'] = $dao->id;
                 }
                 break;
         }
     }
     // The text_length attribute for Memo fields is in a different input as there
     // are different label, help text and default value than for other type fields
     if ($params['data_type'] == "Memo") {
         $params['text_length'] = $params['note_length'];
     }
     // need the FKEY - custom group id
     $params['custom_group_id'] = $this->_gid;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $customField = CRM_Core_BAO_CustomField::create($params);
     // reset the cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)), ts('Saved'), 'success');
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info');
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $this->_gid));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid));
     }
 }
Exemple #20
0
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     $params['name'] = CRM_Utils_String::titleToVar($params['label']);
     $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, false);
     $params['is_required'] = CRM_Utils_Array::value('is_required', $params, false);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['active_on'] = CRM_Utils_Date::format(CRM_Utils_Array::value('active_on', $params));
     $params['expire_on'] = CRM_Utils_Date::format(CRM_Utils_Array::value('expire_on', $params));
     $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, false);
     $params['count'] = CRM_Utils_Array::value('count', $params, false);
     // need the FKEY - price set id
     $params['price_set_id'] = $this->_sid;
     require_once 'CRM/Utils/Weight.php';
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $oldWeight = null;
         if ($this->_fid) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', $oldWeight, $params['weight'], $fieldValues);
     }
     // make value <=> name consistency.
     if (isset($params['option_name'])) {
         $params['option_value'] = $params['option_name'];
     }
     $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, false);
     if ($params['html_type'] == 'Text') {
         // if html type is Text, force is_enter_qty on
         $params['is_enter_qty'] = 1;
         // modify params values as per the option group and option
         // value
         $params['option_amount'] = array(1 => $params['price']);
         $params['option_label'] = array(1 => $params['label']);
         $params['option_count'] = array(1 => $params['count']);
         $params['option_max_value'] = array(1 => $params['max_value']);
         $params['option_description'] = array(1 => $params['description']);
         $params['option_weight'] = array(1 => $params['weight']);
         $params['is_active'] = array(1 => 1);
     }
     $ids = array();
     if ($this->_fid) {
         $ids['id'] = $this->_fid;
     }
     $priceField = CRM_Price_BAO_Field::create($params, $ids);
     if (!is_a($priceField, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)));
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another price set field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid));
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         try {
             CRM_Member_BAO_MembershipStatus::del($this->_id);
         } catch (CRM_Core_Exception $e) {
             CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed'));
         }
         CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipStatus'] = $this->_id;
         }
         $oldWeight = NULL;
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
         // only for add mode, set label to name.
         if ($this->_action & CRM_Core_Action::ADD) {
             $params['name'] = $params['label'];
         }
         $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label)), ts('Saved'), 'success');
     }
 }
 /**
  * Takes an associative array and creates a custom group object.
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Core_DAO_CustomGroup
  */
 public static function create(&$params)
 {
     // create custom group dao, populate fields and then save.
     $group = new CRM_Core_DAO_CustomGroup();
     if (isset($params['title'])) {
         $group->title = $params['title'];
     }
     if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) {
         $group->extends = 'Participant';
     } else {
         $group->extends = $params['extends'][0];
     }
     $group->extends_entity_column_id = 'null';
     if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') {
         $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
     }
     //this is format when form get submit.
     $extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
     //lets allow user to pass direct child type value, CRM-6893
     if (!empty($params['extends_entity_column_value'])) {
         $extendsChildType = $params['extends_entity_column_value'];
     }
     if (!CRM_Utils_System::isNull($extendsChildType)) {
         $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
         if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
             $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType);
         }
         if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) {
             $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $extendsChildType = 'null';
     }
     $group->extends_entity_column_value = $extendsChildType;
     if (isset($params['id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, FALSE));
     $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple');
     foreach ($fields as $field) {
         if (isset($params[$field]) || $field == 'is_multiple') {
             $group->{$field} = CRM_Utils_Array::value($field, $params, FALSE);
         }
     }
     $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null';
     $tableName = $oldTableName = NULL;
     if (isset($params['id'])) {
         $group->id = $params['id'];
         //check whether custom group was changed from single-valued to multiple-valued
         $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple');
         if ((!empty($params['is_multiple']) || $isMultiple) && $params['is_multiple'] != $isMultiple) {
             $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         }
     } else {
         $group->created_id = CRM_Utils_Array::value('created_id', $params);
         $group->created_date = CRM_Utils_Array::value('created_date', $params);
         // we do this only once, so name never changes
         if (isset($params['name'])) {
             $group->name = CRM_Utils_String::munge($params['name'], '_', 64);
         } else {
             $group->name = CRM_Utils_String::munge($group->title, '_', 64);
         }
         if (isset($params['table_name'])) {
             $tableName = $params['table_name'];
             if (CRM_Core_DAO_AllCoreTables::isCoreTable($tableName)) {
                 // Bad idea.  Prevent group creation because it might lead to a broken configuration.
                 CRM_Core_Error::fatal(ts("Cannot create custom table because %1 is already a core table.", array('1' => $tableName)));
             }
         }
     }
     if (array_key_exists('is_reserved', $params)) {
         $group->is_reserved = $params['is_reserved'] ? 1 : 0;
     }
     $op = isset($params['id']) ? 'edit' : 'create';
     CRM_Utils_Hook::pre($op, 'CustomGroup', CRM_Utils_Array::value('id', $params), $params);
     // enclose the below in a transaction
     $transaction = new CRM_Core_Transaction();
     $group->save();
     if (!isset($params['id'])) {
         if (!isset($params['table_name'])) {
             $munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 42));
             $tableName = "civicrm_value_{$munged_title}_{$group->id}";
         }
         $group->table_name = $tableName;
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName);
         // now create the table associated with this group
         self::createTable($group);
     } elseif ($oldTableName) {
         CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
     }
     if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
         $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
     }
     $transaction->commit();
     // reset the cache
     CRM_Utils_System::flushCache();
     if ($tableName) {
         CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group);
     }
     return $group;
 }