/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * * @return void */ function setDefaultValues() { //parent::setDefaultValues(); $defaults = array(); if (isset($this->_id)) { $defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); } $defaults['member_is_active'] = $defaults['is_active']; // Set Display Minimum Fee default to true if we are adding a new membership block if (!isset($defaults['id'])) { $defaults['display_min_fee'] = 1; } else { $this->assign('membershipBlockId', $defaults['id']); } if ($this->_id && ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3, 1))) { $defaults['member_price_set_id'] = $priceSetId; $this->_memPriceSetId = $priceSetId; } else { // for membership_types // if ( isset( $defaults['membership_types'] ) ) { $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3); $this->assign('isQuick', 1); $this->_memPriceSetId = $priceSetId; $pFIDs = array(); if ($priceSetId) { CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_Field', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name')); foreach ($pFIDs as $pid => $pValue) { if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') { $defaults['mem_price_field_id'] = $pValue['id']; } } if (CRM_Utils_Array::value('mem_price_field_id', $defaults)) { $options = array(); $priceFieldOptions = CRM_Price_BAO_FieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1); foreach ($options as $k => $v) { $newMembershipType[$v['membership_type_id']] = 1; if (!empty($defaults['auto_renew'])) { $defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']]; } } $defaults['membership_type'] = $newMembershipType; } } } return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * * @return void */ function setDefaultValues() { $defaults = parent::setDefaultValues(); $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); CRM_Utils_System::setTitle(ts('Contribution Amounts (%1)', array(1 => $title))); if (!CRM_Utils_Array::value('pay_later_text', $defaults)) { $defaults['pay_later_text'] = ts('I will send payment by check'); } if (CRM_Utils_Array::value('amount_block_is_active', $defaults)) { if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, NULL)) { if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config')) { $this->assign('isQuick', $isQuick); //$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_Field', $priceSetId, 'id', 'price_set_id' ); $options = $pFIDs = array(); $priceFieldParams = array('price_set_id' => $priceSetId); $priceFields = CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_Field', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'is_active')); foreach ($priceFields as $priceField) { if ($priceField['id'] && $priceField['html_type'] == 'Radio' && $priceField['name'] == 'contribution_amount') { $defaults['price_field_id'] = $priceField['id']; $priceFieldOptions = CRM_Price_BAO_FieldValue::getValues($priceField['id'], $options, 'id', 1); $countRow = 0; foreach ($options as $optionId => $optionValue) { $countRow++; $defaults['value'][$countRow] = $optionValue['amount']; $defaults['label'][$countRow] = CRM_Utils_Array::value('label', $optionValue); $defaults['name'][$countRow] = CRM_Utils_Array::value('name', $optionValue); $defaults['weight'][$countRow] = $optionValue['weight']; $defaults["price_field_value"][$countRow] = $optionValue['id']; if ($optionValue['is_default']) { $defaults['default'] = $countRow; } } } elseif ($priceField['id'] && $priceField['html_type'] == 'Text' && ($priceField['name'] = 'other_amount' && $priceField['is_active'])) { $defaults['price_field_other'] = $priceField['id']; } } } } if (CRM_Utils_Array::value('value', $defaults) && is_array($defaults['value'])) { // CRM-4038: fix value display foreach ($defaults['value'] as &$amount) { $amount = trim(CRM_Utils_Money::format($amount, ' ')); } } } // fix the display of the monetary value, CRM-4038 if (isset($defaults['min_amount'])) { $defaults['min_amount'] = CRM_Utils_Money::format($defaults['min_amount'], NULL, '%a'); } if (isset($defaults['max_amount'])) { $defaults['max_amount'] = CRM_Utils_Money::format($defaults['max_amount'], NULL, '%a'); } if (CRM_Utils_Array::value('payment_processor', $defaults)) { $defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['payment_processor']), '1'); } return $defaults; }
/** * Browse all price fields. * * @param null * * @return void * @access public */ function browse() { $customOption = array(); CRM_Price_BAO_FieldValue::getValues($this->_fid, $customOption); $config = CRM_Core_Config::singleton(); foreach ($customOption as $id => $values) { $action = array_sum(array_keys($this->actionLinks())); // update enable/disable links depending on price_field properties. if ($this->_isSetReserved) { $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE; } else { if ($values['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } } if (CRM_Utils_Array::value('is_default', $customOption[$id])) { $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />'; } else { $customOption[$id]['is_default'] = ''; } $customOption[$id]['order'] = $customOption[$id]['weight']; $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('oid' => $id, 'fid' => $this->_fid, 'sid' => $this->_sid)); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}"); $filter = "price_field_id = {$this->_fid}"; CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_FieldValue', 'id', $returnURL, $filter); $this->assign('customOption', $customOption); $this->assign('sid', $this->_sid); }
/** * Validate the priceset * * @param int $priceSetId, array $fields * * retrun the error string * * @access public * @static * */ public static function priceSetValidation($priceSetId, $fields, &$error) { // check for at least one positive // amount price field should be selected. $priceField = new CRM_Price_DAO_Field(); $priceField->price_set_id = $priceSetId; $priceField->find(); $priceFields = array(); while ($priceField->fetch()) { $key = "price_{$priceField->id}"; if (CRM_Utils_Array::value($key, $fields)) { $priceFields[$priceField->id] = $fields[$key]; } } if (!empty($priceFields)) { // we should has to have positive amount. $sql = "\nSELECT id, html_type \nFROM civicrm_price_field \nWHERE id IN (" . implode(',', array_keys($priceFields)) . ')'; $fieldDAO = CRM_Core_DAO::executeQuery($sql); $htmlTypes = array(); while ($fieldDAO->fetch()) { $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type; } $selectedAmounts = array(); require_once 'CRM/Price/BAO/FieldValue.php'; foreach ($htmlTypes as $fieldId => $type) { $options = array(); CRM_Price_BAO_FieldValue::getValues($fieldId, $options); if (empty($options)) { continue; } if ($type == 'Text') { foreach ($options as $opId => $option) { $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount']; break; } } else { if (is_array($fields["price_{$fieldId}"])) { foreach (array_keys($fields["price_{$fieldId}"]) as $opId) { $selectedAmounts[$opId] = $options[$opId]['amount']; } } else { if (in_array($fields["price_{$fieldId}"], array_keys($options))) { $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount']; } } } } list($componentName) = explode(':', $fields['_qf_default']); // now we have all selected amount in hand. $totalAmount = array_sum($selectedAmounts); if ($totalAmount < 0) { $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName)); } } else { $error['_qf_default'] = ts("Please select at least one option from price set."); } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $config = CRM_Core_Config::singleton(); // we first reset the confirm page so it accepts new values $this->controller->resetPage('Confirm'); // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('priceSetId', $params)) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config'); $formValue = array(); if ($is_quick_config) { $priceField = new CRM_Price_DAO_Field(); $priceField->price_set_id = $params['priceSetId']; $priceField->orderBy('weight'); $priceField->find(); $check = array(); $otherAmount = FALSE; while ($priceField->fetch()) { CRM_Price_BAO_FieldValue::getValues($priceField->id, $values); if ($priceField->name == "membership_amount") { if ($priceFiledID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) { $this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $values[$priceFiledID]); $this->set('selectMembership', CRM_Utils_Array::value('selectMembership', $params)); if (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) { $this->_values['amount'] = CRM_Utils_Array::value('amount', $values[$priceFiledID]); } } } if ($priceField->name == 'contribution_amount') { $priceFiledID = CRM_Utils_Array::value("price_{$priceField->id}", $params); if ($priceFiledID > 0 && !empty($priceFiledID)) { $params['amount'] = $priceFiledID; $this->_values['amount'] = CRM_Utils_Array::value('amount', $values[$priceFiledID]); $this->_values[$priceFiledID]['value'] = CRM_Utils_Array::value('amount', $values[$priceFiledID]); $this->_values[$priceFiledID]['label'] = CRM_Utils_Array::value('label', $values[$priceFiledID]); $this->_values[$priceFiledID]['amount_id'] = CRM_Utils_Array::value('id', $values[$priceFiledID]); $this->_values[$priceFiledID]['weight'] = CRM_Utils_Array::value('weight', $values[$priceFiledID]); } } if ($priceField->name == "other_amount" && ($priceFiledID = CRM_Utils_Array::value("price_{$priceField->id}", $params))) { $params['amount_other'] = $priceFiledID; } } } } if ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || CRM_Utils_Array::value('payment_processor', $params) == 0) { $params['is_pay_later'] = 1; } else { $params['is_pay_later'] = 0; } $this->set('is_pay_later', $params['is_pay_later']); // assign pay later stuff $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE); $this->assign('is_pay_later', $params['is_pay_later']); if ($params['is_pay_later']) { $this->assign('pay_later_text', $this->_values['pay_later_text']); $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']); } //carry campaign from profile. if (array_key_exists('contribution_campaign_id', $params)) { $params['campaign_id'] = $params['contribution_campaign_id']; } if (CRM_Utils_Array::value('onbehalfof_id', $params)) { $params['organization_id'] = $params['onbehalfof_id']; } $params['currencyID'] = $config->defaultCurrency; $params['amount'] = self::computeAmount($params, $this); $params['separate_amount'] = $params['amount']; $memFee = NULL; if (CRM_Utils_Array::value('selectMembership', $params)) { if (!empty($this->_membershipTypeValues)) { $membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']]; } else { $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $params['selectMembership']); } $memFee = $membershipTypeValues['minimum_fee']; if (!$params['amount'] && !$this->_separateMembershipPayment) { $params['amount'] = $memFee ? $memFee : 0; } } //If the membership & contribution is used in contribution page & not seperate payment $fieldId = $memPresent = $membershipLabel = $fieldOption = $proceFieldAmount = $is_quick_config = NULL; if ($this->_separateMembershipPayment == 0) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) { if ($fieldVal['name'] == 'membership_amount') { $fieldId = $fieldVal['id']; $fieldOption = $params['price_' . $fieldId]; $memPresent = TRUE; } else { if (CRM_Utils_Array::value('price_' . $fieldKey, $params) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) { $fieldId = $fieldVal['id']; if ($fieldVal['name'] == 'other_amount') { $proceFieldAmount = $this->_submitValues['price_' . $fieldId]; } else { $proceFieldAmount = $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount']; } unset($params['price_' . $fieldId]); break; } } } } } if (!isset($params['amount_other'])) { $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params)); } if ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) { $lineItem = array(); $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config'); if ($is_quick_config) { foreach ($this->_values['fee'] as $key => &$val) { if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && array_key_exists('price_' . $key, $params) && $params['price_' . $key] != 0) { foreach ($val['options'] as $optionKey => &$options) { $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params); break; } $params['price_' . $key] = 1; break; } } } CRM_Price_BAO_Set::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId]); if ($proceFieldAmount) { $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount; $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount; if (!$this->_membershipBlock['is_separate_payment']) { $params['amount'] = $proceFieldAmount; //require when separate membership not used } } $this->set('lineItem', $lineItem); } if ($this->_membershipBlock['is_separate_payment'] && CRM_Utils_Array::value('separate_amount', $params)) { $this->set('amount', $params['separate_amount']); } else { $this->set('amount', $params['amount']); } // generate and set an invoiceID for this transaction $invoiceID = md5(uniqid(rand(), TRUE)); $this->set('invoiceID', $invoiceID); // required only if is_monetary and valid postive amount if ($this->_values['is_monetary'] && is_array($this->_paymentProcessor) && ((double) $params['amount'] > 0.0 || $memFee > 0.0)) { // default mode is direct $this->set('contributeMode', 'direct'); if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) { //get the button name $buttonName = $this->controller->getButtonName(); if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && !CRM_Utils_Array::value('is_pay_later', $params)) { $this->set('contributeMode', 'express'); $donateURL = CRM_Utils_System::url('civicrm/contribute', '_qf_Contribute_display=1'); $params['cancelURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE); $params['returnURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Confirm_display=1&rfp=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE); $params['invoiceID'] = $invoiceID; //default action is Sale $params['payment_action'] = 'Sale'; $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); $token = $payment->setExpressCheckout($params); if (is_a($token, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($token); CRM_Utils_System::redirect($params['cancelURL']); } $this->set('token', $token); $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token={$token}"; CRM_Utils_System::redirect($paymentURL); } } elseif ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) { $this->set('contributeMode', 'notify'); } } // should we skip the confirm page? if (!CRM_Utils_Array::value('is_confirm_enabled', $this->_values)) { // build the confirm page $confirmForm =& $this->controller->_pages['Confirm']; $confirmForm->preProcess(); $confirmForm->buildQuickForm(); // the confirmation page is valid $data =& $this->controller->container(); $data['valid']['Confirm'] = 1; // confirm the contribution $confirmForm->postProcess(); $qfKey = $this->controller->_key; // redirect to thank you page CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$qfKey}", TRUE, NULL, FALSE)); } }
/** * 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)) { $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId, NULL, 1); if ($price_set_id) { $defaults['price_set_id'] = $price_set_id; } else { $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId, NULL); if ($priceSetId) { if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config')) { $this->assign('isQuick', $isQuick); $priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceSetId, 'id', 'price_set_id'); $options = array(); $priceFieldOptions = CRM_Price_BAO_FieldValue::getValues($priceField, $options, 'weight', true); $defaults['price_field_id'] = $priceField; $countRow = 0; foreach ($options as $optionId => $optionValue) { $countRow++; $defaults['value'][$countRow] = $optionValue['amount']; $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_Set', $optionGroupId, 'title'); list($defaults["discount_start_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'option_group_id')); list($defaults["discount_end_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'option_group_id')); $defaultDiscounts[] = CRM_Price_BAO_Set::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] = $discountFieldsval['amount']; $defaults['discount_option_id'][$rowCount][] = $discountFieldsval['id']; if (CRM_Utils_Array::value('is_default', $discountFieldsval)) { $defaults['discounted_default'] = $discountFieldsval['weight']; } } $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 (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['id'] = $eventId; 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['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 (CRM_Utils_Array::value('payment_processor', $defaults)) { $defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['payment_processor']), '1'); } return $defaults; }
/** * This method will create the lineItem array required for * processAmount method * * @param int $fid price set field id * @param array $params referance to form values * @param array $fields referance to array of fields belonging * to the price set used for particular event * @param array $values referance to the values array( this is * lineItem array) * * @return void * @access static */ static function format($fid, &$params, &$fields, &$values) { if (empty($params["price_{$fid}"])) { return; } $optionIDs = implode(',', array_keys($params["price_{$fid}"])); //lets first check in fun parameter, //since user might modified w/ hooks. $options = array(); if (array_key_exists('options', $fields)) { $options = $fields['options']; } else { CRM_Price_BAO_FieldValue::getValues($fid, $options, 'weight', TRUE); } $fieldTitle = CRM_Utils_Array::value('label', $fields); if (!$fieldTitle) { $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $fid, 'label'); } foreach ($params["price_{$fid}"] as $oid => $qty) { $price = $options[$oid]['amount']; // lets clean the price in case it is not yet cleant // CRM-10974 $price = CRM_Utils_Rule::cleanMoney($price); $participantsPerField = CRM_Utils_Array::value('count', $options[$oid], 0); $values[$oid] = array('price_field_id' => $fid, 'price_field_value_id' => $oid, 'label' => CRM_Utils_Array::value('label', $options[$oid]), 'field_title' => $fieldTitle, 'description' => CRM_Utils_Array::value('description', $options[$oid]), 'qty' => $qty, 'unit_price' => $price, 'line_total' => $qty * $price, 'participant_count' => $qty * $participantsPerField, 'max_value' => CRM_Utils_Array::value('max_value', $options[$oid]), 'membership_type_id' => CRM_Utils_Array::value('membership_type_id', $options[$oid]), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $options[$oid]), 'html_type' => $fields['html_type']); } }
/** * This method will create the lineItem array required for * processAmount method * * @param int $fid price set field id * @param array $params referance to form values * @param array $fields referance to array of fields belonging * to the price set used for particular event * @param array $values referance to the values array(this is * lineItem array) * * @return void * @access static */ static function format($fid, &$params, &$fields, &$values) { if (empty($params["price_{$fid}"])) { return; } $optionIDs = implode(',', array_keys($params["price_{$fid}"])); //lets first check in fun parameter, //since user might modified w/ hooks. $options = array(); if (array_key_exists('options', $fields)) { $options = $fields['options']; } else { require_once 'CRM/Price/BAO/FieldValue.php'; CRM_Price_BAO_FieldValue::getValues($fid, $options, 'weight', true); } $fieldTitle = CRM_Utils_Array::value('label', $fields); if (!$fieldTitle) { $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $fid, 'label'); } foreach ($params["price_{$fid}"] as $oid => $qty) { require_once 'CRM/Price/BAO/Field.php'; $price = $options[$oid]['amount']; $participantsPerField = CRM_Utils_Array::value('count', $options[$oid], 0); $values[$oid] = array('price_field_id' => $fid, 'price_field_value_id' => $oid, 'label' => $options[$oid]['label'], 'field_title' => $fieldTitle, 'description' => $options[$oid]['description'], 'qty' => $qty, 'unit_price' => $price, 'line_total' => $qty * $price, 'participant_count' => $qty * $participantsPerField, 'max_value' => CRM_Utils_Array::value('max_value', $options[$oid]), 'html_type' => $fields['html_type']); } }