X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fapi.php;h=729f1c766f8f14aa83c11f1e43b5efe23f1b86a8;hb=5f53b1c171d164470d6bbf6002841cdd17c55912;hp=c09d220249775dfe0cc439890f1aa65e28676fb1;hpb=f2a84e5c7c916f6c0d4c7fce69b844b019c17dd1;p=civicrm-core.git diff --git a/api/api.php b/api/api.php index c09d220249..729f1c766f 100644 --- a/api/api.php +++ b/api/api.php @@ -28,9 +28,12 @@ function civicrm_api($entity, $action, $params, $extra = NULL) { /** * Version 3 wrapper for civicrm_api. Throws exception * - * @param string $entity type of entities to deal with - * @param string $action create, get, delete or some special action name. - * @param array $params array to be passed to function + * @param string $entity + * Type of entities to deal with. + * @param string $action + * Create, get, delete or some special action name. + * @param array $params + * Array to be passed to function. * * @throws CiviCRM_API3_Exception * @return array @@ -38,37 +41,40 @@ function civicrm_api($entity, $action, $params, $extra = NULL) { function civicrm_api3($entity, $action, $params = array()) { $params['version'] = 3; $result = civicrm_api($entity, $action, $params); - if(is_array($result) && !empty($result['is_error'])){ + if (is_array($result) && !empty($result['is_error'])) { throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result); } return $result; } /** - * Function to 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 * * @param array $apiRequest - * @return array getfields output + * @return array + * getfields output */ function _civicrm_api3_api_getfields(&$apiRequest) { if (strtolower($apiRequest['action'] == 'getfields')) { // the main param getfields takes is 'action' - however this param is not compatible with REST // so we accept 'api_action' as an alias of action on getfields if (!empty($apiRequest['params']['api_action'])) { - // $apiRequest['params']['action'] = $apiRequest['params']['api_action']; - // unset($apiRequest['params']['api_action']); + // $apiRequest['params']['action'] = $apiRequest['params']['api_action']; + // unset($apiRequest['params']['api_action']); } return array('action' => array('api.aliases' => array('api_action'))); } $getFieldsParams = array('action' => $apiRequest['action']); $entity = $apiRequest['entity']; - if($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) { + if ($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) { $getFieldsParams['profile_id'] = $apiRequest['params']['profile_id']; } $fields = civicrm_api3($entity, 'getfields', $getFieldsParams); @@ -83,10 +89,9 @@ function _civicrm_api3_api_getfields(&$apiRequest) { * * @param $result * - * @internal param array $params (reference ) input parameters - * - * @return boolean true if error, false otherwise - * @static void + * @return boolean + * true if error, false otherwise + * @static * @access public */ function civicrm_error($result) { @@ -100,20 +105,11 @@ function civicrm_error($result) { /** * @param $entity - * @param null $version * * @return string */ -function _civicrm_api_get_camel_name($entity, $version = NULL) { - $fragments = explode('_', $entity); - foreach ($fragments as & $fragment) { - $fragment = ucfirst($fragment); - } - // Special case: UFGroup, UFJoin, UFMatch, UFField - if ($fragments[0] === 'Uf') { - $fragments[0] = 'UF'; - } - return implode('', $fragments); +function _civicrm_api_get_camel_name($entity) { + return CRM_Utils_String::convertStringToCamel($entity); } /** @@ -124,7 +120,6 @@ function _civicrm_api_get_camel_name($entity, $version = NULL) { */ function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResult, $separator = '.') { - foreach ($params as $field => $value) { if (is_string($value) && substr($value, 0, 6) == '$value') { @@ -161,10 +156,13 @@ 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 + * @param string $entity + * Entity name in various formats e.g. Contribution, contribution, + * OptionValue, option_value, UFJoin, uf_join. + * @return string + * 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)) { @@ -182,11 +180,11 @@ function _civicrm_api_get_entity_name_from_camel($entity) { /** * Having a DAO object find the entity name - * @param object $bao DAO being passed in + * @param object $bao + * DAO being passed in. * @return string */ -function _civicrm_api_get_entity_name_from_dao($bao){ +function _civicrm_api_get_entity_name_from_dao($bao) { $daoName = str_replace("BAO", "DAO", get_class($bao)); return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName)); } -