本文整理汇总了PHP中CRM_Core_BAO_CustomGroup::checkCustomField方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomGroup::checkCustomField方法的具体用法?PHP CRM_Core_BAO_CustomGroup::checkCustomField怎么用?PHP CRM_Core_BAO_CustomGroup::checkCustomField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomGroup
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomGroup::checkCustomField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* Set the default values.
*/
public function setDefaultValues()
{
// check if the user is registered and we have a contact ID
$contactID = $this->getContactID();
if (!empty($contactID)) {
$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_' || substr($name, 0, 13) == 'contribution_') {
continue;
}
$fields[$name] = 1;
}
if (!empty($fields)) {
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
}
$billingDefaults = $this->getProfileDefaults('Billing', $contactID);
$this->_defaults = array_merge($this->_defaults, $billingDefaults);
}
if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
$this->_defaults['total_amount'] = CRM_Utils_Money::format($this->_pendingAmount, NULL, '%a');
}
/*
* hack to simplify credit card entry for testing
*
* $this->_defaults['credit_card_type'] = 'Visa';
* $this->_defaults['amount'] = 168;
* $this->_defaults['credit_card_number'] = '4111111111111111';
* $this->_defaults['cvv2'] = '000';
* $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, '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 (!empty($this->_values['pledge_id'])) {
//used to record completed pledge payment ids used later for honor default
$completedContributionIds = array();
$pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']);
$paymentAmount = 0;
$duePayment = FALSE;
foreach ($pledgePayments as $payId => $value) {
if ($value['status'] == 'Overdue') {
$this->_defaults['pledge_amount'][$payId] = 1;
$paymentAmount += $value['scheduled_amount'];
} elseif (!$duePayment && $value['status'] == 'Pending') {
$this->_defaults['pledge_amount'][$payId] = 1;
$paymentAmount += $value['scheduled_amount'];
$duePayment = TRUE;
} elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
$completedContributionIds[] = $value['contribution_id'];
}
}
$this->_defaults['price_' . $this->_priceSetId] = $paymentAmount;
if (count($completedContributionIds)) {
$softCredit = array();
foreach ($completedContributionIds as $id) {
$softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id);
}
if (isset($softCredit['soft_credit'])) {
$this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
//since honoree profile fieldname of fields are prefixed with 'honor'
//we need to reformat the fieldname to append prefix during setting default values
CRM_Core_BAO_UFGroup::setProfileDefaults($softCredit['soft_credit'][1]['contact_id'], CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), $defaults);
foreach ($defaults as $fieldName => $value) {
$this->_defaults['honor[' . $fieldName . ']'] = $value;
}
}
}
} elseif (!empty($this->_values['pledge_block_id'])) {
//set default to one time contribution.
$this->_defaults['is_pledge'] = 0;
}
// to process Custom data that are appended to URL
$getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
$this->_defaults = array_merge($this->_defaults, $getDefaults);
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
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;
}
$entityId = $memtypeID = NULL;
//.........这里部分代码省略.........
示例2: formatFieldsAndSetProfileDefaults
/**
* CRM-17797 -- Format fields and setDefaults for primary and additional participants profile
* @param int $contactId
* @param CRM_Core_Form $form
*/
public static function formatFieldsAndSetProfileDefaults($contactId, &$form)
{
if (!$contactId) {
return;
}
$fields = array();
if (!empty($form->_fields)) {
$removeCustomFieldTypes = array('Participant');
foreach ($form->_fields as $name => $dontCare) {
if (substr($name, 0, 7) == 'custom_' && !$form->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField(substr($name, 7), $removeCustomFieldTypes) || substr($name, 0, 12) == 'participant_') {
continue;
}
$fields[$name] = 1;
}
if (!empty($fields)) {
CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $fields, $form->_defaults);
}
}
}
示例3: testCheckCustomField
/**
* Test checkCustomField()
*/
public function testCheckCustomField()
{
$groupParams = array('title' => 'My Custom Group', 'name' => 'my_custom_group', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1);
$customGroup = $this->customGroupCreate($groupParams);
$this->assertNotNull($customGroup['id'], 'pre-requisite group not created successfully');
$customGroupId = $customGroup['id'];
$customFieldLabel = 'Test Custom Field';
$fieldParams = array('custom_group_id' => $customGroupId, 'label' => $customFieldLabel, 'html_type' => 'Text', 'data_type' => 'String', 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
$customField = $this->customFieldCreate($fieldParams);
$customField = $customField['values'][$customField['id']];
$customFieldId = $customField['id'];
//check db for custom field
$dbCustomFieldLabel = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldId, 'label', 'id', 'Database check for custom field record.');
$this->assertEquals($customFieldLabel, $dbCustomFieldLabel);
//check the custom field type.
$params = array('Individual');
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(FALSE, $usedFor);
$params = array('Contribution', 'Membership', 'Participant');
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(TRUE, $usedFor);
$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
}
示例4: testCheckCustomField
/**
* Function to test checkCustomField()
*/
function testCheckCustomField()
{
$customGroupTitle = 'My Custom Group';
$groupParams = array('title' => $customGroupTitle, 'name' => 'my_custom_group', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1);
$customGroup = Custom::createGroup($groupParams);
$customGroupId = $customGroup->id;
$customFieldLabel = 'Test Custom Field';
$fieldParams = array('custom_group_id' => $customGroupId, 'label' => $customFieldLabel, 'html_type' => 'Text', 'data_type' => 'String', 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
$customField = Custom::createField($fieldParams);
$customFieldId = $customField->id;
//check db for custom group
$dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.');
$this->assertEquals($customGroupTitle, $dbCustomGroupTitle);
//check db for custom field
$dbCustomFieldLabel = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldId, 'label', 'id', 'Database check for custom field record.');
$this->assertEquals($customFieldLabel, $dbCustomFieldLabel);
//check the custom field type.
$params = array('Individual');
require_once 'CRM/Core/BAO/CustomGroup.php';
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(false, $usedFor);
$params = array('Contribution', 'Membership', 'Participant');
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(true, $usedFor);
//cleanup DB by deleting customGroup
Custom::deleteField($customField);
Custom::deleteGroup($customGroup);
}
示例5: 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');
//.........这里部分代码省略.........
示例6: 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;
}
//.........这里部分代码省略.........
示例7: setDefaultValues
/**
* Set default values for the form.
*/
public function setDefaultValues()
{
$this->_defaults = array();
$contactID = $this->getContactID();
CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
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);
//.........这里部分代码省略.........
示例8: 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 {
//.........这里部分代码省略.........
示例9: 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');
//.........这里部分代码省略.........