function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_Set::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             $field_name = "event_{$event->id}_price_{$field['id']}";
             CRM_Price_BAO_Field::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
Exemplo n.º 2
0
 /** 
  * Function to build the price set form.
  * 
  * @return None 
  * @access public 
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $priceSet = self::getSetDetail($priceSetId, true);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->assign('priceSet', $form->_priceSet);
     foreach ($form->_priceSet['fields'] as $field) {
         CRM_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], false, CRM_Utils_Array::value('is_required', $field, false));
     }
 }
Exemplo n.º 3
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assign('groupTree', $this->_groupTree);
     // add the form elements
     require_once 'CRM/Price/BAO/Field.php';
     foreach ($this->_groupTree as $group) {
         if (is_array($group['fields']) && !empty($group['fields'])) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 CRM_Price_BAO_Field::addQuickFormElement($this, $elementName, $fieldId, false, $field['is_required']);
             }
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true)));
 }
 /**
  * build the radio/text form elements for the amount field
  *
  * @param object   $form form object
  * @param boolean  $required  true if you want to add formRule
  * @param int      $discountId discount id for the event
  *
  * @return void
  * @access public
  * @static
  */
 public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
 {
     //if payment done, no need to build the fee block.
     if (isset($form->_paymentId) && $form->_paymentId) {
         //fix to diaplay line item in update mode.
         $form->assign('priceSet', isset($form->_priceSet) ? $form->_priceSet : NULL);
         return;
     }
     $feeFields = CRM_Utils_Array::value('fee', $form->_values);
     if (is_array($feeFields)) {
         $form->_feeBlock =& $form->_values['fee'];
     }
     //check for discount.
     $discountedFee = CRM_Utils_Array::value('discount', $form->_values);
     if (is_array($discountedFee) && !empty($discountedFee)) {
         if (!$discountId) {
             $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
         }
         if ($discountId) {
             $form->_feeBlock =& $form->_values['discount'][$discountId];
         }
     }
     if (!is_array($form->_feeBlock)) {
         $form->_feeBlock = array();
     }
     //its time to call the hook.
     CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
     //reset required if participant is skipped.
     $button = substr($form->controller->getButtonName(), -4);
     if ($required && $button == 'skip') {
         $required = FALSE;
     }
     $className = CRM_Utils_System::getClassName($form);
     //build the priceset fields.
     if (isset($form->_priceSetId) && $form->_priceSetId) {
         //format price set fields across option full.
         self::formatFieldsForOptionFull($form);
         $form->add('hidden', 'priceSetId', $form->_priceSetId);
         foreach ($form->_feeBlock as $field) {
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || $className == 'CRM_Event_Form_Participant') {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 $isRequire = CRM_Utils_Array::value('is_required', $field);
                 if ($button == 'skip') {
                     $isRequire = FALSE;
                 }
                 //user might modified w/ hook.
                 $options = CRM_Utils_Array::value('options', $field);
                 if (!is_array($options)) {
                     continue;
                 }
                 $optionFullIds = CRM_Utils_Array::value('option_full_ids', $field, array());
                 //soft suppress required rule when option is full.
                 if (!empty($optionFullIds) && count($options) == count($optionFullIds)) {
                     $isRequire = FALSE;
                 }
                 //build the element.
                 CRM_Price_BAO_Field::addQuickFormElement($form, $elementName, $fieldId, FALSE, $isRequire, NULL, $options, $optionFullIds);
             }
         }
         $form->assign('priceSet', $form->_priceSet);
     } else {
         $eventFeeBlockValues = array();
         foreach ($form->_feeBlock as $fee) {
             if (is_array($fee)) {
                 //CRM-7632, CRM-6201
                 $totalAmountJs = NULL;
                 if ($className == 'CRM_Event_Form_Participant') {
                     $totalAmountJs = array('onClick' => "fillTotalAmount(" . $fee['value'] . ")");
                 }
                 $eventFeeBlockValues['amount_id_' . $fee['amount_id']] = $fee['value'];
                 $elements[] =& $form->createElement('radio', NULL, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id'], $totalAmountJs);
             }
         }
         $form->assign('eventFeeBlockValues', json_encode($eventFeeBlockValues));
         $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
         $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
         if (isset($form->_online) && $form->_online) {
             $element->freeze();
         }
         if ($required) {
             $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Function to build the price set form.
  *
  * @return None
  * @access public
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     $userid = $form->getVar('_userID');
     if (!$priceSetId) {
         return;
     }
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
         $validFieldsOnly = FALSE;
     }
     $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == "CRM_Contribute_Form_Contribution_Main") {
         $form->_quickConfig = $quickConfig;
     }
     $form->assign('priceSet', $form->_priceSet);
     $component = 'contribution';
     if ($className == 'CRM_Member_Form_Membership') {
         $component = 'membership';
     }
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
         if (!empty($form->_useForMember)) {
             $component = 'membership';
         }
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     foreach ($feeBlock as $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options)) {
                 continue;
             }
             CRM_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * build the radio/text form elements for the amount field
  * 
  * @param object   $form form object
  * @param boolean  $required  true if you want to add formRule
  * @param int      $discountId discount id for the event
  *
  * @return void
  * @access public
  * @static
  */
 public static function buildAmount(&$form, $required = true, $discountId = null)
 {
     //get the button name.
     $button = substr($form->controller->getButtonName(), -4);
     if ($button == 'skip') {
         $required = false;
     }
     $elements = array();
     if (isset($form->_priceSetId)) {
         $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
         $form->add('hidden', 'priceSetId', $form->_priceSetId);
         $form->assign('priceSet', $form->_priceSet);
         require_once 'CRM/Price/BAO/Field.php';
         foreach ($form->_values['fee']['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'price_' . $fieldId;
             if ($button == 'skip') {
                 $isRequire = false;
             } else {
                 $isRequire = CRM_Utils_Array::value('is_required', $field);
             }
             CRM_Price_BAO_Field::addQuickFormElement($form, $elementName, $fieldId, false, $isRequire);
         }
     } else {
         if (!empty($form->_values['fee'])) {
             $form->_feeBlock =& $form->_values['fee'];
             if (isset($form->_values['discount'])) {
                 if (!isset($discountId) && $form->_action != CRM_Core_Action::UPDATE) {
                     require_once 'CRM/Core/BAO/Discount.php';
                     $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
                 }
                 if ($discountId) {
                     $form->_feeBlock =& $form->_values['discount'][$discountId];
                 }
             }
             require_once 'CRM/Utils/Hook.php';
             CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
             if ($form->_action != CRM_Core_Action::UPDATE) {
                 require_once 'CRM/Utils/Money.php';
                 foreach ($form->_feeBlock as $fee) {
                     if (is_array($fee)) {
                         $elements[] =& $form->createElement('radio', null, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id']);
                     }
                 }
                 $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
                 $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
                 if (isset($form->_online) && $form->_online) {
                     $element->freeze();
                 }
                 if ($required) {
                     $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /** 
  * Function to build the price set form.
  * 
  * @return None 
  * @access public 
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $priceSet = self::getSetDetail($priceSetId, true);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->assign('priceSet', $form->_priceSet);
     require_once 'CRM/Core/PseudoConstant.php';
     $className = CRM_Utils_System::getClassName($form);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::buildAmount('contribution', $form, $feeBlock);
     foreach ($feeBlock as $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || $className == 'CRM_Contribute_Form_Contribution') {
             $options = CRM_Utils_Array::value('options', $field);
             if (!is_array($options)) {
                 continue;
             }
             CRM_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], false, CRM_Utils_Array::value('is_required', $field, false), null, $options);
         }
     }
 }