From dcda1cd509262fe625e7caf6ce3a95bd822150d4 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 4 May 2013 14:16:46 -0700 Subject: [PATCH] Add getValue and getKey methods CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Core/PseudoConstant.php | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 7898a120e9..ff35937d1a 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -351,8 +351,38 @@ class CRM_Core_PseudoConstant { } /** - * populate the object from the database. generic populate - * method + * Fetch the label (or other value) for a field given its key + * + * @param String $daoName + * @param String $fieldName + * @param String|Int $key + * @param Array $params will be passed into self::get + * + * @return string + */ + function getValue($daoName, $fieldName, $key, $params = array()) { + $values = self::get($daoName, $fieldName, $params); + return CRM_Utils_Array::value($key, $values); + } + + /** + * Fetch the key for a field option given its label/name + * + * @param String $daoName + * @param String $fieldName + * @param String|Int $value + * @param Array $params will be passed into self::get + * + * @return string + */ + function getKey($daoName, $fieldName, $value, $params = array()) { + $values = self::get($daoName, $fieldName, $params); + return CRM_Utils_Array::key($value, $values); + } + + /** + * DEPRECATED generic populate method + * All pseudoconstant functions that use this method are also deprecated. * * The static array $var is populated from the db * using the $name DAO. -- 2.25.1