// get preferred languages
if (!empty($contact->preferred_language)) {
- $languages = CRM_Core_PseudoConstant::languages();
- $values['preferred_language'] = CRM_Utils_Array::value($contact->preferred_language, $languages);
+ $values['preferred_language'] = CRM_Core_PseudoConstant::getValue('CRM_Contact_DAO_Contact', 'preferred_language', $contact->preferred_language);
}
// Calculating Year difference
ts('Preferred Language'),
array(
'' => ts('- select -')) +
- CRM_Core_PseudoConstant::languages()
+ CRM_Contact_BAO_Contact::buildOptions('preferred_language')
);
if (!empty($privacyOptions)) {
static function setDefaultValues(&$form, &$defaults) {
if (!empty($defaults['preferred_language'])) {
- $languages = array_flip(CRM_Core_PseudoConstant::languages());
- $defaults['preferred_language'] = $languages[$defaults['preferred_language']];
+ $defaults['preferred_language'] = CRM_Core_PseudoConstant::getKey('CRM_Contact_DAO_Contact', 'preferred_language', $defaults['preferred_language']);
}
// CRM-7119: set preferred_language to default if unset
$defaults = parent::setDefaultValues();
if (!empty($defaults['preferred_language'])) {
- $languages = array_flip(CRM_Core_PseudoConstant::languages());
- $defaults['preferred_language'] = $languages[$defaults['preferred_language']];
+ $defaults['preferred_language'] = CRM_Core_PseudoConstant::getKey('CRM_Contact_DAO_Contact', 'preferred_language', $defaults['preferred_language']);
}
// CRM-7119: set preferred_language to default if unset
$form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
//CRM-6138 Preferred Language
- $langPreff = CRM_Core_PseudoConstant::languages();
- $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- any -')) + $langPreff);
+ $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- any -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
// Phone search
$form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
$values[$index] = implode(',', $compref);
}
elseif ($name === 'preferred_language') {
- $languages = CRM_Core_PseudoConstant::languages();
$params[$index] = $details->$name;
- $values[$index] = $languages[$details->$name];
+ $values[$index] = CRM_Core_PseudoConstant::getValue('CRM_Contact_DAO_Contact', 'preferred_language', $details->$name);
}
elseif ($name == 'group') {
$groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE);
$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());
+ $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);
static $enabled = NULL;
if (!$all) {
- $all = CRM_Core_I18n_PseudoConstant::languages();
+ $all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
// check which ones are available; add them to $all if not there already
$config = CRM_Core_Config::singleton();
*
*/
class CRM_Core_I18n_PseudoConstant {
- static function &languages() {
- static $languages = NULL;
- if ($languages === NULL) {
- $rows = array();
- CRM_Core_OptionValue::getValues(array('name' => 'languages'), $rows, 'weight', TRUE);
-
- $languages = array();
- foreach ($rows as $row) {
- $languages[$row['name']] = $row['label'];
- }
- }
- return $languages;
- }
static function longForShort($short) {
$longForShortMapping = self::longForShortMapping();
static function &values(
$name, $flip = FALSE, $grouping = FALSE,
$localize = FALSE, $condition = NULL,
- $labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE
+ $labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE, $keyColumnName = 'value'
) {
- $cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive);
+ $cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName);
- if (array_key_exists($cacheKey, self::$_cache) && !$fresh) {
- return self::$_cache[$cacheKey];
- }
-
- $cache = CRM_Utils_Cache::singleton();
- $var = $cache->get($cacheKey);
- if ($var && !$fresh) {
- return $var;
+ if (!$fresh) {
+ // Fetch from static var
+ if (array_key_exists($cacheKey, self::$_cache)) {
+ return self::$_cache[$cacheKey];
+ }
+ // Fetch from main cache
+ $cache = CRM_Utils_Cache::singleton();
+ $var = $cache->get($cacheKey);
+ if ($var) {
+ return $var;
+ }
}
$query = "
-SELECT v.{$labelColumnName} as {$labelColumnName} ,v.value as value, v.grouping as grouping
+SELECT v.{$labelColumnName} as {$labelColumnName} ,v.{$keyColumnName} as value, v.grouping as grouping
FROM civicrm_option_value v,
civicrm_option_group g
WHERE v.option_group_id = g.id
$query .= $condition;
}
- $query .= " ORDER BY v.weight";
+ $query .= " ORDER BY v.weight";
$p = array(1 => array($name, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $p);
* @param $labelColumnName
* @param $onlyActive
*/
- protected static function flushValues($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive) {
- $cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive);
+ protected static function flushValues($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName = 'value') {
+ $cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName);
$cache = CRM_Utils_Cache::singleton();
$cache->delete($cacheKey);
unset(self::$_cache[$cacheKey]);
}
- protected static function createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive) {
- $cacheKey = "CRM_OG_{$name}_{$flip}_{$grouping}_{$localize}_{$condition}_{$labelColumnName}_{$onlyActive}";
+ protected static function createCacheKey() {
+ $cacheKey = "CRM_OG_" . serialize(func_get_args());
return $cacheKey;
}
$params['condition'],
$params['labelColumn'] ? $params['labelColumn'] : 'label',
$params['onlyActive'],
- $params['fresh']
+ $params['fresh'],
+ $params['keyColumn'] ? $params['keyColumn'] : 'value'
);
}
return self::$greetingDefaults;
}
- /**
- * Get all the Languages from database.
- *
- * @access public
- * @static
- *
- * @return array self::languages - array reference of all languages
- *
- */
- public static function &languages() {
- return CRM_Core_I18n_PseudoConstant::languages();
- }
-
- /**
- * Alias of above
- */
- public static function &preferredLanguage() {
- return CRM_Core_I18n_PseudoConstant::languages();
- }
-
/**
* Get all extensions
*
if (in_array($table, array_keys($daos))) {
// FIXME: these should be populated with pseudo constants as they
// were at the time of logging rather than their current values
+ // FIXME: Use *_BAO:buildOptions() method rather than pseudoconstants & fetch programmatically
$values[$table] = array(
'contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(),
'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(),
'location_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'),
'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(),
'phone_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'),
- 'preferred_communication_method' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'),
- 'preferred_language' => CRM_Core_PseudoConstant::languages(),
- 'prefix_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'),
+ 'preferred_communication_method' => CRM_Contact_BAO_Contact::buildOptions('preferred_communication_method'),
+ 'preferred_language' => CRM_Contact_BAO_Contact::buildOptions('preferred_language'),
+ 'prefix_id' => CRM_Contact_BAO_Contact::buildOptions('prefix_id'),
'provider_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'),
'state_province_id' => CRM_Core_PseudoConstant::stateProvince(),
- 'suffix_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'),
+ 'suffix_id' => CRM_Contact_BAO_Contact::buildOptions('suffix_id'),
'website_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'),
'activity_type_id' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE),
'case_type_id' => CRM_Case_PseudoConstant::caseType('label', FALSE),
// we need to determine of overlay profile should be shown
$showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile();
- $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
- $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
- $languages = CRM_Core_PseudoConstant::languages();
while ($result->fetch()) {
if (isset($result->country)) {
// the query returns the untranslated country name
) {
$url = CRM_Utils_System::fixURL($result->$name);
$typeId = substr($name, 0, -4) . "-website_type_id";
- $typeName = $websiteTypes[$result->$typeId];
+ $typeName = CRM_Core_PseudoConstant::getValue('CRM_Core_DAO_Website', 'website_type_id', $result->$typeId);
if ($typeName) {
$row[] = "<a href=\"$url\">{$result->$name} (${typeName})</a>";
}
}
}
elseif ($name == 'preferred_language') {
- $row[] = $languages[$result->$name];
+ $row[] = CRM_Core_PseudoConstant::getValue('CRM_Contact_DAO_Contact', 'preferred_language', $result->$name);
}
elseif ($multipleSelectFields &&
array_key_exists($name, $multipleSelectFields)
elseif (strpos($name, '-im')) {
if (!empty($result->$name)) {
$providerId = $name . "-provider_id";
- $providerName = $imProviders[$result->$providerId];
+ $providerName = CRM_Core_PseudoConstant::getValue('CRM_Core_DAO_IM', 'provider_id', $result->$providerId);
$row[] = $result->$name . " ({$providerName})";
}
else {
'CRM_Event_PseudoConstant',
'CRM_Contribute_PseudoConstant',
'CRM_Member_PseudoConstant',
- 'CRM_Grant_PseudoConstant',
);
/**
'sample' => 'Team',
'exclude' => 'Individual',
),
+ array(
+ 'fieldName' => 'preferred_language',
+ 'sample' => array('en_US' => 'English (United States)'),
+ 'max' => 250,
+ ),
),
'CRM_Batch_DAO_Batch' => array(
array(
$this->assertNotEmpty($optionValues, $message);
// Ensure sample value is contained in the returned optionValues.
- $this->assertContains($field['sample'], $optionValues, $message);
+ if (!is_array($field['sample'])) {
+ $this->assertContains($field['sample'], $optionValues, $message);
+ }
+ // If sample is an array, we check keys and values
+ else {
+ foreach ($field['sample'] as $key => $value) {
+ $this->assertArrayHasKey($key, $optionValues, $message);
+ $this->assertEquals(CRM_Utils_Array::value($key, $optionValues), $value, $message);
+ }
+ }
// Ensure exclude value is not contained in the optionValues
if (!empty($field['exclude'])) {
3 => 'Organization',
);
// By default this should return an array keyed by name
- $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type');
+ $result = CRM_Contact_DAO_Contact::buildOptions('contact_type');
$this->assertEquals($byName, $result);
// But we can also fetch by ID
$result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
<comment>Which language is preferred for communication. FK to languages in civicrm_option_value.</comment>
<headerPattern>/^lang/i</headerPattern>
<import>true</import>
+ <pseudoconstant>
+ <optionGroupName>languages</optionGroupName>
+ <keyColumn>name</keyColumn>
+ </pseudoconstant>
<add>3.2</add>
</field>
<field>