// 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')));
}
*/
function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResult, $separator = '.') {
-
foreach ($params as $field => $value) {
if (is_string($value) && substr($value, 0, 6) == '$value') {
$daoName = str_replace("BAO", "DAO", get_class($bao));
return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName));
}
-
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;
}
function civicrm_api3_action_schedule_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
-
return $errors;
}
-
// processing for custom data
$values = $activityArray = array();
_civicrm_api3_custom_format_params($params, $values, 'Activity');
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');
}
$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;
}
}
-
$sql = '
SELECT count(*)
FROM civicrm_contact
}
}
-
- $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),
);
$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)) {
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
}
return $output;
}
-
function civicrm_api3_activity_type_delete($params) {
return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
}
-
function civicrm_api3_address_get(&$params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address');
}
-
$filePaths = array();
$fileIds = array();
while ($dao->fetch()) {
- $filePaths [] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri;
+ $filePaths[] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri;
$fileIds[] = $dao->id;
}
function civicrm_api3_campaign_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
$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');
}
* @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>
* <li>wysiwygEditor</li>
* </ul>
* @return array
- * @example ConstantGet.php
+ * @example ConstantGet.php
* {@getfields constant_get}
*/
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',
'worldRegion',
'wysiwygEditor',
);
- $params = (array
- ('name' => array(
+ $params = (array(
+ 'name' => array(
'title' => 'Constant Name',
'name' => 'name',
'api.required' => 1,
))
);
}
-
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,
),
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'],
),
);
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;
}
$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'));
}
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;
* @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
}
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
$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));
}
}
$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;
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;
$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);
function civicrm_api3_contact_type_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $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'])){
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'];
* @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();
}
$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);
'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(
$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'];
function civicrm_api3_contribution_soft_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
return _civicrm_api3_basic_get(_civicrm_api3_get_DAO(__FUNCTION__), $params);
}
-
*
* @param array $params
* Array to search on.
- *{*
+ * {*
*
* @return array
@getfields CustomField_get}
* 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;
}
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'])){
'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']
}
}
-
return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao);
}
unset($params['version']);
$params['name']['api.required'] = 1;
}
-
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
// without putting an exception in for entity
return civicrm_api3_create_success(array());
}
-
}
/**
- *{@getfields EntityTag_delete}
+ * {@getfields EntityTag_delete}
* @example EntityTagGet.php
*
* @param array $params
}
return $values;
}
-
*/
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];
}
*
* 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
//try {
// $info = (array) $mapper->keyToInfo($key);
//} catch (CRM_Extension_Exception $e) {
- $info = array();
- $info['key'] = $key;
+ $info = array();
+ $info['key'] = $key;
//}
$info['status'] = $status;
$result[] = $info;
* This api is used for updating an existing file.
* Required parameters : id of a file
*
- * @param Array $params
+ * @param array $paramsAn array of name/value property values of civicrm_file.
* An array of name/value property values of civicrm_file.
*
* @return array of updated file object property values
// todo could set default here probably
$params['domain_id']['api.required'] = 1;
$params['member_of_contact_id']['api.required'] = 1;
- $params['financial_type_id']['api.required'] =1;
+ $params['financial_type_id']['api.required'] = 1;
$params['name']['api.required'] = 1;
$params['duration_unit']['api.required'] = 1;
$params['duration_interval']['api.required'] = 1;
function civicrm_api3_membership_type_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
*/
function _civicrm_api3_message_template_create_spec(&$params) {
$params['msg_title']['api.required'] = 1;
- $params['is_active']['api.default'] = true;
-/* $params['entity_id']['api.required'] = 1;
+ $params['is_active']['api.default'] = TRUE;
+ /* $params['entity_id']['api.required'] = 1;
$params['entity_table']['api.default'] = "civicrm_contribution_recur";
$params['type']['api.default'] = "R";
-*/
+ */
}
/**
$noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
return civicrm_api3_create_success($noteTree, $params);
}
-
civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
}
}
-
'qty' => $qty,
'participant_count' => 0,
'unit_price' => $dao->amount,
- 'line_total' => $qty*$dao->amount,
+ 'line_total' => $qty * $dao->amount,
'version' => 3,
);
civicrm_api('line_item', 'create', $lineItemparams);
throw new Exception('Error while deleting participant');
}
}
-
* Input parameters.
*
* @return array array of properties, if error an array with an error id and error message
- * @example ParticipantPaymentGet
+ * @example ParticipantPaymentGet
* {@getfields ParticipantPayment_get}
* @access public
*/
function civicrm_api3_participant_payment_get($params) {
return _civicrm_api3_basic_get('CRM_Event_DAO_ParticipantPayment', $params);
}
-
return civicrm_api3_create_error(TRUE);
}
-
function civicrm_api3_payment_processor_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
* Could have been implemented here in this file too, but we moved it to illustrate the feature with a real usage.
*
*/
-
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
$values['scheduled_date'] = $values['start_date'];
}
}
-
$dao = CRM_Pledge_BAO_PledgePayment::add($paymentParams);
if(empty($dao->pledge_id)){
- $dao->find(True);
+ $dao->find(TRUE);
}
_civicrm_api3_object_to_array($dao, $result[$dao->id]);
-
//update pledge status
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($dao->pledge_id);
function civicrm_api3_pledge_payment_delete($params) {
if (CRM_Pledge_BAO_PledgePayment::del($params['id'])) {
- return civicrm_api3_create_success(array('id' => $params['id']), $params,'pledge_payment','delete');
+ return civicrm_api3_create_success(array('id' => $params['id']), $params, 'pledge_payment', 'delete');
}
else {
return civicrm_api3_create_error('Could not delete payment');
*/
function civicrm_api3_pledge_payment_get($params) {
-
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
function civicrm_api3_pledge_payment_get_spec(&$params) {
$params['option.create_new'] = array('title' => "Create new field rather than update an unpaid payment");
}
-
* Note that if contact_id is empty an array of defaults is returned
*/
function civicrm_api3_profile_get($params) {
- $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
+ $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
if(!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', array('contact_id' => $params['contact_id'], 'check_permissions' => 1))) {
throw new API_Exception('permission denied');
}
CRM_Core_Permission::EDIT
);
+ if ($isContactActivityProfile) {
+ civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
- if ($isContactActivityProfile) {
- civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
-
- $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'],
+ $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'],
$params['contact_id'],
$params['profile_id']
- );
- if (!empty($errors)) {
- throw new API_Exception(array_pop($errors));
- }
-
- $contactFields = $activityFields = array();
- foreach ($profileFields as $fieldName => $field) {
- if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
- $activityFields[$fieldName] = $field;
+ );
+ if (!empty($errors)) {
+ throw new API_Exception(array_pop($errors));
}
- else {
- $contactFields[$fieldName] = $field;
+
+ $contactFields = $activityFields = array();
+ foreach ($profileFields as $fieldName => $field) {
+ if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
+ $activityFields[$fieldName] = $field;
+ }
+ else {
+ $contactFields[$fieldName] = $field;
// we should return 'Primary' with & without capitalisation. it is more consistent with api to not
// capitalise, but for form support we need it for now. Hopefully we can move away from it
$contactFields[strtolower($fieldName)] = $field;
}
}
- $ufGroupBAO->setProfileDefaults($params['contact_id'], $contactFields, $values[$profileID], TRUE);
+ $ufGroupBAO->setProfileDefaults($params['contact_id'], $contactFields, $values[$profileID], TRUE);
- if ($params['activity_id']) {
- $ufGroupBAO->setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE);
+ if ($params['activity_id']) {
+ $ufGroupBAO->setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE);
+ }
}
- }
- elseif(!empty($params['contact_id'])) {
- $ufGroupBAO->setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE);
+ elseif(!empty($params['contact_id'])) {
+ $ufGroupBAO->setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE);
foreach ($values[$profileID] as $fieldName => $field){
// we should return 'Primary' with & without capitalisation. it is more consistent with api to not
// capitalise, but for form support we need it for now. Hopefully we can move away from it
//@todo get_options should take an array - @ the moment it is only takes 'all' - which is supported
// by other getfields fn
// we don't resolve state, country & county for performance reasons
- $resolveOptions = CRM_Utils_Array::value('get_options',$apirequest['params']) == 'all' ? True : False;
+ $resolveOptions = CRM_Utils_Array::value('get_options', $apirequest['params']) == 'all' ? TRUE : FALSE;
$profileID = _civicrm_api3_profile_getProfileID($apirequest['params']['profile_id']);
$params = _civicrm_api3_buildprofile_submitfields($profileID, $resolveOptions, CRM_Utils_Array::value('cache_clear', $params));
}
elseif (isset($apirequest['params']['cache_clear'])) {
- _civicrm_api3_buildprofile_submitfields(FALSE, FALSE, True);
+ _civicrm_api3_buildprofile_submitfields(FALSE, FALSE, TRUE);
}
$params['profile_id']['api.required'] = TRUE;
$params['profile_id']['title'] = 'Profile ID';
if(empty($params['contact_id'])) {
$config = CRM_Core_Config::singleton();
- $blanks = array(
+ $blanks = array(
'billing_first_name' => '',
'billing_middle_name' => '',
'billing_last_name' => '',
$addressFields = array('street_address', 'city', 'state_province_id', 'country_id', 'postal_code');
$result = civicrm_api3('contact', 'getsingle', array(
'id' => $params['contact_id'],
- 'api.address.get.1' => array('location_type_id' => 'Billing', 'return' => $addressFields),
+ 'api.address.get.1' => array('location_type_id' => 'Billing', 'return' => $addressFields),
// getting the is_billing required or not is an extra db call but probably cheap enough as this isn't an import api
- 'api.address.get.2' => array('is_billing' => True, 'return' => $addressFields),
- 'api.email.get.1' => array('location_type_id' => 'Billing',),
- 'api.email.get.2' => array('is_billing' => True,),
+ 'api.address.get.2' => array('is_billing' => TRUE, 'return' => $addressFields),
+ 'api.email.get.1' => array('location_type_id' => 'Billing'),
+ 'api.email.get.2' => array('is_billing' => TRUE),
'return' => 'api.email.get, api.address.get, api.address.getoptions, country, state_province, email, first_name, last_name, middle_name, ' . implode($addressFields, ','),
)
);
if(!empty($result['api.address.get.1']['count'])) {
foreach ($addressFields as $fieldname) {
- $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.1']['values'][0][$fieldname]) ? $result['api.address.get.1']['values'][0][$fieldname] : '';
+ $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.1']['values'][0][$fieldname]) ? $result['api.address.get.1']['values'][0][$fieldname] : '';
}
}
elseif(!empty($result['api.address.get.2']['count'])) {
foreach ($addressFields as $fieldname) {
- $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.2']['values'][0][$fieldname]) ? $result['api.address.get.2']['values'][0][$fieldname] : '';
+ $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.2']['values'][0][$fieldname]) ? $result['api.address.get.2']['values'][0][$fieldname] : '';
}
}
else{
foreach ($entityFields as $entityfield => $realName) {
$fieldName = strtolower($entityfield);
if(!strstr($fieldName, '-')) {
- if(strtolower($realName) != $fieldName) {
- // we want to keep the '-' pattern for locations but otherwise
- // we are going to make the api-standard field the main / preferred name but support the db name
- // in future naming the fields in the DB to reflect the way the rest of the api / BAO / metadata works would
- // reduce code
- $fieldName = strtolower($realName);
+ if(strtolower($realName) != $fieldName) {
+ // we want to keep the '-' pattern for locations but otherwise
+ // we are going to make the api-standard field the main / preferred name but support the db name
+ // in future naming the fields in the DB to reflect the way the rest of the api / BAO / metadata works would
+ // reduce code
+ $fieldName = strtolower($realName);
}
if(isset($entityGetFieldsResult[$realName]['uniqueName'])) {
// we won't alias the field name on here are we are using uniqueNames for the possibility of needing to differentiate
}
$profileFields[$profileID][$fieldName] = array_merge($entityGetFieldsResult[$realName], $profileFields[$profileID][$entityfield]);
if(!isset($profileFields[$profileID][$fieldName]['api.aliases'])) {
- $profileFields[$profileID][$fieldName]['api.aliases'] = array();
+ $profileFields[$profileID][$fieldName]['api.aliases'] = array();
}
if($optionsBehaviour && !empty($entityGetFieldsResult[$realName]['pseudoconstant'])) {
if($optionsBehaviour > 1 || !in_array($realName, array('state_province_id', 'county_id', 'country_id'))) {
return array('count' => $relationships);
}
foreach ($relationships as $relationshipId => $values) {
- _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id',$values));
+ _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id', $values));
}
return civicrm_api3_create_success($relationships, $params);
}
function civicrm_api3_relationship_type_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
$reportInstance->preProcess();
$reportInstance->setDefaultValues(FALSE);
$reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params));
- $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get');
+ $options = _civicrm_api3_get_options_from_params($params, TRUE, 'report_template', 'get');
$reportInstance->setLimitValue($options['limit']);
$reportInstance->setOffsetValue($options['offset']);
$reportInstance->beginPostProcessCommon();
$params['filters']['name'] = $params['name'];
}
$result = CRM_Core_BAO_Setting::getSettingSpecification(
- CRM_Utils_Array::value('component_id',$params),
+ CRM_Utils_Array::value('component_id', $params),
CRM_Utils_Array::value('filters', $params, array()),
- CRM_Utils_Array::value('domain_id', $params, null),
- CRM_Utils_Array::value('profile', $params, null)
+ CRM_Utils_Array::value('domain_id', $params, NULL),
+ CRM_Utils_Array::value('profile', $params, NULL)
);
// find any supplemental information
if (!empty($params['action'])){
* Note that is not in place as yet
*/
function civicrm_api3_setting_getdefaults(&$params){
- $settings = civicrm_api3('setting','getfields', $params);
+ $settings = civicrm_api3('setting', 'getfields', $params);
$domains = _civicrm_api3_setting_getDomainArray($params);
$defaults = array();
foreach ($domains as $domainID){
print_r($noDefaults);
}
}
- return civicrm_api3_create_success($defaults,$params,'setting','getfields');
+ return civicrm_api3_create_success($defaults, $params, 'setting', 'getfields');
}
/**
* Metadata for setting create function
* Revert settings to defaults
*/
function civicrm_api3_setting_revert(&$params){
- $defaults = civicrm_api('setting','getdefaults', $params);
- $fields = civicrm_api('setting','getfields', $params);
+ $defaults = civicrm_api('setting', 'getdefaults', $params);
+ $fields = civicrm_api('setting', 'getfields', $params);
$fields = $fields['values'];
$domains = _civicrm_api3_setting_getDomainArray($params);
$result = array();
* Revert settings to defaults
*/
function civicrm_api3_setting_fill(&$params){
- $defaults = civicrm_api3('setting','getdefaults', $params);
+ $defaults = civicrm_api3('setting', 'getdefaults', $params);
$domains = _civicrm_api3_setting_getDomainArray($params);
$result = array();
foreach ($domains as $domainID){
'version' => $params['version'],
'domain_id' => $domainID
);
- $existing = civicrm_api3('setting','get', $apiArray);
+ $existing = civicrm_api3('setting', 'get', $apiArray);
$valuesToFill = array_diff_key($defaults['values'][$domainID], $existing['values'][$domainID]);
if(!empty($valuesToFill)){
$result = array_merge($result, civicrm_api('setting', 'create', $valuesToFill + $apiArray));
function civicrm_api3_setting_create($params) {
$domains = _civicrm_api3_setting_getDomainArray($params);
$result = CRM_Core_BAO_Setting::setItems($params, $domains);
- return civicrm_api3_create_success($result,$params,'setting','create');
+ return civicrm_api3_create_success($result, $params, 'setting', 'create');
}
/**
'description' => 'if you do not pass in a domain id this will default to the current domain
an array or "all" are acceptable values for multiple domains'
);
- $params['group'] = array(
+ $params['group'] = array(
'title' => 'Setting Group',
'description' => 'if you know the group defining it will make the api more efficient'
- )
- ;
+ );
}
/**
*/
function civicrm_api3_setting_get($params) {
$domains = _civicrm_api3_setting_getDomainArray($params);
- $result = $result = CRM_Core_BAO_Setting::getItems($params, $domains, CRM_Utils_Array::value('return', $params, array()));
- return civicrm_api3_create_success($result, $params,'setting','get');
+ $result = $result = CRM_Core_BAO_Setting::getItems($params, $domains, CRM_Utils_Array::value('return', $params, array()));
+ return civicrm_api3_create_success($result, $params, 'setting', 'get');
}
/**
* Metadata for setting create function
$params['group'] = array(
'title' => 'Setting Group',
'description' => 'if you know the group defining it will make the api more efficient'
- )
- ;
+ );
}
/**
* Returns value for specific parameter. Function requires more fields than 'get' but is intended for
}
if($params['domain_id'] == 'all'){
- $domainAPIResult = civicrm_api('domain','get',array('version' => 3, 'return' => 'id'));
+ $domainAPIResult = civicrm_api('domain', 'get', array('version' => 3, 'return' => 'id'));
if (isset($domainAPIResult['values'])) {
$params['domain_id'] = array_keys($domainAPIResult['values']);
}
}
return $domains;
}
-
function civicrm_api3_survey_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
$interviewerID = NULL;
if (array_key_exists('interviewer_id', $params)) {
$interviewerID = $params['interviewer_id'];
-}
+ }
$statusIds = array();
if (array_key_exists('status_id', $params)) {
}
return ($signaturesCount);
}
-
);
return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
}
-
* @return array
*/
function civicrm_api3_system_log_delete($params) {
- return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, True, 'SystemLog');
+ return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'SystemLog');
}
/**
* @return array
*/
function _civicrm_api3_system_log_create_spec(&$params) {
- require_once('api/v3/System.php');
- _civicrm_api3_system_log_spec($params);
+ require_once 'api/v3/System.php';
+ _civicrm_api3_system_log_spec($params);
}
/**
* @return array
*/
function civicrm_api3_system_log_get($params) {
- return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, True, 'SystemLog');
+ return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'SystemLog');
}
-
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
// legacy support for field_id
$params['id']['api.aliases'] = array('field_id');
}
-
function civicrm_api3_uf_group_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
function civicrm_api3_uf_join_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
function civicrm_api3_uf_match_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-
//DO NOT USE THIS FUNCTION AS THE BASIS FOR A NEW API http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
$websiteBAO = CRM_Core_BAO_Website::add($params);
- $values = array();
- _civicrm_api3_object_to_array($websiteBAO, $values[$websiteBAO->id]);
- return civicrm_api3_create_success($values, $params, 'website', 'get');
+ $values = array();
+ _civicrm_api3_object_to_array($websiteBAO, $values[$websiteBAO->id]);
+ return civicrm_api3_create_success($values, $params, 'website', 'get');
}
/**
function civicrm_api3_website_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'website');
}
-
*/
function civicrm_api3_word_replacement_get($params) {
$bao = new CRM_Core_BAO_WordReplacement();
- _civicrm_api3_dao_set_filter($bao, $params, true, 'WordReplacement');
- $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, true,'WordReplacement');
+ _civicrm_api3_dao_set_filter($bao, $params, TRUE, 'WordReplacement');
+ $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'WordReplacement');
return civicrm_api3_create_success($wordReplacements, $params, 'word_replacement', 'get', $bao);
}
* @return null or throws error if there the required fields not present
* @
*/
-function civicrm_api3_verify_one_mandatory($params, $daoName = NULL, $keyoptions = array(
- )) {
+function civicrm_api3_verify_one_mandatory($params, $daoName = NULL, $keyoptions = array()) {
$keys = array(array());
foreach ($keyoptions as $key) {
$keys[0][] = $key;
}
}
if (!empty($unmatched)) {
- throw new API_Exception("Mandatory key(s) missing from params array: " . implode(", ", $unmatched),"mandatory_missing",array("fields"=>$unmatched));
+ throw new API_Exception("Mandatory key(s) missing from params array: " . implode(", ", $unmatched), "mandatory_missing", array("fields" => $unmatched));
}
}
* @param array $values
*/
function _civicrm_api3_filter_fields_for_bao($entity, &$params, &$values){
- $fields = civicrm_api($entity,'getfields', array('version' => 3,'action' => 'create'));
+ $fields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => 'create'));
$fields = $fields['values'];
_civicrm_api3_store_values($fields, $params, $values);
}
$$varToFilter = array_intersect_key($$varToFilter, $fields['values']);
}
}
- $options = array_merge($options,$additional_options);
+ $options = array_merge($options, $additional_options);
$sort = CRM_Utils_Array::value('sort', $options, NULL);
$offset = CRM_Utils_Array::value('offset', $options, NULL);
$limit = CRM_Utils_Array::value('limit', $options, NULL);
}
- $skipPermissions = !empty($params['check_permissions']) ? 0 :1;
+ $skipPermissions = !empty($params['check_permissions']) ? 0 : 1;
list($entities, $options) = CRM_Contact_BAO_Query::apiQuery(
$newParams,
$returnProperties,
NULL,
$sort,
- $offset ,
+ $offset,
$limit,
$smartGroupCache,
$getCount,
if (!empty($options['return']) && is_array($options['return']) && empty($options['is_count'])) {
$dao->selectAdd();
$options['return']['id'] = TRUE;// ensure 'id' is included
- $allfields = _civicrm_api3_get_unique_name_array($dao);
+ $allfields = _civicrm_api3_get_unique_name_array($dao);
$returnMatched = array_intersect(array_keys($options['return']), $allfields);
foreach ($returnMatched as $returnValue) {
$dao->selectAdd($returnValue);
$returnProperties = array_fill_keys($returnProperties, 1);
}
}
- if ($entity && $action =='get') {
+ if ($entity && $action == 'get') {
if (!empty($returnProperties['id'])) {
$returnProperties[$entity . '_id'] = 1;
unset($returnProperties['id']);
}
switch (trim(strtolower($sort))){
- case 'id':
- case 'id desc':
- case 'id asc':
- $sort = str_replace('id', $entity . '_id',$sort);
+ case 'id':
+ case 'id desc':
+ case 'id asc':
+ $sort = str_replace('id', $entity . '_id', $sort);
}
}
$inputParams = array();
$legacyreturnProperties = array();
$otherVars = array(
- 'sort', 'offset', 'rowCount', 'options','return',
+ 'sort', 'offset', 'rowCount', 'options', 'return',
);
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
elseif ($n == 'id') {
$inputParams[$entity. '_id'] = $v;
}
- elseif (in_array($n, $otherVars)) {}
+ elseif (in_array($n, $otherVars)) {
+ }
else {
$inputParams[$n] = $v;
if ($v && !is_array($v) && stristr($v, 'SELECT')) {
*/
function _civicrm_api3_apply_options_to_dao(&$params, &$dao, $entity) {
- $options = _civicrm_api3_get_options_from_params($params,FALSE,$entity);
+ $options = _civicrm_api3_get_options_from_params($params, FALSE, $entity);
if(!$options['is_count']) {
if(!empty($options['limit'])) {
- $dao->limit((int)$options['offset'], (int)$options['limit']);
+ $dao->limit((int) $options['offset'], (int) $options['limit']);
}
if (!empty($options['sort'])) {
$dao->orderBy($options['sort']);
$fields = $bao->fields();
if ($unique) {
if (empty($fields['id'])){
- $entity = _civicrm_api_get_entity_name_from_dao($bao);
- $fields['id'] = $fields[$entity . '_id'];
- unset($fields[$entity . '_id']);
+ $entity = _civicrm_api_get_entity_name_from_dao($bao);
+ $fields['id'] = $fields[$entity . '_id'];
+ unset($fields[$entity . '_id']);
}
return $fields;
}
function _civicrm_api3_get_unique_name_array(&$bao) {
$fields = $bao->fields();
foreach ($fields as $field => $values) {
- $uniqueFields[$field] = CRM_Utils_Array::value('name',$values, $field);
+ $uniqueFields[$field] = CRM_Utils_Array::value('name', $values, $field);
}
return $uniqueFields;
}
}
}
-
return $result;
}
foreach ($params as $key => $value) {
list($customFieldID, $customValueID) = CRM_Core_BAO_CustomField::getKeyID($key, TRUE);
- if ($customFieldID && (!IS_NULL($value))) {
+ if ($customFieldID && (!is_null($value))) {
if ($checkCheckBoxField && !empty($fields['custom_' . $customFieldID]) && $fields['custom_' . $customFieldID]['html_type'] == 'CheckBox') {
formatCheckBoxField($value, 'custom_' . $customFieldID, $entity);
}
$bao = new $bao_name();
_civicrm_api3_dao_set_filter($bao, $params, TRUE, $entity);
if ($returnAsSuccess) {
- return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity, 'get');
+ return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity, 'get');
}
else {
return _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity, 'get');
* ErrorMode do intensive post fail checks?.
* @throws Exception
*/
-function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $errorMode = False) {
+function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $errorMode = FALSE) {
$fields = array_intersect_key($fields, $params);
foreach ($fields as $fieldName => $fieldInfo) {
switch (CRM_Utils_Array::value('type', $fieldInfo)) {
_civicrm_api3_validate_date($params, $fieldName, $fieldInfo);
break;
- case 32://blob
+ case 32://blob
_civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
break;
if (!is_numeric($params[$fieldName]) && is_scalar($params[$fieldName])) {
$realContactId = _civicrm_api3_resolve_contactID($params[$fieldName]);
if ('unknown-user' === $realContactId) {
- throw new API_Exception("\"$fieldName\" \"{$params[$fieldName]}\" cannot be resolved to a contact ID", 2002, array('error_field' => $fieldName,"type"=>"integer"));
+ throw new API_Exception("\"$fieldName\" \"{$params[$fieldName]}\" cannot be resolved to a contact ID", 2002, array('error_field' => $fieldName, "type" => "integer"));
} elseif (is_numeric($realContactId)) {
$params[$fieldName] = $realContactId;
}
if(is_string($params[$fieldName]) && !empty($fieldInfo['maxlength']) && strlen($params[$fieldName]) > $fieldInfo['maxlength']
){
throw new API_Exception( $params[$fieldName] . " is " . strlen($params[$fieldName]) . " characters - longer than $fieldName length" . $fieldInfo['maxlength'] . ' characters',
- 2100, array('field' => $fieldName, "max_length"=>$fieldInfo['maxlength'])
+ 2100, array('field' => $fieldName, "max_length" => $fieldInfo['maxlength'])
);
}
}
function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
if ($value = CRM_Utils_Array::value($fieldName, $params)) {
if (!CRM_Utils_Rule::xssString($value)) {
- throw new API_Exception(ts('Illegal characters in input (potential scripting attack)'), array("field"=>$fieldName,"error_code"=>"xss"));
+ throw new API_Exception(ts('Illegal characters in input (potential scripting attack)'), array("field" => $fieldName, "error_code" => "xss"));
}
}
}