From ee2b1c1c8d89f71f3da57acfaf71c82db571f633 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 9 May 2013 11:56:19 -0700 Subject: [PATCH] Use new buildOptions in the api CRM-12464 ---------------------------------------- * CRM-12464: Add PseudoConstants to Schema Metadata http://issues.civicrm.org/jira/browse/CRM-12464 --- api/v3/Constant.php | 6 +++--- api/v3/Generic.php | 38 ++++++-------------------------------- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/api/v3/Constant.php b/api/v3/Constant.php index b7987c3b8a..2b3e89fc83 100644 --- a/api/v3/Constant.php +++ b/api/v3/Constant.php @@ -27,7 +27,7 @@ */ /** - * File for CiviCRM APIv3 pseudoconstants + * CiviCRM APIv3 pseudoconstants - DEPRECATED * * @package CiviCRM_APIv3 * @subpackage API_Constant @@ -37,8 +37,8 @@ */ /** - * Generic file to retrieve all the constants and - * pseudo constants used in CiviCRM + * This api is DEPRECATED as of CiviCRM 4.4. + * It's recommended to use the api getoptions action instead * * @param string Name of a public static method of * CRM_Core_PseudoContant: one of diff --git a/api/v3/Generic.php b/api/v3/Generic.php index 250a353b04..6ad82b3098 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -204,43 +204,17 @@ function civicrm_api3_generic_replace($apiRequest) { /** * API wrapper for getoptions function * - * @param array $apiRequest api request as an array. Keys are + * @param array $apiRequest api request as an array. * * @return array of results */ function civicrm_api3_generic_getoptions($apiRequest) { - $field = $apiRequest['params']['field']; - $getFieldsArray = array( - 'version' => 3, - 'action' => 'create', - 'options' => array('get_options' => $field), - ); - // First try to retrieve the options from getfields - $result = civicrm_api($apiRequest['entity'], 'getfields', $getFieldsArray); - if (!isset($result['values'][$field]) && isset($result['values'][$field . '_id'])) { - $field = $field . '_id'; - } - if (!empty($result['values'][$field]['options'])) { - return civicrm_api3_create_success($result['values'][$field]['options']); - } - // If that didn't work, try the constant api - if (substr($field, -3) == '_id') { - // Convert foo_id to just plain foo - $field = substr($field, 0, -3); - } - $params = array('name' => _civicrm_api_get_camel_name($field)); - $entity = strtolower($apiRequest['entity']); - if ($entity == 'contribution') { - $params['class'] = 'CRM_Contribute_PseudoConstant'; - } - elseif ($entity == 'event' || $entity == 'participant') { - $params['class'] = 'CRM_Event_PseudoConstant'; - } - elseif (strpos($entity, 'membership') === 0) { - $params['class'] = 'CRM_Member_PseudoConstant'; + $daoName = _civicrm_api3_get_DAO($apiRequest['entity']); + $options = $daoName::buildOptions($apiRequest['params']['field']); + if ($options === FALSE) { + return civicrm_api3_create_error("The field '{$apiRequest['params']['field']}' either doesn't exist or has no associated option list."); } - require_once 'api/v3/Constant.php'; - return civicrm_api3_constant_get($params); + return civicrm_api3_create_success($options); } /** -- 2.25.1