Ejemplo n.º 1
0
 function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::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_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
 /**
  * Build price options.
  *
  * @param CRM_Event_BAO_Event $event
  *
  * @return array
  */
 public function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     //CRM-14492 display admin fields only if user is admin
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) {
                 $field_name = "event_{$event->id}_price_{$field['id']}";
                 CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
                 $price_fields_for_event[] = $field_name;
             }
         }
     }
     return $price_fields_for_event;
 }
Ejemplo n.º 3
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->assign('groupTree', $this->_groupTree);
     // add the form elements
     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_PriceField::addQuickFormElement($this, $elementName, $fieldId, FALSE, $field['is_required']);
             }
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => TRUE)));
 }
Ejemplo n.º 4
0
 /**
  * Build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     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);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $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);
     // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     foreach ($feeBlock as $id => $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $userid = $form->getVar('_membershipContactID');
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
                 continue;
             }
             CRM_Price_BAO_PriceField::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Ejemplo n.º 5
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)
 {
     //if payment done, no need to build the fee block.
     if (!empty($form->_paymentId)) {
         //fix to display 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);
         if (CRM_Utils_Array::value('is_quick_config', $form->_priceSet)) {
             $form->_quickConfig = $form->_priceSet['is_quick_config'];
         }
         $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_PriceField::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');
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     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);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $form->_quickConfig = $quickConfig;
     }
     // Mark which field should have the auto-renew checkbox, if any. CRM-18305
     if (!empty($form->_membershipTypeValues) && is_array($form->_membershipTypeValues)) {
         $autoRenewMembershipTypes = array();
         foreach ($form->_membershipTypeValues as $membershiptTypeValue) {
             if ($membershiptTypeValue['auto_renew']) {
                 $autoRenewMembershipTypes[] = $membershiptTypeValue['id'];
             }
         }
         foreach ($form->_priceSet['fields'] as &$field) {
             if (array_key_exists('options', $field) && is_array($field['options'])) {
                 foreach ($field['options'] as $option) {
                     if (!empty($option['membership_type_id'])) {
                         if (in_array($option['membership_type_id'], $autoRenewMembershipTypes)) {
                             $form->_priceSet['auto_renew_membership_field'] = $field['id'];
                             // Only one field can offer auto_renew memberships, so break here.
                             break;
                         }
                     }
                 }
             }
         }
     }
     $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'];
     }
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         foreach ($feeBlock as $key => $value) {
             foreach ($value['options'] as $k => $options) {
                 if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) {
                     unset($feeBlock[$key]['options'][$k]);
                 }
             }
             if (empty($feeBlock[$key]['options'])) {
                 unset($feeBlock[$key]);
             }
         }
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     foreach ($feeBlock as $id => $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $userid = $form->getVar('_membershipContactID');
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
                 continue;
             }
             CRM_Price_BAO_PriceField::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }