/** * 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'); CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($this->_contactId, $this); $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; }