From: Coleman Watts Date: Wed, 6 May 2015 21:07:01 +0000 (-0400) Subject: CRM-16204 - Add entityRef support for PaymentProcessor api X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6b4c95644d6f2d11289fa4d121acab6f0489edc8;p=civicrm-core.git CRM-16204 - Add entityRef support for PaymentProcessor api --- diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index 8582f1515e..2404608fc6 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -39,11 +39,12 @@ function civicrm_api3_generic_getList($apiRequest) { $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']); $request = $apiRequest['params']; + $meta = civicrm_api3_generic_getfields(array('action' => 'get') + $apiRequest, FALSE); // Hey api, would you like to provide default values? $fnName = "_civicrm_api3_{$entity}_getlist_defaults"; $defaults = function_exists($fnName) ? $fnName($request) : array(); - _civicrm_api3_generic_getList_defaults($entity, $request, $defaults); + _civicrm_api3_generic_getList_defaults($entity, $request, $defaults, $meta['values']); // Hey api, would you like to format the search params? $fnName = "_civicrm_api3_{$entity}_getlist_params"; @@ -56,7 +57,7 @@ function civicrm_api3_generic_getList($apiRequest) { // Hey api, would you like to format the output? $fnName = "_civicrm_api3_{$entity}_getlist_output"; $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output'; - $values = $fnName($result, $request); + $values = $fnName($result, $request, $entity, $meta['values']); _civicrm_api3_generic_getlist_postprocess($result, $request, $values); @@ -80,9 +81,8 @@ function civicrm_api3_generic_getList($apiRequest) { * @param array $request * @param array $apiDefaults */ -function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults) { +function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults, $fields) { $config = CRM_Core_Config::singleton(); - $fields = _civicrm_api_get_fields($entity); $defaults = array( 'page_num' => 1, 'input' => '', @@ -106,6 +106,9 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults } } $resultsPerPage = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10); + if (isset($request['params']) && isset($apiDefaults['params'])) { + $request['params'] += $apiDefaults['params']; + } $request += $apiDefaults + $defaults; // Default api params $params = array( @@ -156,10 +159,11 @@ function _civicrm_api3_generic_getlist_params(&$request) { * * @param array $result * @param array $request + * @param array $fields * * @return array */ -function _civicrm_api3_generic_getlist_output($result, $request) { +function _civicrm_api3_generic_getlist_output($result, $request, $entity, $fields) { $output = array(); if (!empty($result['values'])) { foreach ($result['values'] as $row) { @@ -171,7 +175,16 @@ function _civicrm_api3_generic_getlist_output($result, $request) { $data['description'] = array(); foreach ((array) $request['description_field'] as $field) { if (!empty($row[$field])) { - $data['description'][] = $row[$field]; + if (!isset($fields[$field]['pseudoconstant'])) { + $data['description'][] = $row[$field]; + } + else { + $data['description'][] = CRM_Core_PseudoConstant::getLabel( + _civicrm_api3_get_BAO($entity), + $field, + $row[$field] + ); + } } } }; diff --git a/api/v3/PaymentProcessor.php b/api/v3/PaymentProcessor.php index 2aa529cfa5..177b882b11 100644 --- a/api/v3/PaymentProcessor.php +++ b/api/v3/PaymentProcessor.php @@ -80,3 +80,26 @@ function civicrm_api3_payment_processor_delete($params) { function civicrm_api3_payment_processor_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } + + +/** + * Set default getlist parameters. + * + * @see _civicrm_api3_generic_getlist_defaults + * + * @param array $request + * + * @return array + */ +function _civicrm_api3_payment_processor_getlist_defaults(&$request) { + return array( + 'description_field' => array( + 'payment_processor_type_id', + 'description', + ), + 'params' => array( + 'is_test' => 0, + 'is_active' => 1, + ), + ); +}