本文整理汇总了PHP中CRM_Core_SelectValues::pmf方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_SelectValues::pmf方法的具体用法?PHP CRM_Core_SelectValues::pmf怎么用?PHP CRM_Core_SelectValues::pmf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_SelectValues
的用法示例。
在下文中一共展示了CRM_Core_SelectValues::pmf方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* Set defaults for the form.
*
* @return array
*/
public function setDefaultValues()
{
$defaults = parent::setDefaultValues();
if (!empty($defaults['preferred_language'])) {
$languages = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
$defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'], $languages);
}
// CRM-7119: set preferred_language to default if unset
if (empty($defaults['preferred_language'])) {
$config = CRM_Core_Config::singleton();
$defaults['preferred_language'] = $config->lcMessages;
}
// CRM-19135: where CRM_Core_BAO_Contact::getValues() set label as a default value instead of reserved 'value',
// the code is to ensure we always set default to value instead of label
if (!empty($defaults['preferred_mail_format'])) {
$defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues::pmf());
}
if (empty($defaults['communication_style_id'])) {
$defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1'));
}
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
$name = "{$greeting}_display";
$this->assign($name, CRM_Utils_Array::value($name, $defaults));
}
return $defaults;
}
示例2: buildQuickForm
/**
* Build the form object elements for Communication Preferences object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*
* @return void
*/
public static function buildQuickForm(&$form)
{
// since the pcm - preferred comminication method is logically
// grouped hence we'll use groups of HTML_QuickForm
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$privacy = $commPreff = $commPreference = array();
$privacyOptions = CRM_Core_SelectValues::privacy();
// we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
unset($privacyOptions['is_opt_out']);
foreach ($privacyOptions as $name => $label) {
$privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
}
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
// preferred communication method
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
foreach ($comm as $value => $title) {
$commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
}
$form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
$form->addSelect('preferred_language');
if (!empty($privacyOptions)) {
$commPreference['privacy'] = $privacyOptions;
}
if (!empty($comm)) {
$commPreference['preferred_communication_method'] = $comm;
}
//using for display purpose.
$form->assign('commPreference', $commPreference);
$form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
$form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
$communicationStyleOptions = array();
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE));
foreach ($communicationStyle as $key => $var) {
$communicationStyleOptions[$key] = $form->createElement('radio', NULL, ts('Communication Style'), $var, $key, array('id' => "civicrm_communication_style_{$var}_{$key}"));
}
if (!empty($communicationStyleOptions)) {
$form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style'));
}
//check contact type and build filter clause accordingly for greeting types, CRM-4575
$greetings = self::getGreetingFields($form->_contactType);
foreach ($greetings as $greeting => $fields) {
$filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
//add addressee in Contact form
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
if (!empty($greetingTokens)) {
$form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
//custom addressee
$form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
}
}
}
示例3: buildQuickForm
/**
* build the form elements for Communication Preferences object
*
* @param CRM_Core_Form $form reference to the form object
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
// since the pcm - preferred comminication method is logically
// grouped hence we'll use groups of HTML_QuickForm
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$privacy = $commPreff = $commPreference = array();
$privacyOptions = CRM_Core_SelectValues::privacy();
foreach ($privacyOptions as $name => $label) {
$privacy[] = HTML_QuickForm::createElement('advcheckbox', $name, null, $label);
}
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
// preferred communication method
require_once 'CRM/Core/PseudoConstant.php';
$comm = CRM_Core_PseudoConstant::pcm();
foreach ($comm as $value => $title) {
$commPreff[] = HTML_QuickForm::createElement('advcheckbox', $value, null, $title);
}
$form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
$form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
if (!empty($privacyOptions)) {
$commPreference['privacy'] = $privacyOptions;
}
if (!empty($comm)) {
$commPreference['preferred_communication_method'] = $comm;
}
//using for display purpose.
$form->assign('commPreference', $commPreference);
$form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
$form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
//check contact type and build filter clause accordingly for greeting types, CRM-4575
$greetings = self::getGreetingFields($form->_contactType);
foreach ($greetings as $greeting => $fields) {
$filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
//add addressee in Contact form
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
if (!empty($greetingTokens)) {
$form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
//custom addressee
$form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
}
}
}
示例4: isErrorInCoreData
/**
* function to check if an error in Core( non-custom fields ) field
*
* @param String $errorMessage A string containing all the error-fields.
*
* @access public
*/
function isErrorInCoreData($params, &$errorMessage)
{
require_once 'CRM/Core/OptionGroup.php';
foreach ($params as $key => $value) {
if ($value) {
$session =& CRM_Core_Session::singleton();
$dateType = $session->get("dateTypes");
switch ($key) {
case 'birth_date':
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
if (!CRM_Utils_Rule::date($params[$key])) {
self::addToErrorMsg(ts('Birth Date'), $errorMessage);
}
} else {
self::addToErrorMsg(ts('Birth-Date'), $errorMessage);
}
break;
case 'deceased_date':
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
if (!CRM_Utils_Rule::date($params[$key])) {
self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
}
} else {
self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
}
break;
case 'is_deceased':
if (CRM_Utils_String::strtoboolstr($value) === false) {
self::addToErrorMsg(ts('Is Deceased'), $errorMessage);
}
break;
case 'gender':
if (!self::checkGender($value)) {
self::addToErrorMsg(ts('Gender'), $errorMessage);
}
break;
case 'preferred_communication_method':
$preffComm = array();
$preffComm = explode(',', $value);
foreach ($preffComm as $v) {
if (!self::in_value(trim($v), CRM_Core_PseudoConstant::pcm())) {
self::addToErrorMsg(ts('Preferred Communication Method'), $errorMessage);
}
}
break;
case 'preferred_mail_format':
if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage);
}
break;
case 'individual_prefix':
if (!self::in_value($value, CRM_Core_PseudoConstant::individualPrefix())) {
self::addToErrorMsg(ts('Individual Prefix'), $errorMessage);
}
break;
case 'individual_suffix':
if (!self::in_value($value, CRM_Core_PseudoConstant::individualSuffix())) {
self::addToErrorMsg(ts('Individual Suffix'), $errorMessage);
}
break;
case 'state_province':
if (!empty($value)) {
foreach ($value as $stateValue) {
if ($stateValue['state_province']) {
if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
continue;
} else {
self::addToErrorMsg(ts('State / Province'), $errorMessage);
}
}
}
}
break;
case 'country':
if (!empty($value)) {
foreach ($value as $stateValue) {
if ($stateValue['country']) {
CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active');
CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code');
$config =& CRM_Core_Config::singleton();
$limitCodes = $config->countryLimit();
//If no country is selected in
//localization then take all countries
if (empty($limitCodes)) {
$limitCodes = $countryIsoCodes;
}
if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
continue;
} else {
if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) {
self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Global Settings >> Localization." '), $errorMessage);
} else {
self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $errorMessage);
//.........这里部分代码省略.........
示例5: getValues
/**
* Fetch the object and store the values in the values array.
*
* @param array $params
* Input parameters to find object.
* @param array $values
* Output values of the object.
*
* @return CRM_Contact_BAO_Contact|null
* The found object or null
*/
public static function getValues(&$params, &$values)
{
$contact = new CRM_Contact_BAO_Contact();
$contact->copyValues($params);
if ($contact->find(TRUE)) {
CRM_Core_DAO::storeValues($contact, $values);
$privacy = array();
foreach (self::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
if (!empty($privacy)) {
$values['privacy'] = $privacy;
}
// communication Prefferance
$preffComm = $comm = array();
$comm = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contact->preferred_communication_method);
foreach ($comm as $value) {
$preffComm[$value] = 1;
}
$temp = array('preferred_communication_method' => $contact->preferred_communication_method);
$names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
CRM_Core_OptionGroup::lookupValues($temp, $names, FALSE);
$values['preferred_communication_method'] = $preffComm;
$values['preferred_communication_method_display'] = CRM_Utils_Array::value('preferred_communication_method_display', $temp);
$preferredMailingFormat = CRM_Core_SelectValues::pmf();
$values['preferred_mail_format'] = $preferredMailingFormat[$contact->preferred_mail_format];
// get preferred languages
if (!empty($contact->preferred_language)) {
$values['preferred_language'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $contact->preferred_language);
}
// Calculating Year difference
if ($contact->birth_date) {
$birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d');
if ($birthDate < date('Ymd')) {
$age = CRM_Utils_Date::calculateAge($birthDate);
$values['age']['y'] = CRM_Utils_Array::value('years', $age);
$values['age']['m'] = CRM_Utils_Array::value('months', $age);
}
list($values['birth_date']) = CRM_Utils_Date::setDateDefaults($contact->birth_date, 'birth');
$values['birth_date_display'] = $contact->birth_date;
}
if ($contact->deceased_date) {
list($values['deceased_date']) = CRM_Utils_Date::setDateDefaults($contact->deceased_date, 'birth');
$values['deceased_date_display'] = $contact->deceased_date;
}
$contact->contact_id = $contact->id;
return $contact;
}
return NULL;
}
示例6: buildProfile
//.........这里部分代码省略.........
}
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = $subtypes;
}
$form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE));
} elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
//add email greeting, postal greeting, addressee, CRM-4575
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
$profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
$profileType = 'Individual';
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
// add custom greeting element
$form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
} elseif ($fieldName === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
foreach ($communicationFields as $key => $var) {
if ($key == '') {
continue;
}
$communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
}
$form->addGroup($communicationOptions, $name, $title, '<br/>');
} elseif ($fieldName === 'preferred_mail_format') {
$form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
} elseif ($fieldName === 'preferred_language') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
} elseif ($fieldName == 'external_identifier') {
$form->add('text', $name, $title, $attributes, $required);
$contID = $contactId;
if (!$contID) {
$contID = $form->get('id');
}
$form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
} elseif ($fieldName === 'group') {
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
} elseif ($fieldName === 'tag') {
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
} elseif (substr($fieldName, 0, 4) === 'url-') {
$form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
$form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
} elseif (substr($fieldName, -4) == 'note') {
$form->add('textarea', $name, $title, $attributes, $required);
} elseif (substr($fieldName, 0, 6) === 'custom') {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
if ($customFieldID) {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
}
} elseif (substr($fieldName, 0, 14) === 'address_custom') {
list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
$customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
if ($customFieldID) {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
}
} elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
} elseif ($fieldName == 'send_receipt') {
示例7: buildProfile
//.........这里部分代码省略.........
}
if ($fieldName == 'email_greeting') {
$emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting');
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required);
// adding custom email greeting element alongwith email greeting
$form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false);
} else {
if ($fieldName === 'postal_greeting') {
$postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting');
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required);
// adding custom postal greeting element alongwith postal greeting
$form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false);
} else {
if ($fieldName === 'addressee') {
$addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee');
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required);
// adding custom addressee element alongwith addressee type
$form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false);
}
}
}
} else {
if ($fieldName === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::pcm();
foreach ($communicationFields as $key => $var) {
if ($key == '') {
continue;
}
$communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var);
}
$form->addGroup($communicationOptions, $name, $title, '<br/>');
} else {
if ($fieldName === 'preferred_mail_format') {
$form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
} else {
if ($fieldName == 'external_identifier') {
$form->add('text', $name, $title, $attributes, $required);
$contID = $contactId;
if (!$contID) {
$contID = $form->get('id');
}
$form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
} else {
if ($fieldName === 'group') {
require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name);
} else {
if ($fieldName === 'tag') {
require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name);
} else {
if ($fieldName === 'home_URL') {
$form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false")));
$form->addRule($name, ts('Enter a valid Website.'), 'url');
} else {
if (substr($fieldName, 0, 6) === 'custom') {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
if ($customFieldID) {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title);
}
} else {
if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
$form->addDate($name, $title, $required, array('formatType' => 'custom'));
} else {
if ($fieldName == 'payment_instrument') {
require_once "CRM/Contribute/PseudoConstant.php";
示例8: buildProfile
//.........这里部分代码省略.........
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = $subtypes;
}
$sel = $form->add('select', $name, $title, $subtypeList, $required);
$sel->setMultiple(TRUE);
} elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
//add email greeting, postal greeting, addressee, CRM-4575
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
$profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
$profileType = 'Individual';
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
// add custom greeting element
$form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
} elseif ($fieldName === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::pcm();
foreach ($communicationFields as $key => $var) {
if ($key == '') {
continue;
}
$communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
}
$form->addGroup($communicationOptions, $name, $title, '<br/>');
} elseif ($fieldName === 'preferred_mail_format') {
$form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
} elseif ($fieldName === 'preferred_language') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
} elseif ($fieldName == 'external_identifier') {
$form->add('text', $name, $title, $attributes, $required);
$contID = $contactId;
if (!$contID) {
$contID = $form->get('id');
}
$form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
} elseif ($fieldName === 'group') {
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
} elseif ($fieldName === 'tag') {
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
} elseif (substr($fieldName, 0, 4) === 'url-') {
$form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false")));
$form->addRule($name, ts('Enter a valid Website.'), 'url');
//Website type select
if ($onBehalf) {
if (substr($name, -1) == ']') {
$websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
}
$form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType());
} else {
$form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType());
}
// added because note appeared as a standard text input
} elseif ($fieldName == 'note') {
$form->add('textarea', $name, $title, $attributes, $required);
} elseif (substr($fieldName, 0, 6) === 'custom') {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
if ($customFieldID) {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
示例9: isErrorInCoreData
/**
* function to check if an error in Core( non-custom fields ) field
*
* @param String $errorMessage A string containing all the error-fields.
*
* @access public
*/
function isErrorInCoreData($params, &$errorMessage)
{
foreach ($params as $key => $value) {
if ($value) {
switch ($key) {
case 'birth_date':
if (!CRM_Utils_Rule::date($value)) {
//return _crm_error('Birth Date');
CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage);
}
break;
case 'gender':
if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) {
//return _crm_error('Invalid value for field : Gender');
CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage);
}
break;
case 'preferred_communication_method':
if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) {
//return _crm_error('Invalid value for field : Preferred Communication Method');
CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage);
}
break;
case 'preferred_mail_format':
if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
//return _crm_error('Invalid value for field : Preferred Communication Method');
CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage);
}
break;
case 'individual_prefix':
if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) {
//return _crm_error('Invalid value for field : Individual Prefix');
CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage);
}
break;
case 'individual_suffix':
if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) {
//return _crm_error('Invalid value for field : Individual Suffix');
CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage);
}
break;
case 'state_province':
if (!empty($value)) {
foreach ($value as $stateValue) {
if ($stateValue['state_province']) {
if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
continue;
} else {
//return _crm_error('Invalid value for field : State Province ');
CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage);
}
}
}
}
break;
case 'country':
if (!empty($value)) {
foreach ($value as $stateValue) {
if ($stateValue['country']) {
if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
continue;
} else {
//return _crm_error('Invalid value for field : Country');
CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage);
}
}
}
}
break;
case 'geo_code_1':
if (!empty($value)) {
foreach ($value as $codeValue) {
if ($codeValue['geo_code_1']) {
if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
continue;
} else {
//return _crm_error('Invalid value for field : geo_code_1');
CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage);
}
}
}
}
break;
case 'geo_code_2':
if (!empty($value)) {
foreach ($value as $codeValue) {
if ($codeValue['geo_code_2']) {
if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
continue;
} else {
//return _crm_error('Invalid value for field : geo_code_2');
CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage);
}
//.........这里部分代码省略.........
示例10: buildCommunicationBlock
/**
* Create communication preferences block for the contact.
*
* @param object $form - CRM_Core_Form (or it's subclass)
* @return none
*
* @access public
* @static
*/
function buildCommunicationBlock(&$form)
{
// since the pcm - preferred comminication method is logically
// grouped hence we'll use groups of HTML_QuickForm
$privacy = array();
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$t = CRM_Core_SelectValues::privacy();
$privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
$privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
$privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
$privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
// preferred communication method
$form->add('select', 'preferred_communication_method', ts('Prefers'), CRM_Core_SelectValues::pcm());
$form->add('select', 'preferred_mail_format', ts('Mail Format'), CRM_Core_SelectValues::pmf());
}
示例11: buildQuickForm
/**
* Function to actually build the form
*
* @return void
* @access public
*/
function buildQuickForm()
{
if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) {
//check for mix profile (eg: individual + other contact type)
require_once "CRM/Core/BAO/UFField.php";
if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts."));
$config =& CRM_Core_Config::singleton();
CRM_Utils_System::redirect($config->userFrameworkBaseURL);
}
}
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);
$this->assign('fields', $this->_fields);
$this->assign('fieldset', $this->_fieldset);
/* if ($this->_mode & self::MODE_EDIT) {
$group =& new CRM_Core_DAO_UFGroup();
$group->id = $this->_gid;
if ($group->find(true)) {
$this->assign('help_pre', $group->help_pre);
$this->assign('help_post', $group->help_post);
}
}*/
// do we need inactive options ?
if ($this->_action & CRM_CORE_ACTION_VIEW) {
$inactiveNeeded = true;
} else {
$inactiveNeeded = false;
}
// should we restrict what we display
$admin = true;
if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) {
$admin = false;
$session =& CRM_Core_Session::singleton();
// show all fields that are visibile: if we are a admin or the same user or in registration mode
if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) {
$admin = true;
}
}
require_once "CRM/Contribute/PseudoConstant.php";
// 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 == 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 {
//.........这里部分代码省略.........