/** * Create or update a price_set * * @param array $params Associative array of property * name/value pairs to insert in new 'price_set' * @example PriceSetCreate.php Std Create example * * @return array api result array * {@getfields price_set_create} * @access public */ function civicrm_api3_price_set_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); // Handle price_set_entity if (!empty($result['id']) && !empty($params['entity_table']) && !empty($params['entity_id'])) { $entityId = $params['entity_id']; if (!is_array($params['entity_id'])) { $entityId = explode(',', $entityId); } foreach ($entityId as $eid) { $eid = (int) trim($eid); if ($eid) { CRM_Price_BAO_Set::addTo($params['entity_table'], $eid, $result['id']); } } } return $result; }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('payment_processor_id', $params) == CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type')) { CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).')); } // check for price set. $priceSetID = CRM_Utils_Array::value('price_set_id', $params); // get required fields. $fields = array('id' => $this->_id, 'is_recur' => false, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => false, 'is_pay_later' => false, 'is_recur_interval' => false, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => false, 'amount_block_is_active' => false); $resetFields = array(); if ($priceSetID) { $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount'); } if (!CRM_Utils_Array::value('is_recur', $params)) { $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit')); } foreach ($fields as $field => $defaultVal) { $val = CRM_Utils_Array::value($field, $params, $defaultVal); if (in_array($field, $resetFields)) { $val = $defaultVal; } if (in_array($field, array('min_amount', 'max_amount'))) { $val = CRM_Utils_Rule::cleanMoney($val); } $params[$field] = $val; } if ($params['is_recur']) { require_once 'CRM/Core/BAO/CustomOption.php'; $params['recur_frequency_unit'] = implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($params['recur_frequency_unit'])); $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, false); } require_once 'CRM/Contribute/BAO/ContributionPage.php'; $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $contributionPageID = $contributionPage->id; // prepare for data cleanup. $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = false; if ($this->_priceSetID) { $deletePriceSet = true; } if ($this->_pledgeBlockID) { $deletePledgeBlk = true; } if (!empty($this->_amountBlock)) { $deleteAmountBlk = true; } if ($contributionPageID) { require_once 'CRM/Price/BAO/Set.php'; require_once 'CRM/Core/OptionGroup.php'; require_once 'CRM/Pledge/BAO/PledgeBlock.php'; if (CRM_Utils_Array::value('amount_block_is_active', $params)) { // handle price set. if ($priceSetID) { // add/update price set. $deletePriceSet = false; CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { // process contribution amount block $deleteAmountBlk = false; $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (isset($values[$i]) && strlen(trim($values[$i])) > 0) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } CRM_Core_OptionGroup::createAssoc("civicrm_contribution_page.amount.{$contributionPageID}", $options, $params['default_amount_id']); if ($params['default_amount_id']) { CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageID, 'default_amount_id', $params['default_amount_id']); } if (CRM_Utils_Array::value('is_pledge_active', $params)) { $deletePledgeBlk = false; $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page')); if ($this->_pledgeBlockID) { $pledgeBlockParams['id'] = $this->_pledgeBlockID; } $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day'); foreach ($pledgeBlock as $key) { $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params); } $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, false); // create pledge block. require_once 'CRM/Pledge/BAO/PledgeBlock.php'; CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams); } } } // delete pledge block. if ($deletePledgeBlk) { CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID); } // delete previous price set. if ($deletePriceSet) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID); } // delete amount block. if ($deleteAmountBlk) { CRM_Core_OptionGroup::deleteAssoc("civicrm_contribution_page.amount.{$contributionPageID}"); } } }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (array_key_exists('payment_processor', $params)) { if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type'), CRM_Utils_Array::value('payment_processor', $params))) { CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).')); } } // check for price set. $priceSetID = CRM_Utils_Array::value('price_set_id', $params); // get required fields. $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_recur_interval' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE); $resetFields = array(); if ($priceSetID) { $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount'); } if (!CRM_Utils_Array::value('is_recur', $params)) { $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit')); } foreach ($fields as $field => $defaultVal) { $val = CRM_Utils_Array::value($field, $params, $defaultVal); if (in_array($field, $resetFields)) { $val = $defaultVal; } if (in_array($field, array('min_amount', 'max_amount'))) { $val = CRM_Utils_Rule::cleanMoney($val); } $params[$field] = $val; } if ($params['is_recur']) { $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit'])); $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE); } if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) { $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor'])); } else { $params['payment_processor'] = 'null'; } $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $contributionPageID = $contributionPage->id; // prepare for data cleanup. $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE; if ($this->_priceSetID) { $deletePriceSet = TRUE; } if ($this->_pledgeBlockID) { $deletePledgeBlk = TRUE; } if (!empty($this->_amountBlock)) { $deleteAmountBlk = TRUE; } if ($contributionPageID) { if (CRM_Utils_Array::value('amount_block_is_active', $params)) { // handle price set. if ($priceSetID) { // add/update price set. $deletePriceSet = FALSE; if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) { $deleteAmountBlk = TRUE; } CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { $deletePriceSet = FALSE; // process contribution amount block $deleteAmountBlk = FALSE; $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (isset($values[$i]) && strlen(trim($values[$i])) > 0) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } /* || CRM_Utils_Array::value( 'price_field_value', $params )|| CRM_Utils_Array::value( 'price_field_other', $params )*/ if (!empty($options) || CRM_Utils_Array::value('is_allow_other_amount', $params)) { $fieldParams['is_quick_config'] = 1; $noContriAmount = NULL; $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3); if (!(CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) && !$usedPriceSetId) { $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245)); $setParams['title'] = $this->_values['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) { $setParams['name'] = $pageTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $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('CiviContribute'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetId = $priceSet->id; } elseif ($usedPriceSetId && !CRM_Utils_Array::value('price_field_id', $params)) { $priceSetId = $usedPriceSetId; } else { if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) { foreach ($params['price_field_value'] as $arrayID => $fieldValueID) { if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) { CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0'); unset($params['price_field_value'][$arrayID]); } } if (implode('', $params['price_field_value'])) { $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params); $fieldParams['option_id'] = $params['price_field_value']; } else { $noContriAmount = 0; CRM_Price_BAO_Field::setIsActive($priceFieldId, '0'); } } else { $priceFieldId = CRM_Utils_Array::value('price_field_other', $params); } $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceFieldId, 'price_set_id'); } CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetId); if (!empty($options)) { $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount'); $editedResults = array(); $noContriAmount = 1; CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!CRM_Utils_Array::value('id', $editedResults)) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245)); $fieldParams['label'] = "Contribution Amount"; } else { $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); } $fieldParams['price_set_id'] = $priceSetId; $fieldParams['is_active'] = 1; $fieldParams['weight'] = 2; if (CRM_Utils_Array::value('is_allow_other_amount', $params)) { $fieldParams['is_required'] = 0; } else { $fieldParams['is_required'] = 1; } $fieldParams['html_type'] = 'Radio'; $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; foreach ($options as $value) { $fieldParams['option_weight'][$value['weight']] = $value['weight']; } $fieldParams['default_option'] = $params['default']; $priceField = CRM_Price_BAO_Field::create($fieldParams); } if (CRM_Utils_Array::value('is_allow_other_amount', $params) && !CRM_Utils_Array::value('price_field_other', $params)) { $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount'); $editedResults = array(); CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) { $fieldParams = array('name' => 'other_amount', 'label' => 'Other Amount', 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'is_display_amounts' => 0, 'weight' => 3); $fieldParams['option_weight'][1] = 1; $fieldParams['option_amount'][1] = 1; if (!$noContriAmount) { $fieldParams['is_required'] = 1; $fieldParams['option_label'][1] = 'Contribution Amount'; } else { $fieldParams['is_required'] = 0; $fieldParams['option_label'][1] = 'Other Amount'; } $priceField = CRM_Price_BAO_Field::create($fieldParams); } else { if (!CRM_Utils_Array::value('is_active', $editedResults)) { CRM_Price_BAO_Field::setIsActive($priceFieldID, '1'); } } } elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0'); } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) { $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldID, 'id', 'price_field_id'); if (!$noContriAmount) { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 1); CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Contribution Amount'); } else { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 0); CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Other Amount'); } } } if (CRM_Utils_Array::value('is_pledge_active', $params)) { $deletePledgeBlk = FALSE; $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page')); if ($this->_pledgeBlockID) { $pledgeBlockParams['id'] = $this->_pledgeBlockID; } $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day'); foreach ($pledgeBlock as $key) { $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params); } $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE); // create pledge block. CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams); } } } else { if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) { $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3); if ($usedPriceSetId) { if (CRM_Utils_Array::value('price_field_id', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_id'], '0'); } if (CRM_Utils_Array::value('price_field_other', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0'); } } else { $deleteAmountBlk = TRUE; $deletePriceSet = TRUE; } } } // delete pledge block. if ($deletePledgeBlk) { CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID); } // delete previous price set. if ($deletePriceSet) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID); } if ($deleteAmountBlk) { $priceField = CRM_Utils_Array::value('price_field_id', $params) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params); if ($priceField) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceField, 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } } } parent::endPostProcess(); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false); $params['id'] = $this->_id; //new event, so lets set the created_id if ($this->_action & CRM_Core_Action::ADD) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); require_once 'CRM/Event/BAO/Event.php'; // copy all not explicitely set $params keys from the template (if it should be sourced) if (CRM_Utils_Array::value('template_id', $params)) { $defaults = array(); $templateParams = array('id' => $params['template_id']); CRM_Event_BAO_Event::retrieve($templateParams, $defaults); unset($defaults['id']); unset($defaults['default_fee_id']); unset($defaults['default_discount_fee_id']); foreach ($defaults as $key => $value) { if (!isset($params[$key])) { $params[$key] = $value; } } } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy event fees $ogParams = array('name' => "civicrm_event.amount.{$event->id}"); $defaults = array(); require_once 'CRM/Core/BAO/OptionGroup.php'; if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) { // Copy the Main Event Fees CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id); // Copy the Discount option Group and Values require_once 'CRM/Core/BAO/Discount.php'; $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event"); foreach ($optionGroupIds as $id) { $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label'); CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix); } } // copy price sets if any require_once 'CRM/Price/BAO/Set.php'; $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Core/BAO/UFJoin.php'; if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Friend/BAO/Friend.php'; if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") { $urlParam = "action=update&reset=1&id={$event->id}"; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam)); } parent::endPostProcess(); }
/** * Function to process price set and line items. * * @access public * @return None */ function processPriceSet($contributionId, $lineItem) { if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) { return; } require_once 'CRM/Price/BAO/Set.php'; require_once 'CRM/Price/BAO/LineItem.php'; foreach ($lineItem as $priceSetId => $values) { if (!$priceSetId) { continue; } foreach ($values as $line) { $line['entity_table'] = 'civicrm_contribution'; $line['entity_id'] = $contributionId; CRM_Price_BAO_LineItem::create($line); } CRM_Price_BAO_Set::addTo('civicrm_contribution', $contributionId, $priceSetId); } }
/** * This function is to make a copy of a Event, including * all the fields in the event Wizard * * @param int $id the event id to copy * * @return void * @access public */ static function copy($id) { $defaults = $eventValues = array(); //get the require event values. $eventParams = array('id' => $id); $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id'); CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties); // since the location is sharable, lets use the same loc_block_id. $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues); $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' ')); if (!CRM_Utils_Array::value('is_show_location', $eventValues)) { $fieldsFix['prefix']['is_show_location'] = 0; } $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix); $isQuickConfig = CRM_Price_BAO_Set::getFor('civicrm_event', $id, NULL, 1); if (!$isQuickConfig && $copyEvent->is_monetary) { $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $id); $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId); CRM_Price_BAO_Set::addTo('civicrm_event', $copyEvent->id, $copyPriceSet->id); } else { $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); } $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyPCP =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id), array('replace' => array('target_entity_id' => $copyEvent->id))); $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $id, 'mapping_id' => 3), array('entity_value' => $copyEvent->id)); //copy custom data $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $copyEvent->id; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$id}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } $copyEvent->save(); CRM_Utils_System::flushCache(); CRM_Utils_Hook::copy('Event', $copyEvent); return $copyEvent; }
/** * Process the form * * @return void * @access public */ public function postProcess() { $params = array(); $params = $this->exportValues(); $this->set('discountSection', 0); if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) { $this->buildAmountLabel(); $this->set('discountSection', 1); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage', '#isDiscount')); return; } $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0); if ($this->_id) { require_once 'CRM/Price/BAO/Set.php'; // delete all the prior label values or discounts in the custom options table // and delete a price set if one exists if (!CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) { require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}"); CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}.discount.%", "LIKE"); } } if ($params['is_monetary']) { if ($params['price_set_id']) { CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']); } else { // if there are label / values, create custom options for them $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($options)) { $params['default_fee_id'] = null; CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}", $options, $params['default_fee_id']); } } if (CRM_Utils_Array::value('is_discount', $params) == 1) { // if there are discounted set of label / values, // create custom options for them $labels = CRM_Utils_Array::value('discounted_label', $params); $values = CRM_Utils_Array::value('discounted_value', $params); $default = CRM_Utils_Array::value('discounted_default', $params); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) { $discountOptions = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && CRM_Utils_Array::value($j, $values[$i])) { $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($discountOptions)) { $params['default_discount_fee_id'] = null; $discountOptionsGroupId = CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}.discount.{$params['discount_name'][$j]}", $discountOptions, $params['default_discount_fee_id'], $params['discount_name'][$j]); $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $discountOptionsGroupId, 'start_date' => CRM_Utils_Date::format($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::format($params["discount_end_date"][$j])); require_once 'CRM/Core/BAO/Discount.php'; CRM_Core_BAO_Discount::add($discountParams); } } } } } } else { $params['contribution_type_id'] = ''; } //update events table require_once 'CRM/Event/BAO/Event.php'; $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), TRUE); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); $params['id'] = $this->_id; $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); //merge params with defaults from templates if (CRM_Utils_Array::value('template_id', $params)) { $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy price sets if any $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config'); if ($isQuickConfig) { $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId); $priceSetId = $copyPriceSet->id; } CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; if (isset($tafParams['id'])) { unset($tafParams['id']); } CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } //copy pcp settings CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id), array('replace' => array('target_entity_id' => $event->id))); //copy event schedule remainder CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $params['template_id']), array('entity_value' => $event->id)); } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $url = 'civicrm/event/manage/location'; $urlParams = "action=update&reset=1&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { $url = 'civicrm/event/manage'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } parent::endPostProcess(); }
/** * Process the form * * @return void * @access public */ public function postProcess() { $params = array(); $eventTitle = ''; $params = $this->exportValues(); $this->set('discountSection', 0); if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) { $this->buildAmountLabel(); $this->set('discountSection', 2); return; } if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) { $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor'])); } else { $params['payment_processor'] = 'null'; } $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0); if ($this->_id) { // delete all the prior label values or discounts in the custom options table // and delete a price set if one exists if (CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) { CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event'); } } if ($params['is_monetary']) { if (CRM_Utils_Array::value('price_set_id', $params)) { CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']); if (CRM_Utils_Array::value('price_field_id', $params)) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } } else { // if there are label / values, create custom options for them $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($options)) { $params['default_fee_id'] = NULL; if (!CRM_Utils_Array::value('price_set_id', $params)) { if (!CRM_Utils_Array::value('price_field_id', $params)) { $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle, 'id', 'title')) { $setParams['name'] = $setParams['title'] = $eventTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $this->_id, 'id', 'title')) { $setParams['name'] = $setParams['title'] = $eventTitle . '_' . $this->_id; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $setParams['title'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; $fieldParams['price_set_id'] = $priceSet->id; } else { foreach ($params['price_field_value'] as $arrayID => $fieldValueID) { if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) { CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0'); unset($params['price_field_value'][$arrayID]); } } $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params); $fieldParams['option_id'] = $params['price_field_value']; $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id'); } $fieldParams['html_type'] = 'Radio'; CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id); $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; foreach ($options as $value) { $fieldParams['option_weight'][$value['weight']] = $value['weight']; } $fieldParams['default_option'] = $params['default']; $priceField = CRM_Price_BAO_Field::create($fieldParams); } } } $discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array(); $discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array(); if (CRM_Utils_Array::value('is_discount', $params) == 1) { // if there are discounted set of label / values, // create custom options for them $labels = CRM_Utils_Array::value('discounted_label', $params); $values = CRM_Utils_Array::value('discounted_value', $params); $default = CRM_Utils_Array::value('discounted_default', $params); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) { $discountOptions = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !empty($values[$i][$j])) { $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($discountOptions)) { $fieldParams = array(); $params['default_discount_fee_id'] = NULL; $keyCheck = $j - 1; if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) { if (!$eventTitle) { $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200)); } $setParams['title'] = $params['discount_name'][$j]; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j]; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetID = $priceSet->id; } else { $priceSetID = $discountPriceSets[$j - 1]; unset($discountPriceSets[$j - 1]); $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id'); } $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; $fieldParams['is_required'] = 1; $fieldParams['price_set_id'] = $priceSetID; $fieldParams['html_type'] = 'Radio'; foreach ($discountOptions as $value) { $fieldParams['option_label'][$value['weight']] = $value['label']; $fieldParams['option_amount'][$value['weight']] = $value['value']; $fieldParams['option_weight'][$value['weight']] = $value['weight']; if (CRM_Utils_Array::value('is_default', $value)) { $fieldParams['default_option'] = $value['weight']; } if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'] - 1, $discountFieldIDs[$j])) { $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight'] - 1]; unset($discountFieldIDs[$j][$value['weight'] - 1]); } } //create discount priceset $priceField = CRM_Price_BAO_Field::create($fieldParams); if (!empty($discountFieldIDs)) { foreach ($discountFieldIDs as $fID) { CRM_Price_BAO_FieldValue::setIsActive($fID, '0'); } } $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::processDate($params["discount_end_date"][$j])); CRM_Core_BAO_Discount::add($discountParams); } } } } if (!empty($discountPriceSets)) { foreach ($discountPriceSets as $setId) { CRM_Price_BAO_Set::setIsQuickConfig($setId, 0); } } } } else { if (CRM_Utils_Array::value('price_field_id', $params)) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } $params['contribution_type_id'] = ''; } //update events table $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * * Function to create price sets */ static function createPriceSet($daoName, $addTo, $options = array()) { $query = "SELECT title FROM {$addTo[0]} where id =%1"; $setParams['title'] = CRM_Core_DAO::singleValueQuery($query, array(1 => array($addTo[2], 'Integer'))); $pageTitle = strtolower(CRM_Utils_String::munge($setParams['title'], '_', 245)); // an event or contrib page has been deleted but left the option group behind - (this may be fixed in later versions?) // we should probably delete the option group - but at least early exit here as the code following it does not fatal // CRM-10298 if (empty($pageTitle)) { return; } $optionValue = array(); if (CRM_Utils_Array::value('optionGroup', $options)) { CRM_Core_OptionGroup::getAssoc($options['optionGroup'], $optionValue); if (empty($optionValue)) { return; } } if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name', true)) { $setParams['name'] = $pageTitle; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['extends'] = $daoName[$addTo[0]][1]; $setParams['is_quick_config'] = 1; $priceSet = CRM_Price_BAO_Set::create($setParams); CRM_Price_BAO_Set::addTo($addTo[0], $addTo[2], $priceSet->id, 1); $fieldParams['price_set_id'] = $priceSet->id; if (CRM_Utils_Array::value('optionGroup', $options)) { $fieldParams['html_type'] = 'Radio'; $fieldParams['is_required'] = 1; if ($addTo[0] == 'civicrm_event') { $query = "SELECT fee_label FROM civicrm_event where id =%1"; $fieldParams['name'] = $fieldParams['label'] = CRM_Core_DAO::singleValueQuery($query, array(1 => array($addTo[2], 'Integer'))); $defaultAmountColumn = 'default_fee_id'; } else { $options['membership'] = 1; $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245)); $fieldParams['label'] = "Contribution Amount"; $defaultAmountColumn = 'default_amount_id'; $options['otherAmount'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $addTo[2], 'is_allow_other_amount'); if (CRM_Utils_Array::value('otherAmount', $options)) { $fieldParams['is_required'] = 0; } } $fieldParams['option_label'] = $optionValue['label']; $fieldParams['option_amount'] = $optionValue['value']; $fieldParams['option_weight'] = $optionValue['weight']; if ($defaultAmount = CRM_Core_DAO::getFieldValue($daoName[$addTo[0]][0], $addTo[2], $defaultAmountColumn)) { $fieldParams['default_option'] = array_search($defaultAmount, $optionValue['amount_id']); } $priceField = CRM_Price_BAO_Field::create($fieldParams); } if (CRM_Utils_Array::value('membership', $options)) { $dao = new CRM_Member_DAO_MembershipBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $addTo[2]; if ($dao->find(TRUE)) { if ($dao->membership_types) { $fieldParams = array('name' => strtolower(CRM_Utils_String::munge("Membership Amount", '_', 245)), 'label' => "Membership Amount", 'is_required' => $dao->is_required, 'is_display_amounts' => $dao->display_min_fee, 'is_active' => $dao->is_active, 'price_set_id' => $priceSet->id, 'html_type' => 'Radio', 'weight' => 1); $membershipTypes = unserialize($dao->membership_types); $rowcount = 0; foreach ($membershipTypes as $membershipType => $autoRenew) { $membershipTypeDetail = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipType); $rowcount++; $fieldParams['option_label'][$rowcount] = $membershipTypeDetail['name']; $fieldParams['option_amount'][$rowcount] = $membershipTypeDetail['minimum_fee']; $fieldParams['option_weight'][$rowcount] = $rowcount; $fieldParams['membership_type_id'][$rowcount] = $membershipType; if ($membershipType == $dao->membership_type_default) { $fieldParams['default_option'] = $rowcount; } } $priceField = CRM_Price_BAO_Field::create($fieldParams); $setParams = array('id' => $priceSet->id, 'extends' => CRM_Core_Component::getComponentID('CiviMember'), 'contribution_type_id' => CRM_Core_DAO::getFieldValue($daoName[$addTo[0]][0], $addTo[2], 'contribution_type_id')); CRM_Price_BAO_Set::create($setParams); } } } if (CRM_Utils_Array::value('otherAmount', $options)) { $fieldParams = array('name' => strtolower(CRM_Utils_String::munge("Other Amount", '_', 245)), 'label' => "Other Amount", 'is_required' => 0, 'is_display_amounts' => 0, 'is_active' => 1, 'price_set_id' => $priceSet->id, 'html_type' => 'Text', 'weight' => 3); $fieldParams['option_label'][1] = "Other Amount"; $fieldParams['option_amount'][1] = 1; $fieldParams['option_weight'][1] = 1; $priceField = CRM_Price_BAO_Field::create($fieldParams); } }
/** * Process the form * * @return void * @access public */ 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); } } } // check for price set. $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params); if (CRM_Utils_Array::value('member_is_active', $params) && is_array($membershipTypes) && !$priceSetID) { $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 2); if (!CRM_Utils_Array::value('mem_price_field_id', $params) && !$usedPriceSetId) { $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245)); $setParams['title'] = $this->_values['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) { $setParams['name'] = $pageTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $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['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetID = $priceSet->id; $fieldParams['price_set_id'] = $priceSet->id; } elseif ($usedPriceSetId) { $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember'); $setParams['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values); $setParams['id'] = $usedPriceSetId; $priceSet = CRM_Price_BAO_Set::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_Field', 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_Field::retrieve($editedFieldParams, $editedResults); if (!CRM_Utils_Array::value('id', $editedResults)) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245)); $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership Amount'; if (!CRM_Utils_Array::value('mem_price_field_id', $params)) { CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', 0, 1, array('price_set_id' => $priceSetID)); } $fieldParams['weight'] = 1; } else { $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); } $fieldParams['is_active'] = 1; $fieldParams['html_type'] = 'Radio'; $fieldParams['is_required'] = CRM_Utils_Array::value('is_required', $params) ? 1 : 0; $fieldParams['is_display_amounts'] = CRM_Utils_Array::value('display_min_fee', $params) ? 1 : 0; $rowCount = 1; $options = array(); if (CRM_Utils_Array::value('id', $fieldParams)) { CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_FieldValue', 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['membership_type_id'][$rowCount] = $memType; // [$rowCount] = $membetype['']; $rowCount++; } foreach ($options as $priceFieldID => $memType) { CRM_Price_BAO_FieldValue::setIsActive($priceFieldID, '0'); } $priceField = CRM_Price_BAO_Field::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_Set::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_Field', $conditionParams, $pFIDs); if (!CRM_Utils_Array::value('id', $pFIDs)) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id); CRM_Price_BAO_Set::setIsQuickConfig($this->_memPriceSetId, '0'); } else { CRM_Price_BAO_Field::setIsActive($params['mem_price_field_id'], '0'); } } } } parent::endPostProcess(); }