本文整理汇总了PHP中CRM_Core_BAO_Address::addStateCountryMap方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Address::addStateCountryMap方法的具体用法?PHP CRM_Core_BAO_Address::addStateCountryMap怎么用?PHP CRM_Core_BAO_Address::addStateCountryMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Address
的用法示例。
在下文中一共展示了CRM_Core_BAO_Address::addStateCountryMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* Build the form
*
* @access public
*
* @return void
*/
function buildQuickForm()
{
$ufGroupId = $this->get('ufGroupId');
if (!$ufGroupId) {
CRM_Core_Error::fatal('ufGroupId is missing');
}
$this->_title = ts('Batch Update') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
CRM_Utils_System::setTitle($this->_title);
$this->addDefaultButtons(ts('Save'));
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
// remove file type field and then limit fields
$suppressFields = FALSE;
$removehtmlTypes = array('File', 'Autocomplete-Select');
foreach ($this->_fields as $name => $field) {
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && in_array($this->_fields[$name]['html_type'], $removehtmlTypes)) {
$suppressFields = TRUE;
unset($this->_fields[$name]);
}
}
//FIX ME: phone ext field is added at the end and it gets removed because of below code
//$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
$this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Contact(s)'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
$this->assign('profileTitle', $this->_title);
$this->assign('componentIds', $this->_contactIds);
// if below fields are missing we should not reset sort name / display name
// CRM-6794
$preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'prefix_id', 'suffix_id', 'household_name');
$stateCountryMap = array();
foreach ($this->_contactIds as $contactId) {
$profileFields = $this->_fields;
CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
foreach ($profileFields as $name => $field) {
// Link state to country, county to state per location per contact
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
$stateCountryMap["{$index}-{$contactId}"][$prefixName] = "field_{$contactId}_{$field['name']}";
$this->_stateCountryCountyFields["{$index}-{$contactId}"][$prefixName] = "field[{$contactId}][{$field['name']}]";
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
if (in_array($field['name'], $preserveDefaultsArray)) {
$this->_preserveDefault = FALSE;
}
}
}
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$this->assign('fields', $this->_fields);
// don't set the status message when form is submitted.
$buttonName = $this->controller->getButtonName('submit');
if ($suppressFields && $buttonName != '_qf_BatchUpdateProfile_next') {
CRM_Core_Session::setStatus(ts("File or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded."), ts('Some Fields Excluded'), 'info');
}
$this->addDefaultButtons(ts('Update Contacts'));
$this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
}
示例2: buildQuickForm
//.........这里部分代码省略.........
if (!$userID) {
require_once 'CRM/Core/BAO/LocationType.php';
$defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
$anonUser = true;
$this->assign('anonUser', true);
}
$addCaptcha = array();
$emailPresent = false;
// cache the state country fields. based on the results, we could use our javascript solution
// in create or register mode
$stateCountryMap = array();
// add the form elements
foreach ($this->_fields as $name => $field) {
// make sure that there is enough permission to expose this field
if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) {
unset($this->_fields[$name]);
continue;
}
// since the CMS manages the email field, suppress the email display if in
// register mode which occur within the CMS form
if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
unset($this->_fields[$name]);
continue;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if ($prefixName == 'state_province' || $prefixName == 'country') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $name;
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
if ($field['add_to_group_id']) {
$addToGroupId = $field['add_to_group_id'];
}
//build array for captcha
if ($field['add_captcha']) {
$addCaptcha[$field['group_id']] = $field['add_captcha'];
}
if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
$emailPresent = true;
$this->_mail = $name;
}
}
$setCaptcha = false;
// do this only for CiviCRM created forms
if ($this->_mode == self::MODE_CREATE) {
if (!empty($addCaptcha)) {
$setCaptcha = true;
}
if ($this->_gid) {
$dao = new CRM_Core_DAO_UFGroup();
$dao->id = $this->_gid;
$dao->addSelect();
$dao->addSelect('add_captcha', 'is_update_dupe');
if ($dao->find(true)) {
if ($dao->add_captcha) {
$setCaptcha = true;
}
if ($dao->is_update_dupe) {
$this->_isUpdateDupe = true;
}
}
}
if ($setCaptcha) {
require_once 'CRM/Utils/ReCAPTCHA.php';
$captcha =& CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign("isCaptcha", true);
}
}
if ($this->_mode != self::MODE_SEARCH) {
if (isset($addToGroupId)) {
$this->add('hidden', "group[{$addToGroupId}]", 1);
$this->_addToGroupID = $addToGroupId;
}
}
// also do state country js
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
$action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null);
if ($this->_mode == self::MODE_CREATE) {
require_once 'CRM/Core/BAO/CMSUser.php';
CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
} else {
$this->assign('showCMS', false);
}
$this->assign('groupId', $this->_gid);
// now fix all state country selectors
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
}
if ($this->_context == 'dialog') {
$this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
}
}
示例3: buildQuickForm
/**
* Build the form
*
* @access public
*
* @return void
*/
function buildQuickForm($form, $proxSearch)
{
// is proximity search required (2) or optional (1)?
$proxRequired = $proxSearch == 2 ? TRUE : FALSE;
$form->assign('proximity_search', TRUE);
$form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
$form->add('text', 'prox_city', ts('City'), NULL, FALSE);
$form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
$defaults = self::setDefaultValues($form);
if (CRM_Utils_Array::value('prox_country_id', $defaults)) {
$stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']);
} else {
$stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
}
$form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired);
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
$form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
// prox_distance_unit
// state country js, CRM-5233
$stateCountryMap = array();
$stateCountryMap[] = array('state_province' => 'prox_state_province_id', 'country' => 'prox_country_id');
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
$form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
}
示例4: buildQuickForm
//.........这里部分代码省略.........
// if false, user is not logged-in.
$anonUser = FALSE;
if (!$userID) {
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
$anonUser = TRUE;
$this->assign('anonUser', TRUE);
}
$addCaptcha = array();
$emailPresent = FALSE;
// cache the state country fields. based on the results, we could use our javascript solution
// in create or register mode
$stateCountryMap = array();
// add the form elements
foreach ($this->_fields as $name => $field) {
// make sure that there is enough permission to expose this field
if (!$admin && $field['visibility'] == 'User and User Admin Only') {
unset($this->_fields[$name]);
continue;
}
// since the CMS manages the email field, suppress the email display if in
// register mode which occur within the CMS form
if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
unset($this->_fields[$name]);
continue;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $name;
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
if ($field['add_to_group_id']) {
$addToGroupId = $field['add_to_group_id'];
}
//build array for captcha
if ($field['add_captcha']) {
$addCaptcha[$field['group_id']] = $field['add_captcha'];
}
if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
$emailPresent = TRUE;
$this->_mail = $name;
}
}
// add captcha only for create mode.
if ($this->_mode == self::MODE_CREATE) {
if (!$this->_isAddCaptcha && !empty($addCaptcha)) {
$this->_isAddCaptcha = TRUE;
}
if ($this->_gid) {
$dao = new CRM_Core_DAO_UFGroup();
$dao->id = $this->_gid;
$dao->addSelect();
$dao->addSelect('add_captcha', 'is_update_dupe');
if ($dao->find(TRUE)) {
if ($dao->add_captcha) {
$setCaptcha = TRUE;
}
if ($dao->is_update_dupe) {
$this->_isUpdateDupe = $dao->is_update_dupe;
}
}
}
} else {
$this->_isAddCaptcha = FALSE;
}
//finally add captcha to form.
if ($this->_isAddCaptcha) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
}
$this->assign("isCaptcha", $this->_isAddCaptcha);
if ($this->_mode != self::MODE_SEARCH) {
if (isset($addToGroupId)) {
$this->add('hidden', "add_to_group", $addToGroupId);
$this->_addToGroupID = $addToGroupId;
}
}
// also do state country js
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
if ($this->_mode == self::MODE_CREATE) {
CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
} else {
$this->assign('showCMS', FALSE);
}
$this->assign('groupId', $this->_gid);
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
}
if ($this->_context == 'dialog') {
$this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
}
$this->setDefaultsValues();
}
示例5: buildQuickForm
/**
* build form for address input fields
*
* @param object $form - CRM_Core_Form (or subclass)
* @param array reference $location - location array
* @param int $locationId - location id whose block needs to be built.
* @return none
*
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
$blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
$config =& CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array('onChange' => 'checkLocation( this.id );');
$form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
$js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
$js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null));
$stateCountryMap = array();
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
continue;
}
if (!$attributes) {
$attributes = $attributes[$name];
}
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
if ($name == 'country_id' || $name == 'state_province_id') {
if ($name == 'country_id') {
$stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
} else {
$stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
if ($countryDefault) {
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
} else {
$selectOptions = array('' => ts('- select a country -'));
}
}
$form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
} else {
if ($name == 'address_name') {
$name = "name";
}
$form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
}
} else {
$form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
}
}
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
}
示例6: array
/**
* 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') {
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)) {
require_once 'CRM/Core/BAO/Address.php';
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
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
return $defaults;
}
示例7: buildCustom
/**
* Function to add the custom fields
*
* @return void
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
{
$stateCountryMap = array();
if ($id) {
$contactID = $this->getContactID();
// we don't allow conflicting fields to be
// configured via profile - CRM 2100
$fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
$fields = NULL;
if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
}
if ($fields) {
// unset any email-* fields since we already collect it, CRM-2888
foreach (array_keys($fields) as $fieldName) {
if (substr($fieldName, 0, 6) == 'email-') {
unset($fields[$fieldName]);
}
}
if (array_intersect_key($fields, $fieldsToIgnore)) {
$fields = array_diff_key($fields, $fieldsToIgnore);
CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
}
$fields = array_diff_assoc($fields, $this->_fields);
CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
$addCaptcha = FALSE;
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
// ignore file upload fields
continue;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
if ($prefixName == "state_province") {
if ($profileContactType == 'onbehalf') {
//CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
//as already done during Contribution registration via onBehalf's quickForm
$field['is_required'] = FALSE;
} else {
if (count($this->_submitValues)) {
$locationTypeId = $field['location_type_id'];
if (array_key_exists("country-{$locationTypeId}", $fields) && array_key_exists("state_province-{$locationTypeId}", $fields) && !empty($this->_submitValues["country-{$locationTypeId}"])) {
$field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
}
}
}
}
}
if ($profileContactType) {
//Since we are showing honoree name separately so we are removing it from honoree profile just for display
$honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
unset($fields[$field['name']]);
continue;
}
if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
$this->_fields[$profileContactType][$key] = $field;
} else {
unset($fields[$key]);
}
} else {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields[$key] = $field;
}
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
if ($field['add_captcha'] && !$this->_userID) {
$addCaptcha = TRUE;
}
}
$this->assign($name, $fields);
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign('isCaptcha', TRUE);
}
}
}
}
示例8: buildProfile
//.........这里部分代码省略.........
$sel->setOptions(array($products, $options));
} elseif ($fieldName == 'payment_instrument') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
} else {
if ($fieldName == 'financial_type') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
} elseif ($fieldName == 'contribution_status_id') {
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
$statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
}
$form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
} elseif ($fieldName == 'soft_credit_type') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
$form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
} elseif ($fieldName == 'currency') {
$form->addCurrency($name, $title, $required);
} elseif ($fieldName == 'contribution_page_id') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
} elseif ($fieldName == 'participant_register_date') {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
} elseif ($fieldName == 'activity_status_id') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
} elseif ($fieldName == 'activity_engagement_level') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
} elseif ($fieldName == 'activity_date_time') {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
} elseif ($fieldName == 'participant_status') {
$cond = NULL;
if ($online == TRUE) {
$cond = 'visibility_id = 1';
}
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
} elseif ($fieldName == 'participant_role') {
if (!empty($field['is_multiple'])) {
$form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE);
} else {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
}
} elseif ($fieldName == 'world_region') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
} elseif ($fieldName == 'signature_html') {
$form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
} elseif ($fieldName == 'signature_text') {
$form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
} elseif (substr($fieldName, -11) == 'campaign_id') {
if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
$form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"');
}
} elseif ($fieldName == 'activity_details') {
$form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
} elseif ($fieldName == 'activity_duration') {
$form->add('text', $name, $title, $attributes, $required);
$form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
} else {
if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
$form->add('advcheckbox', $name, $title, $attributes, $required);
} else {
$form->add('text', $name, $title, $attributes, $required);
}
}
}
static $hiddenSubtype = FALSE;
if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
// In registration mode params are submitted via POST and we don't have any clue
// about profile-id or the profile-type (which could be a subtype)
// To generalize the behavior and simplify the process,
// lets always add the hidden
//subtype value if there is any, and we won't have to
// compute it while processing.
if ($usedFor) {
$form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']);
} else {
$form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
}
$hiddenSubtype = TRUE;
}
if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
$form->freeze($name);
}
//add the rules
if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
$form->addRule($name, ts('Please enter a valid amount.'), 'money');
}
$stateCountryMap = array();
if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
$stateCountryMap[$key]['state_province'] = $value;
$stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
}
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
}
if ($rule) {
if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
$form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
}
}
}
示例9: buildForm
function buildForm(&$form)
{
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->add('text', 'distance', ts('Distance'), NULL, TRUE);
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
$form->add('text', 'street_address', ts('Street Address'));
$form->add('text', 'city', ts('City'));
$form->add('text', 'postal_code', ts('Postal Code'));
$stateCountryMap = array();
$stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
$defaults = array();
if ($countryDefault) {
$stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
$defaults['country_id'] = $countryDefault;
} else {
$stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
}
$form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$form->add('select', 'country_id', ts('Country'), $country, TRUE);
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
$form->addElement('select', 'group', ts('Group'), $group);
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
$form->addElement('select', 'tag', ts('Tag'), $tag);
// state country js, CRM-5233
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
/**
* You can define a custom title for the search form
*/
$this->setTitle('Proximity Search');
/**
* if you are using the standard template, this array tells the template what elements
* are part of the search criteria
*/
$form->assign('elements', array('distance', 'prox_distance_unit', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'group', 'tag'));
}
示例10: buildQuickForm
/**
* Function to build the form
*
* @return None
* @access public
*/
public function buildQuickForm()
{
$config = CRM_Core_Config::singleton();
$i18n = CRM_Core_I18n::singleton();
CRM_Utils_System::setTitle(ts('Settings - Localization'));
$locales = CRM_Core_I18n::languages();
$warningTitle = json_encode(ts("Warning"));
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
if ($domain->locales) {
// for multi-lingual sites, populate default language drop-down with available languages
$lcMessages = array();
foreach ($locales as $loc => $lang) {
if (substr_count($domain->locales, $loc)) {
$lcMessages[$loc] = $lang;
}
}
$this->addElement('select', 'lcMessages', ts('Default Language'), $lcMessages);
// add language limiter and language adder
$this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($lcMessages), NULL, NULL, NULL, NULL, ' ');
$this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff($locales, $lcMessages)));
// add the ability to return to single language
$warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
$this->assign('warning', $warning);
$warning = json_encode($warning);
$this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
} else {
// for single-lingual sites, populate default language drop-down with all languages
$this->addElement('select', 'lcMessages', ts('Default Language'), $locales);
$warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
$this->assign('warning', $warning);
$warning = json_encode($warning);
$validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE);
if ($validTriggerPermission && !$config->logging) {
$this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
}
}
$this->addElement('checkbox', 'inheritLocale', ts('Inherit CMS Language'));
$this->addElement('text', 'monetaryThousandSeparator', ts('Thousands Separator'), array('size' => 2));
$this->addElement('text', 'monetaryDecimalPoint', ts('Decimal Delimiter'), array('size' => 2));
$this->addElement('text', 'moneyformat', ts('Monetary Amount Display'));
$this->addElement('text', 'moneyvalueformat', ts('Monetary Value Display'));
$country = array();
CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
$i18n->localizeArray($country, array('context' => 'country'));
asort($country);
$includeCountry =& $this->addElement('advmultiselect', 'countryLimit', ts('Available Countries') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
$includeCountry->setButtonAttributes('add', array('value' => ts('Add >>')));
$includeCountry->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$includeState =& $this->addElement('advmultiselect', 'provinceLimit', ts('Available States and Provinces') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
$includeState->setButtonAttributes('add', array('value' => ts('Add >>')));
$includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
/***Default State/Province***/
$stateCountryMap = array();
$stateCountryMap[] = array('state_province' => 'defaultContactStateProvince', 'country' => 'defaultContactCountry');
$countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry;
if ($countryDefault) {
$selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
} else {
$selectStateProvinceOptions = array('' => ts('- select a country -'));
}
$i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province'));
asort($selectStateProvinceOptions);
$this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions);
// state country js
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$defaults = array();
CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
// we do this only to initialize currencySymbols, kinda hackish but works!
$config->defaultCurrencySymbol();
$symbol = $config->currencySymbols;
foreach ($symbol as $key => $value) {
$this->_currencySymbols[$key] = "{$key}";
if ($value) {
$this->_currencySymbols[$key] .= " ({$value})";
}
}
$this->addElement('select', 'defaultCurrency', ts('Default Currency'), $this->_currencySymbols);
$includeCurrency =& $this->addElement('advmultiselect', 'currencyLimit', ts('Available Currencies') . ' ', $this->_currencySymbols, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
$includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
$includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$this->addElement('text', 'legacyEncoding', ts('Legacy Encoding'));
$this->addElement('text', 'customTranslateFunction', ts('Custom Translate Function'));
$this->addElement('text', 'fieldSeparator', ts('Import / Export Field Separator'), array('size' => 2));
$this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
parent::buildQuickForm();
}
示例11: buildCustom
/**
* Function to add the custom fields
*
* @return None
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE)
{
$stateCountryMap = $fields = array();
if ($id) {
$button = substr($this->controller->getButtonName(), -4);
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
// we don't allow conflicting fields to be
// configured via profile
$fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
if ($contactID) {
//FIX CRM-9653
if (is_array($id)) {
$fields = array();
foreach ($id as $profileID) {
$field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
$fields = array_merge($fields, $field);
}
} else {
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
}
}
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
}
if (array_intersect_key($fields, $fieldsToIgnore)) {
$fields = array_diff_key($fields, $fieldsToIgnore);
CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
}
$addCaptcha = FALSE;
if (!empty($this->_fields)) {
$fields = @array_diff_assoc($fields, $this->_fields);
}
if (!CRM_Utils_Array::value('additional_participants', $this->_params[0]) && is_null($cid)) {
CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
}
$this->assign($name, $fields);
if (is_array($fields)) {
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
// ignore file upload fields
continue;
}
//make the field optional if primary participant
//have been skip the additional participant.
if ($button == 'skip') {
$field['is_required'] = FALSE;
} elseif ($field['add_captcha'] && !$contactID) {
// only add captcha for first page
$addCaptcha = TRUE;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields[$key] = $field;
}
}
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign('isCaptcha', TRUE);
}
}
}
示例12: buildQuickForm
/**
* build form for address input fields
*
* @param object $form - CRM_Core_Form (or subclass)
* @param array reference $location - location array
* @param int $locationId - location id whose block needs to be built.
* @return none
*
* @access public
* @static
*/
static function buildQuickForm(&$form, $addressBlockCount = null)
{
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
} else {
$blockId = $addressBlockCount;
}
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array('onChange' => 'checkLocation( this.id );');
$form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
$js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
$js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
// hidden element to store master address id
$form->addElement('hidden', "address[{$blockId}][master_id]");
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null), 'street_number' => array(ts('Street Number'), $attributes['street_number'], null), 'street_name' => array(ts('Street Name'), $attributes['street_name'], null), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], null));
$stateCountryMap = array();
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
$continue = true;
if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
$continue = false;
}
if ($continue) {
continue;
}
}
if (!$attributes) {
$attributes = $attributes[$name];
}
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
if ($name == 'country_id' || $name == 'state_province_id') {
if ($name == 'country_id') {
$stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
} else {
$stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
if ($countryDefault) {
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
} else {
$selectOptions = array('' => ts('- select a country -'));
}
}
$form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
} else {
if ($name == 'address_name') {
$name = "name";
}
$form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
}
} else {
$form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
}
}
require_once 'CRM/Core/BAO/Address.php';
require_once 'CRM/Core/BAO/CustomGroup.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$entityId = null;
if (!empty($form->_values['address'])) {
$entityId = $form->_values['address'][$blockId]['id'];
}
// Process any address custom data -
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
}
}
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
// For some of the custom fields like checkboxes, the defaults doesn't populate
//.........这里部分代码省略.........
示例13: buildQuickForm
/**
* generic function to build all the form elements for a specific group tree
*
* @param object $form the form object
* @param array $groupTree the group tree object
* @param boolean $inactiveNeeded return inactive custom groups
* @param string $prefix prefix for custom grouptree assigned to template
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '')
{
$form->assign_by_ref("{$prefix}groupTree", $groupTree);
// this is fix for date field
$form->assign('currentYear', date('Y'));
foreach ($groupTree as $id => $group) {
CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
foreach ($group['fields'] as $field) {
$required = CRM_Utils_Array::value('is_required', $field);
//fix for CRM-1620
if ($field['data_type'] == 'File') {
if (!empty($field['element_value']['data'])) {
$required = 0;
}
}
$fieldId = $field['id'];
$elementName = $field['element_name'];
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required);
}
}
if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
$stateCountryMap[$key]['state_province'] = $value;
$stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
}
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
}
}
示例14: setDefaultValues
function setDefaultValues()
{
$this->_defaults = array();
if ($this->_contactID) {
foreach ($this->_fields as $name => $dontcare) {
$fields[$name] = 1;
}
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
}
$stateCountryMap = array();
//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);
}
}
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, $this->_defaults);
}
}
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
return $this->_defaults;
}
示例15: buildCustom
/**
* Function to add the custom fields
*
* @return None
* @access public
*/
function buildCustom($id, $name, $viewOnly = false)
{
$stateCountryMap = array();
if ($id) {
$button = substr($this->controller->getButtonName(), -4);
require_once 'CRM/Core/BAO/UFGroup.php';
require_once 'CRM/Profile/Form.php';
$session =& CRM_Core_Session::singleton();
$contactID = $session->get('userID');
// we don't allow conflicting fields to be
// configured via profile
$fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
$fields = null;
if ($contactID) {
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
}
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
}
if (is_array($fields)) {
// unset any email-* fields since we already collect it, CRM-2888
foreach (array_keys($fields) as $fieldName) {
if (substr($fieldName, 0, 6) == 'email-') {
unset($fields[$fieldName]);
}
}
}
if (array_intersect_key($fields, $fieldsToIgnore)) {
$fields = array_diff_key($fields, $fieldsToIgnore);
CRM_Core_Session::setStatus("Some of the profile fields cannot be configured for this page.");
}
$addCaptcha = false;
$this->assign($name, $fields);
if (is_array($fields)) {
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File') {
// ignore file upload fields
continue;
}
//make the field optional if primary participant
//have been skip the additional participant.
if ($button == 'skip') {
$field['is_required'] = false;
} else {
if ($field['add_captcha']) {
// only add captcha for first page
$addCaptcha = true;
}
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
if ($prefixName == 'state_province' || $prefixName == 'country') {
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, true);
$this->_fields[$key] = $field;
}
}
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
if ($addCaptcha && !$viewOnly) {
require_once 'CRM/Utils/ReCAPTCHA.php';
$captcha =& CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign("isCaptcha", true);
}
}
}