/** * Set default values for the form. * * For edit/view mode the default values are retrieved from the database. */ public function setDefaultValues() { $parentDefaults = parent::setDefaultValues(); $eventId = $this->_id; $params = array(); $defaults = array(); if (isset($eventId)) { $params = array('id' => $eventId); } CRM_Event_BAO_Event::retrieve($params, $defaults); if (isset($eventId)) { $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL, 1); if ($price_set_id) { $defaults['price_set_id'] = $price_set_id; } else { $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL); if ($priceSetId) { if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) { $this->assign('isQuick', $isQuick); $priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id'); $options = array(); $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField, $options, 'weight', TRUE); $defaults['price_field_id'] = $priceField; $countRow = 0; foreach ($options as $optionId => $optionValue) { $countRow++; $defaults['value'][$countRow] = CRM_Utils_Money::format($optionValue['amount'], NULL, '%a'); $defaults['label'][$countRow] = $optionValue['label']; $defaults['name'][$countRow] = $optionValue['name']; $defaults['weight'][$countRow] = $optionValue['weight']; $defaults['price_field_value'][$countRow] = $optionValue['id']; if ($optionValue['is_default']) { $defaults['default'] = $countRow; } } } } } } //check if discounted $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, 'civicrm_event'); if (!empty($discountedEvent)) { $defaults['is_discount'] = $i = 1; $totalLables = $maxSize = $defaultDiscounts = array(); foreach ($discountedEvent as $optionGroupId) { $defaults['discount_price_set'][] = $optionGroupId; $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title'); list($defaults["discount_start_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'price_set_id')); list($defaults["discount_end_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'price_set_id')); $defaultDiscounts[] = CRM_Price_BAO_PriceSet::getSetDetail($optionGroupId); $i++; } //avoid moving up value of lable when some labels don't //have a value ,fixed for CRM-3088 $rowCount = 1; foreach ($defaultDiscounts as $val) { $discountFields = current($val); $discountFields = current($discountFields['fields']); foreach ($discountFields['options'] as $discountFieldsval) { $defaults['discounted_label'][$discountFieldsval['weight']] = $discountFieldsval['label']; $defaults['discounted_value'][$discountFieldsval['weight']][$rowCount] = CRM_Utils_Money::format($discountFieldsval['amount'], NULL, '%a'); $defaults['discount_option_id'][$rowCount][$discountFieldsval['weight']] = $discountFieldsval['id']; if (!empty($discountFieldsval['is_default'])) { $defaults['discounted_default'] = $discountFieldsval['weight']; } } $rowCount++; } //CRM-12970 ksort($defaults['discounted_value']); ksort($defaults['discounted_label']); $rowCount = 1; foreach ($defaults['discounted_label'] as $key => $value) { if ($key != $rowCount) { $defaults['discounted_label'][$rowCount] = $value; $defaults['discounted_value'][$rowCount] = $defaults['discounted_value'][$key]; unset($defaults['discounted_value'][$key]); unset($defaults['discounted_label'][$key]); foreach ($defaults['discount_option_id'] as &$optionIds) { if (array_key_exists($key, $optionIds)) { $optionIds[$rowCount] = $optionIds[$key]; unset($optionIds[$key]); } } } $rowCount++; } $this->set('discountSection', 1); $this->buildQuickForm(); } elseif (!empty($defaults['label'])) { //if Regular Fees are present in DB and event fee page is in update mode $defaults['discounted_label'] = $defaults['label']; } elseif (!empty($this->_submitValues['label'])) { //if event is newly created, use submitted values for //discount labels if (is_array($this->_submitValues['label'])) { $k = 1; foreach ($this->_submitValues['label'] as $value) { if ($value) { $defaults['discounted_label'][$k] = $value; $k++; } } } } $defaults['id'] = $eventId; if (!empty($totalLables)) { $maxKey = count($totalLables) - 1; if (isset($maxKey) && !empty($totalLables[$maxKey]['value'])) { foreach ($totalLables[$maxKey]['value'] as $i => $v) { if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) { $defaults['discounted_default'] = $i; break; } } } } if (!isset($defaults['discounted_default'])) { $defaults['discounted_default'] = 1; } if (!isset($defaults['is_monetary'])) { $defaults['is_monetary'] = 1; } if (!isset($defaults['fee_label'])) { $defaults['fee_label'] = ts('Event Fee(s)'); } if (!isset($defaults['pay_later_text']) || empty($defaults['pay_later_text'])) { $defaults['pay_later_text'] = ts('I will send payment by check'); } $this->_showHide = new CRM_Core_ShowHideBlocks(); if (!$defaults['is_monetary']) { $this->_showHide->addHide('event-fees'); } if (isset($defaults['price_set_id'])) { $this->_showHide->addHide('map-field'); } $this->_showHide->addToTemplate(); $this->assign('inDate', $this->_inDate); if (!empty($defaults['payment_processor'])) { $defaults['payment_processor'] = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', $defaults['payment_processor']); } return $defaults; }
/** * Initiate event fee. * * @param CRM_Core_Form $form * @param int $eventID * * @throws Exception */ public static function initEventFee(&$form, $eventID) { // get price info // retrive all active price set fields. $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event'); if (property_exists($form, '_discountId') && $form->_discountId) { $discountId = $form->_discountId; } //CRM-16456 get all price field including expired one. $getAllPriceField = TRUE; $className = CRM_Utils_System::getClassName($form); if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action == CRM_Core_Action::UPDATE) { $getAllPriceField = FALSE; } if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId); } else { $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField); } if (property_exists($form, '_context') && ($form->_context == 'standalone' || $form->_context == 'participant')) { $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event'); if (is_array($discountedEvent)) { foreach ($discountedEvent as $key => $priceSetId) { $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId); $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet); $fieldID = key($form->_values['discount'][$key]); $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'title'); } } } $eventFee = CRM_Utils_Array::value('fee', $form->_values); if (!is_array($eventFee) || empty($eventFee)) { $form->_values['fee'] = array(); } //fix for non-upgraded price sets.CRM-4256. if (isset($form->_isPaidEvent)) { $isPaidEvent = $form->_isPaidEvent; } else { $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']); } if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !empty($form->_values['fee'])) { foreach ($form->_values['fee'] as $k => $fees) { foreach ($fees['options'] as $options) { if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) { unset($form->_values['fee'][$k]); } } } } if ($isPaidEvent && empty($form->_values['fee'])) { if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') { CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)))); } } }
/** * 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(); }
/** * 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); $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)); require_once "CRM/Core/BAO/OptionGroup.php"; //copy option Group and values $copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues)); //copy discounted fee levels require_once 'CRM/Core/BAO/Discount.php'; $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event'); if (!empty($discount)) { foreach ($discount as $discountOptionGroup) { $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup); $length = substr_compare($name, "civicrm_event.amount." . $id, 0); $discountSuffix = substr($name, $length * -1); $copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix); } } //copy custom data require_once 'CRM/Core/BAO/CustomGroup.php'; $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(); require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::copy('Event', $copyEvent); return $copyEvent; }
/** * Copy priceSet when event/contibution page is copied * * @param string $baoName * BAO name. * @param int $id * Old event/contribution page id. * @param int $newId * Newly created event/contribution page id. */ public static function copyPriceSet($baoName, $id, $newId) { $priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id); if ($priceSetId) { $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config'); if ($isQuickConfig) { $copyPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetId); CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id); } else { $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSetEntity', array('entity_id' => $id, 'entity_table' => $baoName), array('entity_id' => $newId)); } // copy event discount if ($baoName == 'civicrm_event') { $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event'); foreach ($discount as $discountId => $setId) { $copyPriceSet =& CRM_Price_BAO_PriceSet::copy($setId); CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('id' => $discountId), array('entity_id' => $newId, 'price_set_id' => $copyPriceSet->id)); } } } }
/** * @param $form * @param $eventID * * @throws Exception */ static function initEventFee(&$form, $eventID) { // get price info // retrive all active price set fields. $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event'); if (property_exists($form, '_discountId') && $form->_discountId) { $discountId = $form->_discountId; } if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId); } else { $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE); } if (property_exists($form, '_context') && ($form->_context == 'standalone' || $form->_context == 'participant')) { $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event'); if (is_array($discountedEvent)) { foreach ($discountedEvent as $key => $priceSetId) { $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId); $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet); $fieldID = key($form->_values['discount'][$key]); $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'title'); } } } $eventFee = CRM_Utils_Array::value('fee', $form->_values); if (!is_array($eventFee) || empty($eventFee)) { $form->_values['fee'] = array(); } //fix for non-upgraded price sets.CRM-4256. if (isset($form->_isPaidEvent)) { $isPaidEvent = $form->_isPaidEvent; } else { $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']); } if ($isPaidEvent && empty($form->_values['fee'])) { if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') { CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)))); } } }
static function initPriceSet(&$form, $eventID) { // get price info require_once 'CRM/Price/BAO/Set.php'; $price = CRM_Price_BAO_Set::initSet($form, $eventID, 'civicrm_event'); if ($price == false) { require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventID}", $form->_values['fee'], true); require_once 'CRM/Core/BAO/Discount.php'; $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, "civicrm_event"); if (is_array($discountedEvent)) { foreach ($discountedEvent as $key => $optionGroupId) { $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId); CRM_Core_OptionGroup::getAssoc($name, $form->_values['discount'][$key], true); $form->_values['discount'][$key]["name"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId, 'label'); } } } return $price; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $parentDefaults = parent::setDefaultValues(); $eventId = $this->_id; $params = array(); $defaults = array(); if (isset($eventId)) { $params = array('id' => $eventId); } CRM_Event_BAO_Event::retrieve($params, $defaults); if (isset($eventId)) { require_once 'CRM/Price/BAO/Set.php'; $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId); if ($price_set_id) { $defaults['price_set_id'] = $price_set_id; } else { require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventId}", $defaults); } } //check if discounted require_once 'CRM/Core/BAO/Discount.php'; $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, "civicrm_event"); if (!empty($discountedEvent)) { $defaults['is_discount'] = $i = 1; $totalLables = $maxSize = $defaultDiscounts = array(); foreach ($discountedEvent as $optionGroupId) { $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId, 'label'); $defaults["discount_start_date[{$i}]"] = CRM_Utils_Date::unformat(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'option_group_id')); $defaults["discount_end_date[{$i}]"] = CRM_Utils_Date::unformat(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'option_group_id')); CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventId}.discount.{$name}", $defaultDiscounts[]); $i++; } //avoid moving up value of lable when some labels don't //have a value ,fixed for CRM-3088 foreach ($defaultDiscounts as $key => $val) { $totalLables[$key]['label'] = $val['label']; $totalLables[$key]['value'] = $val['value']; $totalLables[$key]['amount_id'] = $val['amount_id']; foreach ($val['weight'] as $v) { //take array of weight for setdefault $discountWeight[$key][] = $v; } foreach ($val['value'] as $v) { //take array of available value for particular //discount set $discountValue[$key][] = $v; } //combining the weight with amount array for set default $discountDefualt[] = array_combine($discountWeight[$key], $discountValue[$key]); foreach ($discountDefualt[$key] as $k => $v) { $defaults["discounted_value"][$k][$key + 1] = $v; } $maxSize[$key] = sizeof($val['label']); } $maxKey = CRM_Utils_Array::key(max($maxSize), $maxSize); $defaults["discounted_label"] = $totalLables[$maxKey]['label']; $this->set('discountSection', 1); $this->buildQuickForm(); } else { if (!empty($defaults['label'])) { //if Regular Fees are present in DB and event fee page is in update mode $defaults["discounted_label"] = $defaults['label']; } else { if (CRM_Utils_Array::value('label', $this->_submitValues)) { //if event is newly created, use submitted values for //discount labels if (is_array($this->_submitValues['label'])) { $k = 1; foreach ($this->_submitValues['label'] as $value) { if ($value) { $defaults["discounted_label"][$k] = $value; $k++; } } } } } } $defaults = array_merge($defaults, $parentDefaults); $defaults['id'] = $eventId; if (CRM_Utils_Array::value('value', $defaults)) { foreach ($defaults['value'] as $i => $v) { if ($defaults['amount_id'][$i] == $defaults['default_fee_id']) { $defaults['default'] = $i; break; } } } if (!empty($totalLables)) { $maxKey = count($totalLables) - 1; if (isset($maxKey) && CRM_Utils_Array::value('value', $totalLables[$maxKey])) { foreach ($totalLables[$maxKey]['value'] as $i => $v) { if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) { $defaults['discounted_default'] = $i; break; } } } } if (!isset($defaults['default'])) { $defaults['default'] = 1; } if (!isset($defaults['discounted_default'])) { $defaults['discounted_default'] = 1; } if (!isset($defaults['is_monetary'])) { $defaults['is_monetary'] = 1; } if (!isset($defaults['fee_label'])) { $defaults['fee_label'] = ts('Event Fee(s)'); } if (!isset($defaults['pay_later_text']) || empty($defaults['pay_later_text'])) { $defaults['pay_later_text'] = ts('I will send payment by check'); } require_once 'CRM/Core/ShowHideBlocks.php'; $this->_showHide =& new CRM_Core_ShowHideBlocks(); if (!$defaults['is_monetary']) { $this->_showHide->addHide('event-fees'); } if (isset($defaults['price_set_id'])) { $this->_showHide->addHide('map-field'); } $this->_showHide->addToTemplate(); $this->assign('inDate', $this->_inDate); return $defaults; }
static function initEventFee(&$form, $eventID) { // get price info require_once 'CRM/Price/BAO/Set.php'; $price = CRM_Price_BAO_Set::initSet($form, $eventID, 'civicrm_event'); if ($price == false) { require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventID}", $form->_values['fee'], true); require_once 'CRM/Core/BAO/Discount.php'; $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, "civicrm_event"); if (is_array($discountedEvent)) { foreach ($discountedEvent as $key => $optionGroupId) { $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId); CRM_Core_OptionGroup::getAssoc($name, $form->_values['discount'][$key], true); $form->_values['discount'][$key]["name"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId, 'label'); } } } $eventFee = CRM_Utils_Array::value('fee', $form->_values); if (!is_array($eventFee) || empty($eventFee)) { $form->_values['fee'] = array(); } //fix for non-upgraded price sets.CRM-4256. if (isset($form->_isPaidEvent)) { $isPaidEvent = $form->_isPaidEvent; } else { $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']); } if ($isPaidEvent && empty($form->_values['fee'])) { CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)))); } }