Commit 35671d00 authored by totten's avatar totten
Browse files

INFRA-132 - api/ - phpcbf

parent e7292422
......@@ -64,8 +64,8 @@ function _civicrm_api3_api_getfields(&$apiRequest) {
// 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')));
}
......@@ -116,7 +116,6 @@ function _civicrm_api_get_camel_name($entity) {
*/
function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResult, $separator = '.') {
foreach ($params as $field => $value) {
if (is_string($value) && substr($value, 0, 6) == '$value') {
......@@ -183,4 +182,3 @@ 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));
}
......@@ -73,7 +73,7 @@ function civicrm_api3_action_schedule_create($params) {
function _civicrm_api3_action_schedule_create_spec(&$params) {
$params['title']['api.required'] = TRUE;
$params['mapping_id']['api.required'] = TRUE;
// $params['entity_status']['api.required'] = TRUE;
// $params['entity_status']['api.required'] = TRUE;
$params['entity_value']['api.required'] = TRUE;
}
......@@ -91,5 +91,3 @@ function _civicrm_api3_action_schedule_create_spec(&$params) {
function civicrm_api3_action_schedule_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
......@@ -76,7 +76,6 @@ function civicrm_api3_activity_create($params) {
return $errors;
}
// processing for custom data
$values = $activityArray = array();
_civicrm_api3_custom_format_params($params, $values, 'Activity');
......@@ -236,7 +235,7 @@ function civicrm_api3_activity_get($params) {
else {
$activities = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
}
$options = _civicrm_api3_get_options_from_params($params, FALSE,'activity','get');
$options = _civicrm_api3_get_options_from_params($params, FALSE, 'activity', 'get');
if($options['is_count']) {
return civicrm_api3_create_success($activities, $params, 'activity', 'get');
}
......@@ -278,16 +277,19 @@ function _civicrm_api3_activity_get_formatResult($params, $activities) {
$activities[$key]['assignee_contact_id'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activityArray['id']);
}
break;
case 'target_contact_id':
foreach ($activities as $key => $activityArray) {
$activities[$key]['target_contact_id'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityArray['id']);
}
break;
case 'source_contact_id':
foreach ($activities as $key => $activityArray) {
$activities[$key]['source_contact_id'] = CRM_Activity_BAO_Activity::getSourceContactID($activityArray['id']);
}
break;
default:
if (substr($n, 0, 6) == 'custom') {
$returnProperties[$n] = $v;
......@@ -369,7 +371,6 @@ function _civicrm_api3_activity_check_params(&$params) {
}
}
$sql = '
SELECT count(*)
FROM civicrm_contact
......@@ -379,8 +380,8 @@ SELECT count(*)
}
}
$activityIds = array('activity' => CRM_Utils_Array::value('id', $params),
$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),
);
......@@ -409,7 +410,7 @@ SELECT count(*)
$activityTypeIdInList = array_search(($activityName ? $activityName : $activityLabel), $activityTypes);
if (!$activityTypeIdInList) {
$errorString = $activityName ? "Invalid Activity Name : $activityName" : "Invalid Activity Type Label";
$errorString = $activityName ? "Invalid Activity Name : $activityName" : "Invalid Activity Type Label";
throw new Exception($errorString);
}
elseif ($activityTypeId && ($activityTypeId != $activityTypeIdInList)) {
......@@ -430,7 +431,6 @@ SELECT count(*)
throw new API_Exception('Invalid Activity Duration (in minutes)');
}
//if adding a new activity & date_time not set make it now
// this should be managed by the wrapper layer & setting ['api.default'] in speces
// needs testing
......@@ -490,4 +490,3 @@ function _civicrm_api3_activity_getlist_output($result, $request) {
}
return $output;
}
......@@ -118,4 +118,3 @@ function _civicrm_api3_activity_type_create_spec(&$params) {
function civicrm_api3_activity_type_delete($params) {
return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
}
......@@ -155,4 +155,3 @@ function civicrm_api3_address_delete($params) {
function civicrm_api3_address_get(&$params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address');
}
......@@ -210,7 +210,7 @@ function civicrm_api3_attachment_delete($params) {
$filePaths = array();
$fileIds = array();
while ($dao->fetch()) {
$filePaths [] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri;
$filePaths[] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri;
$fileIds[] = $dao->id;
}
......
......@@ -98,4 +98,3 @@ function civicrm_api3_campaign_get($params) {
function civicrm_api3_campaign_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
......@@ -258,13 +258,13 @@ SELECT DISTINCT case_id
$options['return'] = array('contacts' => 1, 'activities' => 1);
}
$foundcases = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Case');
$foundcases = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Case');
$cases = array();
foreach ($foundcases['values'] as $foundcase) {
if ($case = _civicrm_api3_case_read($foundcase['id'], $options)) {
$cases[$foundcase['id']] = $case;
}
if ($case = _civicrm_api3_case_read($foundcase['id'], $options)) {
$cases[$foundcase['id']] = $case;
}
}
return civicrm_api3_create_success($cases, $params, 'case', 'get');
}
......
......@@ -48,7 +48,7 @@ function _civicrm_api3_constant_deprecation() {
* @deprecated as of CiviCRM 4.4.
* It's recommended to use the api getoptions action instead
*
* @param string Name of a public static method of
* @param string Name of a public static method of
* CRM_Core_PseudoConstant: one of
* <ul>
* <li>activityStatus</li>
......@@ -93,7 +93,7 @@ function _civicrm_api3_constant_deprecation() {
* <li>wysiwygEditor</li>
* </ul>
* @return array
* @example ConstantGet.php
* @example ConstantGet.php
* {@getfields constant_get}
*/
function civicrm_api3_constant_get($params) {
......@@ -103,7 +103,6 @@ function civicrm_api3_constant_get($params) {
//ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
// once tests are 100% can try removing the first block & a similar block from Generic:getoptions
// Whitelist approach is safer
$allowedClasses = array(
'CRM_Core_PseudoConstant',
......@@ -183,8 +182,8 @@ function _civicrm_api3_constant_get_spec(&$params) {
'worldRegion',
'wysiwygEditor',
);
$params = (array
('name' => array(
$params = (array(
'name' => array(
'title' => 'Constant Name',
'name' => 'name',
'api.required' => 1,
......@@ -192,4 +191,3 @@ function _civicrm_api3_constant_get_spec(&$params) {
))
);
}
......@@ -69,7 +69,8 @@ function civicrm_api3_contact_create($params) {
if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
$defLocType = CRM_Core_BAO_LocationType::getDefault();
$params['email'] = array(
1 => array('email' => $email,
1 => array(
'email' => $email,
'is_primary' => 1,
'location_type_id' => ($defLocType->id) ? $defLocType->id : 1,
),
......@@ -79,7 +80,9 @@ function civicrm_api3_contact_create($params) {
if (!empty($params['home_url'])) {
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$params['website'] = array(1 => array('website_type_id' => key($websiteTypes),
$params['website'] = array(
1 => array(
'website_type_id' => key($websiteTypes),
'url' => $params['home_url'],
),
);
......@@ -164,7 +167,7 @@ function civicrm_api3_contact_get($params) {
function civicrm_api3_contact_getcount($params) {
$options = array();
_civicrm_api3_contact_get_supportanomalies($params, $options);
$count = _civicrm_api3_get_using_query_object('contact', $params, $options,1);
$count = _civicrm_api3_get_using_query_object('contact', $params, $options, 1);
return (int) $count;
}
......@@ -212,7 +215,7 @@ function _civicrm_api3_contact_get_spec(&$params) {
$params['tag']['title'] = 'Assigned tags (filter, array)';
$params['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or greater than'));
$params['birth_date_high'] = array('name' => 'birth_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or less than'));
$params['deceased_date_low'] = array('name' => 'deceased_date_low','type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or greater than'));
$params['deceased_date_low'] = array('name' => 'deceased_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or greater than'));
$params['deceased_date_high'] = array('name' => 'deceased_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or less than'));
}
......@@ -251,7 +254,8 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
if (is_array($params['filter.group_id'])) {
$groups = $params['filter.group_id'];
}
else $groups = explode(',', $params['filter.group_id']);
else { $groups = explode(',', $params['filter.group_id']);
}
unset($params['filter.group_id']);
$groups = array_flip($groups);
$groups[key($groups)] = 1;
......@@ -308,25 +312,27 @@ function civicrm_api3_contact_delete($params) {
* @throws API_Exception
* @throws CiviCRM_API3_Exception
*/
function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeErrorArray = false, $obsoletevalue = true, $dedupeRuleGroupID = null )
function _civicrm_api3_contact_check_params(&$params, $dupeCheck = TRUE, $dupeErrorArray = FALSE, $obsoletevalue = TRUE, $dedupeRuleGroupID = NULL)
{
switch (strtolower(CRM_Utils_Array::value('contact_type', $params))) {
case 'household':
civicrm_api3_verify_mandatory($params, null, array('household_name'));
civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
break;
case 'organization':
civicrm_api3_verify_mandatory($params, null, array('organization_name'));
civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
break;
case 'individual':
civicrm_api3_verify_one_mandatory($params, null, array(
civicrm_api3_verify_one_mandatory($params, NULL, array(
'first_name',
'last_name',
'email',
'display_name',
)
);
break;
);
break;
}
// Fixme: This really needs to be handled at a lower level. @See CRM-13123
......@@ -335,10 +341,10 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
}
if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array)$params['contact_sub_type']));
}
if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
}
}
if ($dupeCheck) {
// check for record already existing
......@@ -354,8 +360,8 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Unsupervised', array());
if (count($ids) >0) {
throw new API_Exception("Found matching contacts: ". implode(',',$ids),"duplicate",array("ids"=>$ids));
if (count($ids) > 0) {
throw new API_Exception("Found matching contacts: ". implode(',', $ids), "duplicate", array("ids" => $ids));
}
}
......@@ -510,13 +516,11 @@ function _civicrm_api3_greeting_format_params($params) {
$greetingId = CRM_Utils_Array::key('Customized', $greetings);
}
$customValue = isset($params['contact_id']) ?
CRM_Core_DAO::getFieldValue(
$customValue = isset($params['contact_id']) ? CRM_Core_DAO::getFieldValue(
'CRM_Contact_DAO_Contact',
$params['contact_id'],
"{$key}{$greeting}_custom"
) :
FALSE;
) : FALSE;
if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
$nullValue = TRUE;
......@@ -810,7 +814,7 @@ LIMIT 0, {$limit}
while ($dao->fetch()) {
$t = array('id' => $dao->id);
foreach ($as as $k) {
$t[$k] = isset($dao->$k)? $dao->$k: '';
$t[$k] = isset($dao->$k) ? $dao->$k : '';
}
$t['data'] = $dao->data;
$contactList[] = $t;
......@@ -877,7 +881,8 @@ function civicrm_api3_contact_merge($params) {
$mode = CRM_Utils_Array::value('mode', $params, 'safe');
$autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE);
$dupePairs = array(array('srcID' => CRM_Utils_Array::value('main_id', $params),
$dupePairs = array(array(
'srcID' => CRM_Utils_Array::value('main_id', $params),
'dstID' => CRM_Utils_Array::value('other_id', $params),
));
$result = CRM_Dedupe_Merger::merge($dupePairs, array(), $mode, $autoFlip);
......
......@@ -98,4 +98,3 @@ function civicrm_api3_contact_type_get($params) {
function civicrm_api3_contact_type_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
......@@ -147,11 +147,11 @@ function _civicrm_api3_contribution_create_spec(&$params) {
}
/**
* Support for schema changes made in 4.5
* The main purpose of the API is to provide integrators a level of stability not provided by
* the core code or schema - this means we have to provide support for api calls (where possible)
* across schema changes.
*/
* Support for schema changes made in 4.5
* The main purpose of the API is to provide integrators a level of stability not provided by
* the core code or schema - this means we have to provide support for api calls (where possible)
* across schema changes.
*/
function _civicrm_api3_contribution_create_legacy_support_45(&$params){
//legacy soft credit handling - recommended approach is chaining
if(!empty($params['soft_credit_to'])){
......@@ -222,7 +222,7 @@ function civicrm_api3_contribution_get($params) {
while ($dao->fetch()) {
//CRM-8662
$contribution_details = $query->store($dao);
$softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id , TRUE);
$softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id, TRUE);
$contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution);
if(isset($contribution[$dao->contribution_id]['financial_type_id'])){
$contribution[$dao->contribution_id]['financial_type_id'] = $contribution[$dao->contribution_id]['financial_type_id'];
......@@ -278,7 +278,7 @@ function _civicrm_api3_contribution_get_spec(&$params) {
* @access public
*/
function _civicrm_api3_contribute_format_params($params, &$values, $create = FALSE) {
//legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
//legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
_civicrm_api3_filter_fields_for_bao('Contribution', $params, $values);
return array();
}
......@@ -365,7 +365,7 @@ function civicrm_api3_contribution_sendconfirmation($params) {
$contribution->id = $params['id'];
if (! $contribution->find(TRUE)) {
throw new Exception('Contribution does not exist');
}
}
$input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE);
$contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
......@@ -384,7 +384,7 @@ function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
'title' => 'Contribution ID'
);
$params['receipt_from_email'] = array(
'api.required' =>1,
'api.required' => 1,
'title' => 'From Email address (string) required until someone provides a patch :-)',
);
$params['receipt_from_name'] = array(
......@@ -437,7 +437,7 @@ function civicrm_api3_contribution_completetransaction(&$params) {
$objects['contribution'] = &$contribution;
$input['component'] = $contribution->_component;
$input['is_test'] = $contribution->is_test;
$input['trxn_id']= !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
$input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
$input['amount'] = $contribution->total_amount;
if(isset($params['is_email_receipt'])){
$input['is_email_receipt'] = $params['is_email_receipt'];
......
......@@ -102,4 +102,3 @@ function civicrm_api3_contribution_soft_delete($params) {
function civicrm_api3_contribution_soft_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
......@@ -99,4 +99,3 @@ function civicrm_api3_country_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_DAO(__FUNCTION__), $params);
}
......@@ -137,7 +137,7 @@ function civicrm_api3_custom_field_delete($params) {
*
* @param array $params
* Array to search on.
*{*
* {*
*
* @return array
@getfields CustomField_get}
......@@ -166,8 +166,8 @@ function civicrm_api3_custom_field_get($params) {
* removing as it might be useful in wrapper layer
*/
function _civicrm_api3_custom_field_validate_field($fieldName, $value, $fieldDetails, &$errors = array()) {
return;
//see comment block
return;
//see comment block
if (!$value) {
return $errors;
}
......
......@@ -56,8 +56,8 @@ function civicrm_api3_domain_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
_civicrm_api3_dao_set_filter($bao, $params, true, 'domain');
$domains = _civicrm_api3_dao_to_array($bao, $params, true,'domain');
_civicrm_api3_dao_set_filter($bao, $params, TRUE, 'domain');
$domains = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'domain');
foreach ($domains as $domain) {
if(!empty($domain['contact_id'])){
......@@ -85,21 +85,21 @@ function civicrm_api3_domain_get($params) {
'phone_type_id',
$values['location']['phone'][1]
)
),
),
'phone' => CRM_Utils_Array::value(
'phone',
$values['location']['phone'][1]
)
);
}
);
}
if ( !empty( $values['location']['address'] ) ) {
foreach ($address_array as $value) {
$domain['domain_address'][$value] = CRM_Utils_Array::value($value,
if ( !empty( $values['location']['address'] ) ) {
foreach ($address_array as $value) {
$domain['domain_address'][$value] = CRM_Utils_Array::value($value,
$values['location']['address'][1]
);
);
}
}
}
list($domain['from_name'],
$domain['from_email']
......@@ -108,7 +108,6 @@ function civicrm_api3_domain_get($params) {
}
}
return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao);
}
......@@ -150,4 +149,3 @@ function _civicrm_api3_domain_create_spec(&$params) {
unset($params['version']);
$params['name']['api.required'] = 1;
}
......@@ -101,4 +101,3 @@ function civicrm_api3_email_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
......@@ -39,4 +39,3 @@ function civicrm_api3_entity_getfields($params) {
// without putting an exception in for entity
return civicrm_api3_create_success(array());
}
......@@ -89,7 +89,7 @@ function civicrm_api3_entity_tag_create($params) {
}
/**
*{@getfields EntityTag_delete}
* {@getfields EntityTag_delete}
* @example EntityTagGet.php
*
* @param array $params
......@@ -163,4 +163,3 @@ function _civicrm_api3_entity_tag_common($params, $op = 'add') {
}
return $values;
}
......@@ -177,7 +177,7 @@ function _civicrm_api3_event_get_spec(&$params) {
*/
function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id){
if(!empty($event[$event_id]['payment_processor'])){
$processors = explode(CRM_Core_DAO::VALUE_SEPARATOR,$event[$event_id]['payment_processor']);
$processors = explode(CRM_Core_DAO::VALUE_SEPARATOR, $event[$event_id]['payment_processor']);
if(count($processors) == 3 ){
$event[$event_id]['payment_processor_id'] = $processors[1];
}
......@@ -189,7 +189,7 @@ function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id){
*
* This API is used for deleting a event
*
* @param Array $params
* @param array $paramsArray containing event_id to be deleted.
* Array containing event_id to be deleted.
*
* @return boolean true if success, error otherwise
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment