本文整理汇总了PHP中CRM_Core_BAO_CustomOption::getOptionLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomOption::getOptionLabel方法的具体用法?PHP CRM_Core_BAO_CustomOption::getOptionLabel怎么用?PHP CRM_Core_BAO_CustomOption::getOptionLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomOption
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomOption::getOptionLabel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array_merge
/**
* Replace all the org-level tokens in $str
*
* @param string $str
* The string with tokens to be replaced.
* @param object $org
* Associative array of org properties.
* @param bool $html
* Replace tokens with HTML or plain text.
*
* @param bool $escapeSmarty
*
* @return string
* The processed string
*/
public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE)
{
self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id'));
$cv = NULL;
foreach (self::$_tokens['org'] as $token) {
// print "Getting token value for $token<br/><br/>";
if ($token == '') {
continue;
}
// If the string doesn't contain this token, skip it.
if (!self::token_match('org', $token, $str)) {
continue;
}
// Construct value from $token and $contact
$value = NULL;
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) {
// only generate cv if we need it
if ($cv === NULL) {
$cv = CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']);
}
foreach ($cv as $cvFieldID => $value) {
if ($cvFieldID == $cfID) {
$value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value);
break;
}
}
} elseif ($token == 'checksum') {
$cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']);
$value = "cs={$cs}";
} elseif ($token == 'address') {
// Build the location values array
$loc = array();
$loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name');
$loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address');
$loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city');
$loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province');
$loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code');
// Construct the address token
$value = CRM_Utils_Address::format($loc);
if ($html) {
$value = str_replace("\n", '<br />', $value);
}
} else {
$value = CRM_Utils_Array::retrieveValueRecursive($org, $token);
}
self::token_replace('org', $token, $value, $str, $escapeSmarty);
}
return $str;
}
示例2: setProfileDefaults
//.........这里部分代码省略.........
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
}
switch ($customFields[$customFieldId]['html_type']) {
case 'Multi-Select State/Province':
case 'Multi-Select Country':
case 'AdvMulti-Select':
case 'Multi-Select':
$v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = $item;
}
}
break;
case 'CheckBox':
$v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = 1;
// seems like we need this for QF style checkboxes in profile where its multiindexed
// CRM-2969
$defaults["{$fldName}[{$item}]"] = 1;
}
}
break;
case 'Autocomplete-Select':
if ($customFields[$customFieldId]['data_type'] == "ContactReference") {
require_once 'CRM/Contact/BAO/Contact.php';
if (is_numeric($details[$name])) {
$defaults[$fldName . '_id'] = $details[$name];
$defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name');
}
} else {
$label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
$defaults[$fldName . '_id'] = $details[$name];
$defaults[$fldName] = $label;
}
break;
case 'Select Date':
list($defaults[$fldName], $defaults[substr($fldName, 0, -1) . '_time]']) = CRM_Utils_Date::setDateDefaults($details[$name]);
break;
default:
$defaults[$fldName] = $details[$name];
break;
}
} else {
$defaults[$fldName] = $details[$name];
}
}
}
}
}
}
}
}
}
}
} else {
list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3);
if (is_array($details)) {
foreach ($details as $key => $value) {
// when we fixed CRM-5319 - get primary loc
// type as per loc field and removed below code.
if ($locTypeId == 'Primary') {
$locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId);
}
示例3: setDefaults
//.........这里部分代码省略.........
$checkedData = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
if (isset($value)) {
foreach ($customOption as $customValue => $customLabel) {
if (in_array($customValue, $checkedData)) {
if ($field['html_type'] == 'CheckBox') {
$defaults[$elementName][$customValue] = 1;
} else {
$defaults[$elementName][$customValue] = $customValue;
}
} else {
$defaults[$elementName][$customValue] = 0;
}
}
}
} else {
if (isset($field['customValue']['data'])) {
$checkedData = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($field['customValue']['data'], 1, -1));
foreach ($customOption as $val) {
if (in_array($val['value'], $checkedData)) {
if ($field['html_type'] == 'CheckBox') {
$defaults[$elementName][$val['value']] = 1;
} else {
$defaults[$elementName][$val['value']] = $val['value'];
}
} else {
$defaults[$elementName][$val['value']] = 0;
}
}
} else {
$checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
foreach ($customOption as $val) {
if (in_array($val['value'], $checkedValue)) {
if ($field['html_type'] == 'CheckBox') {
$defaults[$elementName][$val['value']] = 1;
} else {
$defaults[$elementName][$val['value']] = $val['value'];
}
}
}
}
}
break;
case 'Select Date':
if (isset($value)) {
if (!$field['time_format']) {
list($defaults[$elementName]) = CRM_Utils_Date::setDateDefaults($value, null, $field['date_format']);
} else {
$timeElement = $elementName . '_time';
if (substr($elementName, -1) == ']') {
$timeElement = substr($elementName, 0, ${$elementName} . length - 1) . '_time]';
}
list($defaults[$elementName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($value, null, $field['date_format'], $field['time_format']);
}
}
break;
case 'Multi-Select Country':
case 'Multi-Select State/Province':
if (isset($value)) {
$checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
foreach ($checkedValue as $val) {
if ($val) {
$defaults[$elementName][$val] = $val;
}
}
}
break;
case 'Select Country':
if ($value) {
$defaults[$elementName] = $value;
} else {
$config = CRM_Core_Config::singleton();
$defaults[$elementName] = $config->defaultContactCountry;
}
break;
case 'Autocomplete-Select':
if ($field['data_type'] == "ContactReference") {
require_once 'CRM/Contact/BAO/Contact.php';
if (is_numeric($value)) {
$defaults[$elementName . '_id'] = $value;
$defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name');
}
} else {
$label = CRM_Core_BAO_CustomOption::getOptionLabel($field['id'], $value);
$defaults[$elementName . '_id'] = $value;
$defaults[$elementName] = $label;
}
break;
default:
if ($field['data_type'] == "Float") {
$defaults[$elementName] = (double) $value;
} elseif ($field['data_type'] == 'Money') {
require_once 'CRM/Utils/Money.php';
$defaults[$elementName] = CRM_Utils_Money::format($value, null, '%a');
} else {
$defaults[$elementName] = $value;
}
}
}
}
}
示例4: setProfileDefaults
/**
* Function to set profile defaults
*
* @params int $contactId contact id
* @params array $fields associative array of fields
* @params array $defaults defaults array
* @params boolean $singleProfile true for single profile else false(batch update)
* @params int $componentId id for specific components like contribute, event etc
*
* @return null
* @static
* @access public
*/
static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = TRUE, $componentId = NULL, $component = NULL)
{
if (!$componentId) {
//get the contact details
list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
$details = CRM_Utils_Array::value($contactId, $contactDetails);
$multipleFields = array('website' => 'url');
//start of code to set the default values
foreach ($fields as $name => $field) {
// skip pseudo fields
if (substr($name, 0, 9) == 'phone_ext') {
continue;
}
//set the field name depending upon the profile mode(single/batch)
if ($singleProfile) {
$fldName = $name;
} else {
$fldName = "field[{$contactId}][{$name}]";
}
if ($name == 'group') {
CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
}
if ($name == 'tag') {
CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
}
if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) {
//to handle custom data (checkbox) to be written
// to handle birth/deceased date, greeting_type and few other fields
if ($name == 'birth_date' || $name == 'deceased_date') {
list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
} elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
$defaults[$fldName] = $details[$name . '_id'];
$defaults[$name . '_custom'] = $details[$name . '_custom'];
} elseif ($name == 'preferred_communication_method') {
$v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName . "[{$item}]"] = 1;
}
}
} elseif ($name == 'world_region') {
$defaults[$fldName] = $details['worldregion_id'];
} elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
//fix for custom fields
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details));
// hack to add custom data for components
$components = array('Contribution', 'Participant', 'Membership', 'Activity');
foreach ($components as $value) {
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
}
switch ($customFields[$customFieldId]['html_type']) {
case 'Multi-Select State/Province':
case 'Multi-Select Country':
case 'AdvMulti-Select':
case 'Multi-Select':
$v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = $item;
}
}
break;
case 'CheckBox':
$v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = 1;
// seems like we need this for QF style checkboxes in profile where its multiindexed
// CRM-2969
$defaults["{$fldName}[{$item}]"] = 1;
}
}
break;
case 'Autocomplete-Select':
if ($customFields[$customFieldId]['data_type'] == 'ContactReference') {
if (is_numeric($details[$name])) {
$defaults[$fldName . '_id'] = $details[$name];
$defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name');
}
} else {
$label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
$defaults[$fldName . '_id'] = $details[$name];
$defaults[$fldName] = $label;
}
break;
case 'Select Date':
// CRM-6681, set defult values according to date and time format (if any).
//.........这里部分代码省略.........
示例5: setProfileDefaults
/**
* Function to set default values for custom data used in profile
*
* @params int $customFieldId custom field id
* @params string $elementName custom field name
* @params array $defaults associated array of fields
* @params int $contactId contact id
* @param int $mode profile mode
*
* @static
* @access public
*/
static function setProfileDefaults($customFieldId, $elementName, &$defaults, $contactId = null, $mode = null)
{
//get the type of custom field
$customField = new CRM_Core_BAO_CustomField();
$customField->id = $customFieldId;
$customField->find(true);
require_once "CRM/Profile/Form.php";
$value = null;
if (!$contactId) {
if ($mode == CRM_Profile_Form::MODE_CREATE) {
$value = $customField->default_value;
}
} else {
$info = self::getTableColumnGroup($customFieldId);
$query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
$result = CRM_Core_DAO::executeQuery($query);
if ($result->fetch()) {
$value = $result->value;
}
if ($customField->data_type == 'Country') {
if (!$value) {
$config = CRM_Core_Config::singleton();
if ($config->defaultContactCountry) {
$value = $config->defaultContactCountry();
}
}
}
}
//set defaults if mode is registration
if (!trim($value) && $value !== 0 && !in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH))) {
$value = $customField->default_value;
}
if ($customField->data_type == 'Money' && isset($value)) {
$value = number_format($value, 2);
}
switch ($customField->html_type) {
case 'CheckBox':
case 'AdvMulti-Select':
case 'Multi-Select':
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldId, false);
$defaults[$elementName] = array();
$checkedValue = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($value, 1, -1));
foreach ($customOption as $val) {
if (in_array($val['value'], $checkedValue)) {
if ($customField->html_type == 'CheckBox') {
$defaults[$elementName][$val['value']] = 1;
} elseif ($customField->html_type == 'Multi-Select' || $customField->html_type == 'AdvMulti-Select') {
$defaults[$elementName][$val['value']] = $val['value'];
}
}
}
break;
case 'Select Date':
if ($value) {
list($defaults[$elementName], $defaults[$elementName . '_time']) = CRM_Utils_Date::setDateDefaults($value, null, $customField->date_format, $customField->time_format);
}
break;
case 'Autocomplete-Select':
if ($customField->data_type == "ContactReference") {
require_once 'CRM/Contact/BAO/Contact.php';
if (is_numeric($value)) {
$defaults[$elementName . '_id'] = $value;
$defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name');
}
} else {
$label = CRM_Core_BAO_CustomOption::getOptionLabel($customField->id, $value);
$defaults[$elementName . '_id'] = $value;
$defaults[$elementName] = $label;
}
break;
default:
$defaults[$elementName] = $value;
}
}
示例6: array_merge
/**
* Replace all the org-level tokens in $str
*
* @param string $str The string with tokens to be replaced
* @param object $org Associative array of org properties
* @param boolean $html Replace tokens with HTML or plain text
* @return string The processed string
* @access public
* @static
*/
public static function &replaceOrgTokens($str, &$org, $html = false)
{
self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id'));
/*
print "org tokens: <pre>";
print_r( $_tokens['org'] );
print "</pre>";
*/
$cv = null;
foreach (self::$_tokens['org'] as $token) {
// print "Getting token value for $token<br/><br/>";
if ($token == '') {
continue;
}
/* If the string doesn't contain this token, skip it. */
if (!self::token_match('org', $token, $str)) {
continue;
}
/* Construct value from $token and $contact */
$value = null;
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) {
// only generate cv if we need it
if ($cv === null) {
$cv =& CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']);
}
foreach ($cv as $cvFieldID => $value) {
if ($cvFieldID == $cfID) {
$value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value);
break;
}
}
} else {
if ($token == 'checksum') {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
$cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']);
$value = "cs={$cs}";
} else {
if ($token == 'address') {
/* Build the location values array */
$loc = array();
$loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name');
$loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address');
$loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city');
$loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province');
$loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code');
/* Construct the address token */
$value = CRM_Utils_Address::format($loc);
if ($html) {
$value = str_replace("\n", '<br />', $value);
}
} else {
/*
print "\$org: <pre>";
print_r( $org );
print "</pre>";
*/
$value = CRM_Utils_Array::retrieveValueRecursive($org, $token);
/*
print "\$value: <pre>";
print_r( $value );
print "</pre>";
*/
}
}
}
self::token_replace('org', $token, $value, $str);
}
return $str;
}