From dabf9814dea26c8f4b845ddb1d2638d7765fc7a1 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 9 Oct 2014 14:16:49 -0400 Subject: [PATCH] Add basic entityRef support for activities --- api/v3/Activity.php | 47 ++++++++++++++++++++++++++++++++++++++ api/v3/Generic/Getlist.php | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/api/v3/Activity.php b/api/v3/Activity.php index c7d033ec6a..4e46c49e2f 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -437,3 +437,50 @@ SELECT count(*) return NULL; } +/** + * @see _civicrm_api3_generic_getlist_params. + * + * @param $request array + */ +function _civicrm_api3_activity_getlist_params(&$request) { + $fieldsToReturn = array('activity_date_time', 'activity_type_id', 'subject', 'source_contact_id'); + $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra'])); + $request['params']['options']['sort'] = 'activity_date_time DESC'; + $request['params'] += array( + 'is_current_revision' => 1, + 'is_deleted' => 0, + ); +} + +/** + * @see _civicrm_api3_generic_getlist_output + * + * @param $result array + * @param $request array + * + * @return array + */ +function _civicrm_api3_activity_getlist_output($result, $request) { + $output = array(); + if (!empty($result['values'])) { + foreach ($result['values'] as $row) { + $data = array( + 'id' => $row[$request['id_field']], + 'label' => $row[$request['label_field']] ? $row[$request['label_field']] : ts('(no subject)'), + 'description' => array(CRM_Core_Pseudoconstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $row['activity_type_id'])), + ); + if (!empty($row['activity_date_time'])) { + $data['description'][0] .= ': ' . CRM_Utils_Date::customFormat($row['activity_date_time']); + } + if (!empty($row['source_contact_id'])) { + $data['description'][] = ts('By %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['source_contact_id'], 'display_name'))); + } + foreach ($request['extra'] as $field) { + $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL; + } + $output[] = $data; + } + } + return $output; +} + diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index 85c148929e..b7383bb0f7 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -82,7 +82,7 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request) { 'extra' => array(), ); // Find main field from meta - foreach (array('sort_name', 'title', 'label', 'name') as $field) { + foreach (array('sort_name', 'title', 'label', 'name', 'subject') as $field) { if (isset($fields[$field])) { $defaults['label_field'] = $defaults['search_field'] = $field; break; -- 2.25.1