/** * Set default values for the form. * * @param CRM_Core_Form $form * @param int $contactID */ public static function setDefaultValues(&$form, $contactID) { $billingDefaults = $form->getProfileDefaults('Billing', $contactID); $form->_defaults = array_merge($form->_defaults, $billingDefaults); // set default country & state 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($form->_defaults["billing_country_id-{$form->_bltID}"])) { $form->_defaults["billing_country_id-{$form->_bltID}"] = CRM_Core_Config::singleton()->defaultContactCountry; } if (empty($form->_defaults["billing_state_province_id-{$form->_bltID}"])) { $form->_defaults["billing_state_province_id-{$form->_bltID}"] = CRM_Core_Config::singleton()->defaultContactStateProvince; } }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * * @param CRM_Core_Form $form * * @return void */ public static function setDefaultValues(&$form) { $defaults = array(); if ($form->_eventId) { //get receipt text and financial type $returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date'); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); if (!empty($details[$form->_eventId]['financial_type_id'])) { $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id']; } } if ($form->_pId) { $ids = array(); $params = array('id' => $form->_pId); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); if ($form->_action == CRM_Core_Action::UPDATE) { $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { $value = current($value); $discounts[$key] = $value['name']; } } if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) { $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]); } $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId])); } $defaults[$form->_pId]['send_receipt'] = 0; } else { $defaults[$form->_pId]['send_receipt'] = strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time() ? 1 : 0; if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) { //set receipt text $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text']; } list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults(); } //CRM-11601 we should keep the record contribution //true by default while adding participant if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) { $defaults[$form->_pId]['record_contribution'] = 1; } //CRM-13420 if (empty($defaults['payment_instrument_id'])) { $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } if ($form->_mode) { $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) { $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry; } if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) { $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince; } $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId); $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults); // // hack to simplify credit card entry for testing // $defaults[$form->_pId]['credit_card_type'] = 'Visa'; // $defaults[$form->_pId]['credit_card_number'] = '4807731747657838'; // $defaults[$form->_pId]['cvv2'] = '000'; // $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' ); } // if user has selected discount use that to set default if (isset($form->_discountId)) { $defaults[$form->_pId]['discount_id'] = $form->_discountId; //hack to set defaults for already selected discount value if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; if ($form->_originalDiscountId) { $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; } } $discountId = $form->_discountId; } else { $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); } else { $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId); } if ($form->_action == CRM_Core_Action::ADD && $form->_eventId && $discountId) { // this case is for add mode, where we show discount automatically $defaults[$form->_pId]['discount_id'] = $discountId; } if ($priceSetId) { // get price set default values, CRM-4090 if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) { $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId); if (!empty($priceSetValues)) { $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues); } } if ($form->_action == CRM_Core_Action::ADD && !empty($form->_priceSet['fields'])) { foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) { continue; } if ($val['html_type'] == 'CheckBox') { $defaults[$form->_pId]["price_{$key}"][$keys] = 1; } else { $defaults[$form->_pId]["price_{$key}"] = $keys; } } } } } $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); if ($form->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$form->_pId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $form->assign('fee_level', $fee_level); $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); } } //CRM-4453 if (!empty($defaults[$form->_pId]['participant_fee_currency'])) { $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']); } // CRM-4395 if ($contriId = $form->get('onlinePendingContributionId')) { $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->id = $contriId; $contribution->find(TRUE); foreach (array('financial_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) { if ($f == 'receive_date') { list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f}); } else { $defaults[$form->_pId][$f] = $contribution->{$f}; } } } return $defaults[$form->_pId]; }