本文整理汇总了PHP中CRM_Core_BAO_CustomField::setProfileDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomField::setProfileDefaults方法的具体用法?PHP CRM_Core_BAO_CustomField::setProfileDefaults怎么用?PHP CRM_Core_BAO_CustomField::setProfileDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomField
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomField::setProfileDefaults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* Set the default form values
*
* @access protected
*
* @return array the default array reference
*/
function setDefaultValues()
{
$defaults = array();
$stateCountryMap = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
//CRM-5403
if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$fieldName] = $name;
}
}
// also take care of state country widget
if (!empty($stateCountryMap)) {
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
return $defaults;
}
示例2: setDefaultValues
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues()
{
$defaults = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
return $defaults;
}
示例3: setDefaultValues
function setDefaultValues()
{
$defaults = array();
$profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileID);
$contactID = $this->_contactID;
$entityCaseID = NULL;
$cases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($contactID, FALSE, 'Application');
$entityCaseID = end($cases);
if ($contactID) {
$options = array();
$fields = array();
foreach ($profileFields as $name => $field) {
if (substr($name, 0, 7) == 'custom_') {
$id = substr($name, 7);
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if ($entityCaseID) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $entityCaseID, CRM_Profile_Form::MODE_REGISTER);
}
if (!isset($defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $contactID, CRM_Profile_Form::MODE_REGISTER);
}
$htmlType = $field['html_type'];
if ($htmlType == 'File') {
$this->assign('customname', $name);
$entityId = $entityCaseID;
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
if ($url) {
$customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/vacancy/apply', "reset=1&id={$this->_id}&cid={$contactID}"));
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
$this->assign('customFiles', $customFiles);
}
}
}
} else {
$fields[$name] = 1;
}
}
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $defaults);
}
return $defaults;
}
示例4: setDefaultValues
function setDefaultValues()
{
if (!$this->_donorID) {
return;
}
foreach ($this->_fields as $name => $dontcare) {
$fields[$name] = 1;
}
require_once "CRM/Core/BAO/UFGroup.php";
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_donorID, $fields, $this->_defaults);
//set custom field defaults
require_once "CRM/Core/BAO/CustomField.php";
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
}
return $this->_defaults;
}
示例5: setDefaultValues
/**
* 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']);
}
//CRM-17865 set custom field defaults
if (!empty($this->_fields)) {
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
}
}
return $defaults;
}
示例6: setDefaultValues
/**
* 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);
//.........这里部分代码省略.........
示例7: setDefaultsValues
/**
* This function sets the default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @access public
* @return void
*/
function setDefaultsValues()
{
$this->_defaults = array();
if ($this->_id) {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, true);
}
//set custom field defaults
require_once "CRM/Core/BAO/CustomField.php";
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if (!CRM_Utils_Array::value($name, $this->_defaults) || $htmlType == 'File') {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
}
if ($htmlType == 'File') {
$url = CRM_Core_BAO_CustomField::getFileURL($this->_id, $customFieldID);
if ($url) {
$customFiles[$field['name']]['displayURL'] = "Attached File : {$url['file_url']}";
$deleteExtra = "Are you sure you want to delete attached file ?";
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}&fid={$customFieldID}&action=delete");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">Delete Attached File</a>";
}
}
}
}
if (isset($customFiles)) {
$this->assign('customFiles', $customFiles);
}
$this->setDefaults($this->_defaults);
}
示例8: setDefaultValues
function setDefaultValues()
{
// process defaults only once
if (!empty($this->_defaults)) {
// return $this->_defaults;
}
// check if the user is registered and we have a contact ID
$session =& CRM_Core_Session::singleton();
$contactID = $this->_userID;
if ($contactID) {
$options = array();
$fields = array();
require_once "CRM/Core/BAO/CustomGroup.php";
$removeCustomFieldTypes = array('Contribution', 'Membership');
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
// remove component related fields
foreach ($this->_fields as $name => $dontCare) {
//don't set custom data Used for Contribution (CRM-1344)
if (substr($name, 0, 7) == 'custom_') {
$id = substr($name, 7);
if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
continue;
}
} else {
if (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_') {
//ignore component fields
continue;
}
}
$fields[$name] = 1;
}
$names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
foreach ($names as $name) {
$fields[$name] = 1;
}
$fields["state_province-{$this->_bltID}"] = 1;
$fields["country-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$fields["email-Primary"] = 1;
require_once "CRM/Core/BAO/UFGroup.php";
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
// use primary email address if billing email address is empty
if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
$this->_defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
}
foreach ($names as $name) {
if (!empty($this->_defaults[$name])) {
$this->_defaults["billing_" . $name] = $this->_defaults[$name];
}
}
}
//set custom field defaults set by admin if value is not set
if (!empty($this->_fields)) {
//set custom field defaults
require_once "CRM/Core/BAO/CustomField.php";
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, null, CRM_Profile_Form::MODE_REGISTER);
}
}
}
}
//set default membership for membershipship block
require_once 'CRM/Member/BAO/Membership.php';
if ($this->_membershipBlock) {
$this->_defaults['selectMembership'] = $this->_defaultMemTypeId ? $this->_defaultMemTypeId : CRM_Utils_Array::value('membership_type_default', $this->_membershipBlock);
}
if ($this->_membershipContactID) {
$this->_defaults['is_for_organization'] = 1;
$this->_defaults['org_option'] = 1;
} elseif ($this->_values['is_for_organization']) {
$this->_defaults['org_option'] = 0;
}
if ($this->_values['is_for_organization'] && !isset($this->_defaults['location'][1]['email'][1]['email'])) {
$this->_defaults['location'][1]['email'][1]['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $this->_defaults);
}
//if contribution pay later is enabled and payment
//processor is not available then freeze the pay later checkbox with
//default check
if (CRM_Utils_Array::value('is_pay_later', $this->_values) && empty($this->_paymentProcessor)) {
$this->_defaults['is_pay_later'] = 1;
}
// // hack to simplify credit card entry for testing
// $this->_defaults['credit_card_type'] = 'Visa';
// $this->_defaults['amount'] = 168;
// $this->_defaults['credit_card_number'] = '4807731747657838';
// $this->_defaults['cvv2'] = '000';
// $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
// // hack to simplify direct debit entry for testing
// $this->_defaults['account_holder'] = 'Max Müller';
// $this->_defaults['bank_account_number'] = '12345678';
// $this->_defaults['bank_identification_number'] = '12030000';
// $this->_defaults['bank_name'] = 'Bankname';
//build set default for pledge overdue payment.
if (CRM_Utils_Array::value('pledge_id', $this->_values)) {
//get all payment statuses.
$statuses = array();
$returnProperties = array('status_id');
//.........这里部分代码省略.........
示例9: setDefaultsValues
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
*/
public function setDefaultsValues()
{
$this->_defaults = array();
if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) {
return;
}
if ($this->_mode != self::MODE_SEARCH) {
// set default values for country / state to start with
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults);
}
if ($this->_id && !$this->_multiRecordProfile) {
if ($this->_isContactActivityProfile) {
$contactFields = $activityFields = array();
foreach ($this->_fields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
} else {
$contactFields[$fieldName] = $field;
}
}
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
if ($this->_activityId) {
CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
}
} else {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
}
}
//set custom field defaults
if ($this->_multiRecordProfile) {
foreach ($this->_multiRecordFields as $key => $field) {
$fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
}
$defaultValues = array();
if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
$defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
if ($this->_recordExists == TRUE) {
$defaultValues = $defaultValues[$this->_recordId];
} else {
$defaultValues = NULL;
}
}
if (!empty($defaultValues)) {
foreach ($defaultValues as $key => $value) {
$name = "custom_{$key}";
$htmlType = $this->_multiRecordFields[$name]['html_type'];
if ($htmlType != 'File') {
if (isset($value)) {
CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value);
} else {
$this->_defaults[$name] = "";
}
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
if ($url) {
$customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
// also delete the required rule that we've set on the form element
$this->removeFileRequiredRules($name);
}
}
}
}
} else {
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
if ($url) {
$customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
// also delete the required rule that we've set on the form element
//.........这里部分代码省略.........
示例10: setDefaultValues
function setDefaultValues()
{
// process defaults only once
if (!empty($this->_defaults)) {
// return $this->_defaults;
}
if ($this->_onbehalf) {
return;
}
// check if the user is registered and we have a contact ID
$session = CRM_Core_Session::singleton();
$contactID = $this->_userID;
if ($contactID) {
$options = array();
$fields = array();
$removeCustomFieldTypes = array('Contribution', 'Membership');
$contribFields = CRM_Contribute_BAO_Contribution::getContributionFields();
// remove component related fields
foreach ($this->_fields as $name => $dontCare) {
//don't set custom data Used for Contribution (CRM-1344)
if (substr($name, 0, 7) == 'custom_') {
$id = substr($name, 7);
if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
continue;
}
// ignore component fields
} elseif (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_') {
continue;
}
$fields[$name] = 1;
}
$names = array('first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
foreach ($names as $name) {
$fields[$name] = 1;
}
$fields["state_province-{$this->_bltID}"] = 1;
$fields["country-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$fields['email-Primary'] = 1;
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
// use primary email address if billing email address is empty
if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults['email-Primary'])) {
$this->_defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary'];
}
foreach ($names as $name) {
if (!empty($this->_defaults[$name])) {
$this->_defaults['billing_' . $name] = $this->_defaults[$name];
}
}
}
//set custom field defaults set by admin if value is not set
if (!empty($this->_fields)) {
//load default campaign from page.
if (array_key_exists('contribution_campaign_id', $this->_fields)) {
$this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
}
//set custom field defaults
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
}
}
//set default membership for membershipship block
if ($this->_membershipBlock) {
$this->_defaults['selectMembership'] = $defaultMemType = $this->_defaultMemTypeId ? $this->_defaultMemTypeId : CRM_Utils_Array::value('membership_type_default', $this->_membershipBlock);
}
// // hack to simplify credit card entry for testing
// $this->_defaults['credit_card_type'] = 'Visa';
// $this->_defaults['amount'] = 168;
// $this->_defaults['credit_card_number'] = '4807731747657838';
// $this->_defaults['cvv2'] = '000';
// $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
// // hack to simplify direct debit entry for testing
// $this->_defaults['account_holder'] = 'Max Müller';
// $this->_defaults['bank_account_number'] = '12345678';
// $this->_defaults['bank_identification_number'] = '12030000';
// $this->_defaults['bank_name'] = 'Bankname';
//build set default for pledge overdue payment.
if (CRM_Utils_Array::value('pledge_id', $this->_values)) {
//get all payment statuses.
$statuses = array();
$returnProperties = array('status_id');
CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_values['pledge_id'], $statuses, $returnProperties);
$paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$duePayment = FALSE;
foreach ($statuses as $payId => $value) {
if ($paymentStatusTypes[$value['status_id']] == 'Overdue') {
$this->_defaults['pledge_amount'][$payId] = 1;
} elseif (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') {
$this->_defaults['pledge_amount'][$payId] = 1;
$duePayment = TRUE;
}
}
} elseif (CRM_Utils_Array::value('pledge_block_id', $this->_values)) {
//set default to one time contribution.
$this->_defaults['is_pledge'] = 0;
}
//.........这里部分代码省略.........
示例11: setDefaultValues
/**
* This function sets the default values for the form. For edit/view mode
* the default values are retrieved from the database
*
* @access public
* @return None
*/
function setDefaultValues()
{
$contactID = parent::getContactID();
if ($contactID) {
$options = array();
$fields = array();
require_once "CRM/Core/BAO/CustomGroup.php";
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;
}
} else {
if (substr($name, 0, 12) == 'participant_') {
//ignore component fields
continue;
}
}
$fields[$name] = 1;
}
}
$names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
foreach ($names as $name) {
$fields[$name] = 1;
}
$fields["state_province-{$this->_bltID}"] = 1;
$fields["country-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$fields["email-Primary"] = 1;
require_once 'CRM/Core/BAO/UFGroup.php';
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
// use primary email address if billing email address is empty
if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
$this->_defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
}
foreach ($names as $name) {
if (isset($this->_defaults[$name])) {
$this->_defaults["billing_" . $name] = $this->_defaults[$name];
}
}
}
//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 (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !is_array($this->_paymentProcessor)) {
$this->_defaults['is_pay_later'] = 1;
}
//set custom field defaults
if (!empty($this->_fields)) {
require_once "CRM/Core/BAO/CustomField.php";
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
//fix for CRM-1743
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'])) {
require_once 'CRM/Core/BAO/Discount.php';
$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));
}
}
}
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
$this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
}
// now fix all state country selectors
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
// 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_id'] = $this->_values['event']['default_role_id'];
}
if ($this->_priceSetId) {
foreach ($this->_feeBlock as $key => $val) {
foreach ($val['options'] as $keys => $values) {
if ($values['is_default'] && !CRM_Utils_Array::value('is_full', $values)) {
if ($val['html_type'] == 'CheckBox') {
$this->_defaults["price_{$key}"][$keys] = 1;
} else {
//.........这里部分代码省略.........
示例12: setDefaultValues
/**
* This function sets the default values for the form.
*
* @access public
* @return None
*/
function setDefaultValues()
{
require_once 'CRM/Core/BAO/UFGroup.php';
$this->_defaults = array();
if ($this->_contactId) {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_contactProfileFields, $this->_defaults, true);
if ($this->_activityProfileId) {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_activityProfileFields, $this->_defaults, true);
}
}
//set custom field defaults
require_once "CRM/Core/BAO/CustomField.php";
foreach ($this->_contactProfileFields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
}
}
}
if ($this->_activityProfileFields) {
foreach ($this->_activityProfileFields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
}
}
}
}
$this->setDefaults($this->_defaults);
}
示例13: setDefaultValues
/**
* This function sets the default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @access public
*
* @return void
*/
function setDefaultValues()
{
//set default values for applicaiton profile fields
$profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileID);
$contactID = $this->_contactID;
if ($contactID) {
$options = array();
$fields = array();
if (!empty($this->_fields)) {
foreach ($this->_fields as $name => $dontCare) {
if (substr($name, 0, 7) == 'custom_') {
$id = substr($name, 7);
continue;
}
$fields[$name] = 1;
}
}
}
if (!empty($fields)) {
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
}
//set custom field defaults
if (!empty($this->_fields)) {
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $contactID, CRM_Profile_Form::MODE_REGISTER);
}
}
}
}
return $this->_defaults;
}
示例14: buildQuickForm
//.........这里部分代码省略.........
}
// since the CMS manages the email field, suppress the email display if in
// register mode which occur within the CMS form
if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') {
unset($this->_fields[$name]);
continue;
}
$required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required'];
//if ( $field['name'] === 'state_province' ) {
if (substr($field['name'], 0, 14) === 'state_province') {
$this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
} else {
if (substr($field['name'], 0, 7) === 'country') {
$this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
} else {
if ($field['name'] === 'birth_date') {
$this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required);
} else {
if ($field['name'] === 'gender') {
$genderOptions = array();
$gender = CRM_Core_PseudoConstant::gender();
foreach ($gender as $key => $var) {
$genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
}
$this->addGroup($genderOptions, $field['name'], $field['title']);
if ($required) {
$this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required');
}
} else {
if ($field['name'] === 'individual_prefix') {
$this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
} else {
if ($field['name'] === 'individual_suffix') {
$this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
} else {
if ($field['name'] === 'preferred_communication_method') {
$this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm());
} else {
if ($field['name'] === 'preferred_mail_format') {
$this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf());
} else {
if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') {
$this->add('checkbox', $name, $field['title'], $field['attributes'], $required);
} else {
if ($field['name'] === 'group') {
require_once 'CRM/Contact/Form/GroupTag.php';
CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null);
} else {
if ($field['name'] === 'tag') {
require_once 'CRM/Contact/Form/GroupTag.php';
CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']);
} else {
if (substr($field['name'], 0, 6) === 'custom') {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']);
CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']);
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode);
} else {
if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
$this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required);
$this->addRule($field['name'], ts('Select a valid date.'), 'qfDate');
} else {
if ($field['name'] == 'payment_instrument') {
$this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
} else {
if ($field['name'] == 'contribution_type') {
$this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
} else {
$this->add('text', $name, $field['title'], $field['attributes'], $required);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
$this->addRule($field['name'], ts('Please enter a valid amount.'), 'money');
}
if ($field['rule']) {
if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) {
continue;
} else {
$this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']);
}
}
}
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_CORE_ACTION_VIEW) {
$this->freeze();
}
$this->setDefaults($defaults);
}
示例15: setDefaultValues
/**
* This function sets the 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)
*
* @access public
*
* @return None
*/
function setDefaultValues()
{
if ($this->_ppType && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
// see function comment block for explanation of this
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 (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
$this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
}
// set default state/province from config if no state/province set
if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $this->_defaults)) {
$this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
}
if ($this->_snippet) {
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
return $this->_defaults;
}
if ($contactID) {
$options = array();
$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);
}
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
// Set default payment processor as default payment_processor radio button value
if (!empty($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $pid => $value) {
if (CRM_Utils_Array::value('is_default', $value)) {
$this->_defaults['payment_processor'] = $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 (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !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');
//.........这里部分代码省略.........