X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPseudoConstant.php;h=344cba8072ec3b44c3c9858ea061a41dcbd5455d;hb=900eb33a20f6f8ed03c1a8da6259a61679935ac8;hp=c53b37409b92cfa460e4f3b2fedabe7a09c169c5;hpb=2dbbc4d03e5ea12e54dbddf6f807a4cbd1c3bb26;p=civicrm-core.git diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index c53b37409b..344cba8072 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -205,6 +205,7 @@ class CRM_Core_PseudoConstant { /** * Low-level option getter, rarely accessed directly. * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions() + * @see http://wiki.civicrm.org/confluence/display/CRMDOC/Pseudoconstant+%28option+list%29+Reference * * @param String $daoName * @param String $fieldName @@ -222,7 +223,7 @@ class CRM_Core_PseudoConstant { * - fresh boolean ignore cache entries and go back to DB * @param String $context: Context string * - * @return Array on success, FALSE on error. + * @return Array|bool - array on success, FALSE on error. * * @static */ @@ -233,7 +234,7 @@ class CRM_Core_PseudoConstant { $params += array( 'grouping' => FALSE, 'localize' => FALSE, - 'onlyActive' => ($context == 'validate' || $context == 'create') ? FALSE : TRUE, + 'onlyActive' => ($context == 'validate' || $context == 'get') ? FALSE : TRUE, 'fresh' => FALSE, ); @@ -276,20 +277,12 @@ class CRM_Core_PseudoConstant { // Core field: load schema $dao = new $daoName; - $fields = $dao->fields(); - $fieldKeys = $dao->fieldKeys(); + $fieldSpec = $dao->getFieldSpec($fieldName); $dao->free(); - - // Support "unique names" as well as sql names - $fieldKey = $fieldName; - if (empty($fields[$fieldKey])) { - $fieldKey = $fieldKeys[$fieldName]; - } // If neither worked then this field doesn't exist. Return false. - if (empty($fields[$fieldKey])) { + if (empty($fieldSpec)) { return FALSE; } - $fieldSpec = $fields[$fieldKey]; // If the field is an enum, explode the enum definition and return the array. if (isset($fieldSpec['enumValues'])) { @@ -501,6 +494,33 @@ class CRM_Core_PseudoConstant { return CRM_Utils_Array::key($value, $values); } + /** + * Lookup the admin page at which a field's option list can be edited + * @param $fieldSpec + * @return string|null + */ + static function getOptionEditUrl($fieldSpec) { + // If it's an option group, that's easy + if (!empty($fieldSpec['pseudoconstant']['optionGroupName'])) { + return 'civicrm/admin/options/' . $fieldSpec['pseudoconstant']['optionGroupName']; + } + // For everything else... + elseif (!empty($fieldSpec['pseudoconstant']['table'])) { + $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($fieldSpec['pseudoconstant']['table']); + if (!$daoName) { + return NULL; + } + // We don't have good mapping so have to do a bit of guesswork from the menu + list(, $parent, , $child) = explode('_', $daoName); + $sql = "SELECT path FROM civicrm_menu + WHERE page_callback LIKE '%CRM_Admin_Page_$child%' OR page_callback LIKE '%CRM_{$parent}_Page_$child%' + ORDER BY page_callback + LIMIT 1"; + return CRM_Core_Dao::singleValueQuery($sql); + } + return NULL; + } + /** * DEPRECATED generic populate method * All pseudoconstant functions that use this method are also deprecated.