Exemple #1
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if (!$this->_allowConfirmation && $this->_requireApproval) {
         $this->_defaults['bypass_payment'] = 1;
     }
     $contactID = $this->getContactID();
     CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
     CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($contactID, $this);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = $unsetSubmittedOptions = array();
     $discountId = NULL;
     //fix for CRM-3088, default value for discount set.
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId && !empty($this->_values['event']['default_discount_fee_id'])) {
             $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
             $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
         }
     }
     if ($this->_priceSetId) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionsFull = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !in_array($keys, $optionsFull)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             if (!empty($optionsFull)) {
                 $unsetSubmittedOptions[$val['id']] = $optionsFull;
             }
         }
     }
     //CRM-4320, setdefault additional participant values.
     if ($this->_allowConfirmation && $this->_additionalParticipantId) {
         //hack to get set default from eventFees.php
         $this->_discountId = $discountId;
         $this->_pId = $this->_additionalParticipantId;
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id');
         $participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this);
         $participantDefaults = array_merge($this->_defaults, $participantDefaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         $defaults = array_merge($defaults, $participantDefaults);
     }
     $defaults = array_merge($this->_defaults, $defaults);
     //reset values for all options those are full.
     CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     //load default campaign from page.
     if (array_key_exists('participant_campaign_id', $this->_fields)) {
         $defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     return $defaults;
 }
Exemple #3
0
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  * Adding discussion from CRM-11915 as code comments
  * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page :
  * The 'Register' page gets loaded through ajax and following happens :
  * the setDefaults function is called with the variable _ppType set with selected payment processor type,
  * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead.
  * - For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution .
  * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI)
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_paymentProcessorID && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
         // see function comment block for explanation of this. Note that CRM-15555 will require this to look at the billing form fields not the
         // billing_mode which
         return;
     }
     $this->_defaults = array();
     $contactID = $this->getContactID();
     $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
     $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     // note the effect of this is to set the billing country to default to the site default
     // country if the person has an address but no country (for anonymous country is set above)
     // this could have implications if the billing profile is filled but hidden.
     // this behaviour has been in place for a while but the use of js to hide things has increased
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     if ($this->_snippet) {
         return $this->_defaults;
     }
     if ($contactID) {
         $fields = array();
         if (!empty($this->_fields)) {
             $removeCustomFieldTypes = array('Participant');
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                         continue;
                     }
                     // ignore component fields
                 } elseif (substr($name, 0, 12) == 'participant_') {
                     continue;
                 }
                 $fields[$name] = 1;
             }
         }
     }
     if (!empty($fields)) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
     }
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }