From ab5fa8f252750f2e8c0854916371d02b61ecb5c0 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 11 Feb 2014 13:41:39 -0800 Subject: [PATCH] HR-268 - Activity API - Extract necessary bits so that we re-use in alternative "get" implementation --- api/v3/Activity.php | 20 +++++++++++++++++--- api/v3/utils.php | 7 +++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/api/v3/Activity.php b/api/v3/Activity.php index 4deab7fe53..171e20a539 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -233,6 +233,21 @@ function civicrm_api3_activity_get($params) { $activities = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); } + $activities = _civicrm_api3_activity_get_formatResult($params, $activities); + //legacy custom data get - so previous formatted response is still returned too + return civicrm_api3_create_success($activities, $params, 'activity', 'get'); +} + +/** + * Given a list of activities, append any extra data requested about the activities + * + * NOTE: Called by civicrm-core and CiviHR + * + * @param array $params API request parameters + * @param array $activities + * @return array new activities list + */ +function _civicrm_api3_activity_get_formatResult($params, $activities) { $returns = CRM_Utils_Array::value('return', $params, array()); if (!is_array($returns)) { $returns = str_replace(' ', '', $returns); @@ -274,13 +289,12 @@ function civicrm_api3_activity_get($params) { foreach ($activities as $activityId => $values) { _civicrm_api3_custom_data_get($activities[$activityId], 'Activity', $activityId, NULL, $values['activity_type_id']); } + return $activities; } - //legacy custom data get - so previous formatted response is still returned too - return civicrm_api3_create_success($activities, $params, 'activity', 'get'); + return $activities; } - /** * Delete a specified Activity. * diff --git a/api/v3/utils.php b/api/v3/utils.php index d9043a9044..8737a0a6dd 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -761,12 +761,15 @@ function _civicrm_api3_get_unique_name_array(&$bao) { * @static void * @access public */ -function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "") { +function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "", $autoFind = TRUE) { $result = array(); if(isset($params['options']) && CRM_Utils_Array::value('is_count', $params['options'])) { return $dao->count(); } - if (empty($dao) || !$dao->find()) { + if (empty($dao)) { + return array(); + } + if ($autoFind && !$dao->find()) { return array(); } -- 2.25.1