/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { $defaults = array(); $fieldDefaults = array(); if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomOption::retrieve($params, $defaults); //$this->_fid = $defaults['custom_field_id']; $this->_fid = $defaults['entity_id']; $paramsField = array('id' => $this->_fid); CRM_Core_BAO_CustomField::retrieve($paramsField, $fieldDefaults); if ($fieldDefaults['html_type'] == 'CheckBox' || $fieldDefaults['html_type'] == 'Multi-Select') { $defaultCheckValues = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $fieldDefaults['default_value']); if (in_array($defaults['value'], $defaultCheckValues)) { $defaults['default_value'] = 1; } } else { if ($fieldDefaults['default_value'] == $defaults['value']) { $defaults['default_value'] = 1; } } } else { $defaults['is_active'] = 1; } require_once 'CRM/Core/DAO.php'; if ($this->_action & CRM_CORE_ACTION_ADD) { $cf =& new CRM_Core_DAO(); $sql = "SELECT max(weight) as weight\n FROM civicrm_custom_option\n WHERE entity_table='civicrm_custom_field' AND entity_id=" . $this->_fid . "\n ORDER BY weight"; $cf->query($sql); while ($cf->fetch()) { $defaults['weight'] = $cf->weight + 1; } if (empty($defaults['weight'])) { $defaults['weight'] = 1; } } return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { $defaults = array(); $fieldDefaults = array(); if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomOption::retrieve($params, $defaults); $paramsField = array('id' => $this->_fid); CRM_Core_BAO_CustomField::retrieve($paramsField, $fieldDefaults); if ($fieldDefaults['html_type'] == 'CheckBox' || $fieldDefaults['html_type'] == 'Multi-Select' || $fieldDefaults['html_type'] == 'AdvMulti-Select') { $defaultCheckValues = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($fieldDefaults['default_value'], 1, -1)); if (in_array($defaults['value'], $defaultCheckValues)) { $defaults['default_value'] = 1; } } else { if (CRM_Utils_Array::value('default_value', $fieldDefaults) == CRM_Utils_Array::value('value', $defaults)) { $defaults['default_value'] = 1; } } } else { $defaults['is_active'] = 1; } require_once 'CRM/Core/DAO.php'; if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('option_group_id' => $this->_optionGroupID); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues); } return $defaults; }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ static function setDefaultValues(&$form) { $defaults = array(); if ($form->_eventId) { //get receipt text and contribution type $returnProperities = array('confirm_email_text', 'contribution_type_id'); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); $defaults[$form->_pId]['contribution_type_id'] = $details[$form->_eventId]['contribution_type_id']; } if ($form->_pId) { $ids = array(); $params = array('id' => $form->_pId); require_once "CRM/Event/BAO/Participant.php"; 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) { $discounts[$key] = $value['name']; } } if ($form->_discountId) { $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]); } $form->assign('fee_amount', $defaults[$form->_pId]['fee_amount']); $form->assign('fee_level', $defaults[$form->_pId]['fee_level']); } $defaults[$form->_pId]['send_receipt'] = 0; } else { $defaults[$form->_pId]['send_receipt'] = 1; if ($form->_eventId) { //set receipt text $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text']; } list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults(); } if ($form->_mode) { $fields = array(); foreach ($form->_fields as $name => $dontCare) { $fields[$name] = 1; } $names = array("first_name", "middle_name", "last_name", "street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}", "state_province_id-{$form->_bltID}"); foreach ($names as $name) { $fields[$name] = 1; } $fields["state_province-{$form->_bltID}"] = 1; $fields["country-{$form->_bltID}"] = 1; $fields["email-{$form->_bltID}"] = 1; $fields["email-Primary"] = 1; require_once "CRM/Core/BAO/UFGroup.php"; if ($form->_contactID) { CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactID, $fields, $form->_defaults); } // use primary email address if billing email address is empty if (empty($form->_defaults["email-{$form->_bltID}"]) && !empty($form->_defaults["email-Primary"])) { $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults["email-Primary"]; } foreach ($names as $name) { if (!empty($form->_defaults[$name])) { $defaults[$form->_pId]["billing_" . $name] = $form->_defaults[$name]; } } } require_once 'CRM/Price/BAO/Set.php'; if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) { // get price set default values, CRM-4090 if (in_array(get_class($form), array('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) { foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { 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])); } } else { $optionGroupId = null; // 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) { $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $form->_originalDiscountId, 'option_group_id'); $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; } } } if ($form->_action == CRM_Core_Action::ADD) { // this case is for add mode, where we show discount automatically if (!isset($form->_discountId)) { require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } else { $discountId = $form->_discountId; } if ($form->_eventId && $discountId) { $defaultDiscountId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_discount_fee_id'); if ($defaultDiscountId) { $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $defaultDiscountId, 'weight'); } $defaults[$form->_pId]['discount_id'] = $discountId; $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, true)); $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $discountId, 'option_group_id'); } else { if ($form->_eventId) { $defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_fee_id'); } } } if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) { if (!empty($form->_feeBlock)) { $feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]); $feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]); foreach ($form->_feeBlock as $amountId => $amountInfo) { if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } // if amount is not set do fuzzy matching if (!isset($defaults[$form->_pId]['amount'])) { // if only level use that if ($amountInfo['label'] == $feeLevel) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } else { if (strpos($feeLevel, $amountInfo['label']) !== false) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } else { if ($amountInfo['value'] == $feeAmount) { // if amount matches use that $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } } } } } } if (!isset($defaults[$form->_pId]['amount'])) { // keeping the old code too if (!$optionGroupId) { $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionGroup", 'civicrm_event.amount.' . $defaults[$form->_pId]['event_id'], 'id', 'name'); } $optionParams = array('option_group_id' => $optionGroupId, 'label' => CRM_Utils_Array::value('fee_level', $defaults[$form->_pId])); CRM_Core_BAO_CustomOption::retrieve($optionParams, $params); $defaults[$form->_pId]['amount'] = $params['id']; } } $form->assign("amountId", $defaults[$form->_pId]['amount']); } //CRM-4453 $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']); // CRM-4395 if ($contriId = $form->get('onlinePendingContributionId')) { require_once 'CRM/Contribute/DAO/Contribution.php'; $contribution =& new CRM_Contribute_DAO_Contribution(); $contribution->id = $contriId; $contribution->find(true); foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $f) { $defaults[$form->_pId][$f] = $contribution->{$f}; } } return $defaults[$form->_pId]; }