From 7cdbcb16520d540f0b7c5cb43c9511374d692931 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 8 Jan 2015 16:02:10 -0800 Subject: [PATCH] INFRA-132 - api/ - Misc --- api/Exception.php | 8 ++++-- api/api.php | 18 +++++++----- api/v3/ActionSchedule.php | 2 +- api/v3/Activity.php | 59 +++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/api/Exception.php b/api/Exception.php index 1b5d544f8e..1ee7914cbf 100644 --- a/api/Exception.php +++ b/api/Exception.php @@ -9,8 +9,12 @@ */ /** - * This api exception returns more information than the default one. The aim it let the api consumer know better what is exactly the error without having to parse the error message. - * If you consume an api that doesn't return an error_code or the extra data you need, consider improving the api and contribute + * This api exception returns more information than the default one. The aim + * it let the api consumer know better what is exactly the error without + * having to parse the error message. + * + * If you consume an api that doesn't return an error_code or the extra data + * you need, consider improving the api and contribute. */ class API_Exception extends Exception { const UNAUTHORIZED = 'unauthorized'; diff --git a/api/api.php b/api/api.php index 93e63cc2a6..6c46cb763b 100644 --- a/api/api.php +++ b/api/api.php @@ -48,11 +48,13 @@ function civicrm_api3($entity, $action, $params = array()) { } /** - * call getfields from api wrapper. This function ensures that settings that could alter - * getfields output (e.g. action for all api & profile_id for profile api ) are consistently passed in. + * Call getfields from api wrapper. This function ensures that settings that + * could alter getfields output (e.g. action for all api & profile_id for + * profile api ) are consistently passed in. * - * We check whether the api call is 'getfields' because if getfields is being called we return an empty array - * as no alias swapping, validation or default filling is done on getfields & we want to avoid a loop + * We check whether the api call is 'getfields' because if getfields is + * being called we return an empty array as no alias swapping, validation or + * default filling is done on getfields & we want to avoid a loop * * @todo other output modifiers include contact_type * @@ -153,10 +155,12 @@ function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResu * Convert possibly camel name to underscore separated entity name * * @param string $entity - * Entity name in various formats e.g. Contribution, contribution, OptionValue, option_value, UFJoin, uf_join. - * @return string $entity entity name in underscore separated format + * Entity name in various formats e.g. Contribution, contribution, + * OptionValue, option_value, UFJoin, uf_join. + * @return string $entity + * Entity name in underscore separated format. * - * FIXME: Why isn't this called first thing in civicrm_api wrapper? + * @fixme Why isn't this called first thing in civicrm_api wrapper? */ function _civicrm_api_get_entity_name_from_camel($entity) { if ($entity == strtolower($entity)) { diff --git a/api/v3/ActionSchedule.php b/api/v3/ActionSchedule.php index bc01516cba..a4269c2eba 100644 --- a/api/v3/ActionSchedule.php +++ b/api/v3/ActionSchedule.php @@ -82,7 +82,7 @@ function _civicrm_api3_action_schedule_create_spec(&$params) { * * @param array $params * Array containing id of the action_schedule. - * to be deleted + * to be deleted * * @return array API result array * diff --git a/api/v3/Activity.php b/api/v3/Activity.php index fc1e693f6d..9f1c58148e 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -60,7 +60,9 @@ function civicrm_api3_activity_create($params) { civicrm_api3_verify_one_mandatory($params, NULL, array( - 'activity_name', 'activity_type_id', 'activity_label', + 'activity_name', + 'activity_type_id', + 'activity_label', ) ); } @@ -91,8 +93,8 @@ function civicrm_api3_activity_create($params) { // If this is a case activity, see if there is an existing activity // and set it as an old revision. Also retrieve details we'll need. // this handling should all be moved to the BAO layer - $case_id = ''; - $createRevision = FALSE; + $case_id = ''; + $createRevision = FALSE; $oldActivityValues = array(); if (!empty($params['case_id'])) { $case_id = $params['case_id']; @@ -201,11 +203,11 @@ function _civicrm_api3_activity_create_spec(&$params) { ); $params['source_contact_id'] = array( - 'name' => 'source_contact_id', - 'title' => 'Activity Source Contact', - 'type' => 1, - 'FKClassName' => 'CRM_Activity_DAO_ActivityContact', - 'api.default' => 'user_contact_id', + 'name' => 'source_contact_id', + 'title' => 'Activity Source Contact', + 'type' => 1, + 'FKClassName' => 'CRM_Activity_DAO_ActivityContact', + 'api.default' => 'user_contact_id', ); } @@ -345,11 +347,11 @@ function civicrm_api3_activity_delete($params) { function _civicrm_api3_activity_check_params(&$params) { $contactIDFields = array_intersect_key($params, - array( - 'source_contact_id' => 1, - 'assignee_contact_id' => 1, - 'target_contact_id' => 1, - ) + array( + 'source_contact_id' => 1, + 'assignee_contact_id' => 1, + 'target_contact_id' => 1, + ) ); // this should be handled by wrapper layer & probably the api would already manage it @@ -381,9 +383,9 @@ SELECT count(*) } $activityIds = array( - 'activity' => CRM_Utils_Array::value('id', $params), - 'parent' => CRM_Utils_Array::value('parent_id', $params), - 'original' => CRM_Utils_Array::value('original_id', $params), + 'activity' => CRM_Utils_Array::value('id', $params), + 'parent' => CRM_Utils_Array::value('parent_id', $params), + 'original' => CRM_Utils_Array::value('original_id', $params), ); foreach ($activityIds as $id => $value) { @@ -397,8 +399,8 @@ SELECT count(*) //correctly by doing pseudoconstant validation // needs testing $activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate'); - $activityName = CRM_Utils_Array::value('activity_name', $params); - $activityName = ucfirst($activityName); + $activityName = CRM_Utils_Array::value('activity_name', $params); + $activityName = ucfirst($activityName); $activityLabel = CRM_Utils_Array::value('activity_label', $params); if ($activityLabel) { $activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'create'); @@ -442,13 +444,18 @@ SELECT count(*) } /** - * @see _civicrm_api3_generic_getlist_params. + * @see _civicrm_api3_generic_getlist_params * - * @param $request - * Array. + * @param array $request + * API request. */ function _civicrm_api3_activity_getlist_params(&$request) { - $fieldsToReturn = array('activity_date_time', 'activity_type_id', 'subject', 'source_contact_id'); + $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( @@ -474,13 +481,17 @@ function _civicrm_api3_activity_getlist_output($result, $request) { $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'])), + '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'))); + $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; -- 2.25.1