<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
- * @param array $params Associative array of property name/value
+ * @param array $params Associative array of property name/value
* pairs to insert in new contact.
- * @param array $values The reformatted properties that we can use internally
+ * @param array $values The reformatted properties that we can use internally
*
- * @param array $create Is the formatted Values array going to
+ * @param array|bool $create Is the formatted Values array going to
* be used for CRM_vent_BAO_Participant:create()
*
* @return array|CRM_Error
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
- * @param array $params Associative array of property name/value
+ * @param array $params Associative array of property name/value
* pairs to insert in new contact.
- * @param array $values The reformatted properties that we can use internally
+ * @param array $values The reformatted properties that we can use internally
* '
*
+ * @param bool $create
+ * @param null $onDuplicate
+ *
* @return array|CRM_Error
* @access public
*/
-function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = FALSE) {
+function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = FALSE, $onDuplicate = Null) {
// copy all the contribution fields as is
$fields = CRM_Contribute_DAO_Contribution::fields();
}
}
}
- elseif ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id']) {
+ elseif (!empty($params['contribution_id']) || !empty($params['trxn_id']) || !empty($params['invoice_id'])) {
//when update mode check contribution id or trxn id or
//invoice id
$contactId = new CRM_Contribute_DAO_Contribution();
- if ($params['contribution_id']) {
+ if (!empty($params['contribution_id'])) {
$contactId->id = $params['contribution_id'];
}
- elseif ($params['trxn_id']) {
+ elseif (!empty($params['trxn_id'])) {
$contactId->trxn_id = $params['trxn_id'];
}
- elseif ($params['invoice_id']) {
+ elseif (!empty($params['invoice_id'])) {
$contactId->invoice_id = $params['invoice_id'];
}
if ($contactId->find(TRUE)) {
}
}
}
+ else {
+ if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
+ return civicrm_api3_create_error("Empty Contribution and Invoice and Transaction ID. Row was skipped.");
+ }
+ else {
+ return civicrm_api3_create_error("Empty Contact and External ID. Row was skipped.");
+ }
+ }
break;
case 'receive_date':
break;
}
}
- if (!CRM_Utils_Array::value('financial_type_id', $values)) {
+ if (empty($values['financial_type_id'])) {
return civicrm_api3_create_error("Financial Type is not valid: $value");
}
break;
case 'payment_instrument':
require_once 'CRM/Core/OptionGroup.php';
$values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
- if (!CRM_Utils_Array::value('payment_instrument_id', $values)) {
+ if (empty($values['payment_instrument_id'])) {
return civicrm_api3_create_error("Payment Instrument is not valid: $value");
}
break;
}
break;
- case 'honor_type_id':
- require_once 'CRM/Core/OptionGroup.php';
- $values['honor_type_id'] = CRM_Core_OptionGroup::getValue('honor_type', $value);
- if (!CRM_Utils_Array::value('honor_type_id', $values)) {
- return civicrm_api3_create_error("Honor Type is not valid: $value");
- }
- break;
-
case 'soft_credit':
//import contribution record according to select contact type
-
// validate contact id and external identifier.
- $contactId = CRM_Utils_Array::value('contact_id', $params['soft_credit']);
- $externalId = CRM_Utils_Array::value('external_identifier', $params['soft_credit']);
- if ($contactId || $externalId) {
- require_once 'CRM/Contact/DAO/Contact.php';
- $contact = new CRM_Contact_DAO_Contact();
- $contact->id = $contactId;
- $contact->external_identifier = $externalId;
-
- $errorMsg = NULL;
- if (!$contact->find(TRUE)) {
- $errorMsg = ts("No match found for specified Soft Credit contact data. Row was skipped.");
- }
-
- if ($errorMsg) {
- return civicrm_api3_create_error($errorMsg, 'soft_credit');
- }
-
- // finally get soft credit contact id.
- $values['soft_credit_to'] = $contact->id;
- }
- else {
- // get the contact id from duplicate contact rule, if more than one contact is returned
- // we should return error, since current interface allows only one-one mapping
-
- $softParams = $params['soft_credit'];
- $softParams['contact_type'] = $params['contact_type'];
-
- $error = _civicrm_api3_deprecated_duplicate_formatted_contact($softParams);
+ $value[$key] = $mismatchContactType = $softCreditContactIds = '';
+ if (isset($params[$key]) && is_array($params[$key])) {
+ foreach ($params[$key] as $softKey => $softParam) {
+ $contactId = CRM_Utils_Array::value('contact_id', $softParam);
+ $externalId = CRM_Utils_Array::value('external_identifier', $softParam);
+ $email = CRM_Utils_Array::value('email', $softParam);
+ if ($contactId || $externalId) {
+ require_once 'CRM/Contact/DAO/Contact.php';
+ $contact = new CRM_Contact_DAO_Contact();
+ $contact->id = $contactId;
+ $contact->external_identifier = $externalId;
+ $errorMsg = NULL;
+ if (!$contact->find(TRUE)) {
+ $errorMsg = $contactId ? ts("Soft Credit ContactID - $contactId doesn't exist. Row was skipped.") : ts("Provided Soft Credit External Identifier - $externalIddoesn't exist. Row was skipped.");
+ }
- if (isset($error['error_message']['params'][0])) {
- $matchedIDs = explode(',', $error['error_message']['params'][0]);
+ if ($errorMsg) {
+ return civicrm_api3_create_error($errorMsg, $value[$key]);
+ }
- // check if only one contact is found
- if (count($matchedIDs) > 1) {
- return civicrm_api3_create_error($error['error_message']['message'], 'soft_credit');
+ // finally get soft credit contact id.
+ $values[$key][$softKey] = $softParam;
+ $values[$key][$softKey]['contact_id'] = $contact->id;
}
- else {
- $values['soft_credit_to'] = $matchedIDs[0];
+ elseif ($email) {
+ if (!CRM_Utils_Rule::email($email)) {
+ return civicrm_api3_create_error("Invalid email address $email provided for Soft Credit. Row was skipped");
+ }
+
+ // get the contact id from duplicate contact rule, if more than one contact is returned
+ // we should return error, since current interface allows only one-one mapping
+ $emailParams = array('email' => $email, 'contact_type' => $params['contact_type']);
+ $checkDedupe = _civicrm_api3_deprecated_duplicate_formatted_contact($emailParams);
+ if (!$checkDedupe['is_error']) {
+ return civicrm_api3_create_error("Invalid email address(doesn't exist) $email for Soft Credit. Row was skipped");
+ }
+ else {
+ $matchingContactIds = explode(',', $checkDedupe['error_message']['params'][0]);
+ if (count($matchingContactIds) > 1) {
+ return civicrm_api3_create_error("Invalid email address(duplicate) $email for Soft Credit. Row was skipped");
+ }
+ elseif (count($matchingContactIds) == 1) {
+ $contactId = $matchingContactIds[0];
+ unset($softParam['email']);
+ $values[$key][$softKey] = $softParam + array('contact_id' => $contactId);
+ }
+ }
}
}
- else {
- return civicrm_api3_create_error('No match found for specified Soft Credit contact data. Row was skipped.', 'soft_credit');
- }
- }
- break;
+ }
+ break;
case 'pledge_payment':
case 'pledge_id':
//giving respect to pledge_payment flag.
- if (!CRM_Utils_Array::value('pledge_payment', $params)) {
+ if (empty($params['pledge_payment'])) {
continue;
}
}
else {
// first get the contact id for given contribution record.
- if (CRM_Utils_Array::value('contribution_contact_id', $params)) {
+ if (!empty($params['contribution_contact_id'])) {
$contributionContactID = $params['contribution_contact_id'];
}
- elseif (CRM_Utils_Array::value('external_identifier', $params)) {
+ elseif (!empty($params['external_identifier'])) {
require_once 'CRM/Contact/DAO/Contact.php';
$contact = new CRM_Contact_DAO_Contact();
$contact->external_identifier = $params['external_identifier'];
}
}
- if (CRM_Utils_Array::value('pledge_id', $params)) {
+ if (!empty($params['pledge_id'])) {
if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) {
return civicrm_api3_create_error('Invalid Pledge ID provided. Contribution row was skipped.', 'pledge_payment');
}
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
- * @param array $params Associative array of property name/value
+ * @param array $params Associative array of property name/value
* pairs to insert in new contact.
- * @param array $values The reformatted properties that we can use internally
+ * @param array $values The reformatted properties that we can use internally
*
- * @param array $create Is the formatted Values array going to
+ * @param array|bool $create Is the formatted Values array going to
* be used for CRM_Activity_BAO_Activity::create()
*
* @return array|CRM_Error
}
if (isset($values['individual_prefix'])) {
- if (CRM_Utils_Array::value('prefix_id', $params)) {
+ if (!empty($params['prefix_id'])) {
$prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
$params['prefix'] = $prefixes[$params['prefix_id']];
}
}
if (isset($values['individual_suffix'])) {
- if (CRM_Utils_Array::value('suffix_id', $params)) {
+ if (!empty($params['suffix_id'])) {
$suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
$params['suffix'] = $suffixes[$params['suffix_id']];
}
//CRM-4575
if (isset($values['email_greeting'])) {
- if (CRM_Utils_Array::value('email_greeting_id', $params)) {
+ if (!empty($params['email_greeting_id'])) {
$emailGreetingFilter = array(
'contact_type' => CRM_Utils_Array::value('contact_type', $params),
'greeting_type' => 'email_greeting',
}
if (isset($values['postal_greeting'])) {
- if (CRM_Utils_Array::value('postal_greeting_id', $params)) {
+ if (!empty($params['postal_greeting_id'])) {
$postalGreetingFilter = array(
'contact_type' => CRM_Utils_Array::value('contact_type', $params),
'greeting_type' => 'postal_greeting',
}
if (isset($values['addressee'])) {
- if (CRM_Utils_Array::value('addressee_id', $params)) {
+ if (!empty($params['addressee_id'])) {
$addresseeFilter = array(
'contact_type' => CRM_Utils_Array::value('contact_type', $params),
'greeting_type' => 'addressee',
}
if (isset($values['gender'])) {
- if (CRM_Utils_Array::value('gender_id', $params)) {
+ if (!empty($params['gender_id'])) {
$genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
$params['gender'] = $genders[$params['gender_id']];
}
}
//format the website params.
- if (CRM_Utils_Array::value('url', $values)) {
+ if (!empty($values['url'])) {
static $websiteFields;
if (!is_array($websiteFields)) {
require_once 'CRM/Core/DAO/Website.php';
}
// get the formatted location blocks into params - w/ 3.0 format, CRM-4605
- if (CRM_Utils_Array::value('location_type_id', $values)) {
+ if (!empty($values['location_type_id'])) {
_civicrm_api3_deprecated_add_formatted_location_blocks($values, $params);
return TRUE;
}
/* Check for custom field values */
- if (!CRM_Utils_Array::value('custom', $fields)) {
+ if (empty($fields['custom'])) {
$fields['custom'] = &CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values),
FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE
);
$params[$name][++$blockCnt]
);
- if (!CRM_Utils_Array::value('id', $params) && ($blockCnt == 1)) {
+ if (empty($params['id']) && ($blockCnt == 1)) {
$params[$name][$blockCnt]['is_primary'] = TRUE;
}
// Note: we doing multiple value formatting here for address custom fields, plus putting into right format.
// The actual formatting (like date, country ..etc) for address custom fields is taken care of while saving
// the address in CRM_Core_BAO_Address::create method
- if (CRM_Utils_Array::value('location_type_id', $values)) {
+ if (!empty($values['location_type_id'])) {
static $customFields = array();
if (empty($customFields)) {
$customFields = CRM_Core_BAO_CustomField::getFields('Address');
*
* @param <type> $params
*
- * @return <type>
+ * @return array <type>
*/
function _civicrm_api3_deprecated_duplicate_formatted_contact($params) {
$id = CRM_Utils_Array::value('id', $params);
}
//check for loc type id.
- if (!CRM_Utils_Array::value('location_type_id', $values)) {
+ if (empty($values['location_type_id'])) {
return civicrm_api3_create_error('Location Type Id missing.');
}
}
}
-
/**
* @deprecated - this is part of the import parser not the API & needs to be moved on out
*
- * @param <type> $params
- * @param <type> $onDuplicate
+ * @param $params
+ * @param $onDuplicate
+ *
+ * @internal param $ <type> $params
+ * @internal param $ <type> $onDuplicate
*
- * @return <type>
+ * @return array|bool <type>
*/
function _civicrm_api3_deprecated_create_participant_formatted($params, $onDuplicate) {
require_once 'CRM/Event/Import/Parser.php';
*
* @param <type> $params
*
- * @return <type>
+ * @param bool $checkDuplicate
+ *
+ * @return array|bool <type>
*/
function _civicrm_api3_deprecated_participant_check_params($params, $checkDuplicate = FALSE) {
//check if participant id is valid or not
- if (CRM_Utils_Array::value('id', $params)) {
+ if (!empty($params['id'])) {
$participant = new CRM_Event_BAO_Participant();
$participant->id = $params['id'];
if (!$participant->find(TRUE)) {
}
require_once 'CRM/Contact/BAO/Contact.php';
//check if contact id is valid or not
- if (CRM_Utils_Array::value('contact_id', $params)) {
+ if (!empty($params['contact_id'])) {
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $params['contact_id'];
if (!$contact->find(TRUE)) {
}
//check that event id is not an template
- if (CRM_Utils_Array::value('event_id', $params)) {
+ if (!empty($params['event_id'])) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered'));
// contact_type has a limited number of valid values
+ if(empty($params['contact_type'])) {
+ return civicrm_api3_create_error("No Contact Type");
+ }
$fields = CRM_Utils_Array::value($params['contact_type'], $required);
if ($fields == NULL) {
return civicrm_api3_create_error("Invalid Contact Type: {$params['contact_type']}");
}
}
- if (!CRM_Utils_Array::value('contact_id', $params) && CRM_Utils_Array::value('id', $params)) {
+ if (empty($params['contact_id']) && !empty($params['id'])) {
$valid = FALSE;
$error = '';
foreach ($fields as $field) {
if (is_array($field)) {
$valid = TRUE;
foreach ($field as $element) {
- if (!CRM_Utils_Array::value($element, $params)) {
+ if (empty($params[$element])) {
$valid = FALSE;
$error .= $element;
break;
}
}
else {
- if (CRM_Utils_Array::value($field, $params)) {
+ if (!empty($params[$field])) {
$valid = TRUE;
}
}
}
//check for organisations with same name
- if (CRM_Utils_Array::value('current_employer', $params)) {
+ if (!empty($params['current_employer'])) {
$organizationParams = array();
$organizationParams['organization_name'] = $params['current_employer'];
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Supervised');
// check for mismatch employer name and id
- if (CRM_Utils_Array::value('employer_id', $params)
- && !in_array($params['employer_id'], $dupeIds)
+ if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)
) {
return civicrm_api3_create_error('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
- if (!CRM_Utils_Array::value('employer_id', $params)
- && (count($dupeIds) > 1)
+ if (empty($params['employer_id']) && (count($dupeIds) > 1)
) {
return civicrm_api3_create_error('Found more than one Organisation with same Name.');
}
/**
*
- * @param <type> $result
- * @param <type> $activityTypeID
+ * @param $result
+ * @param $activityTypeID
+ *
+ * @internal param $ <type> $result
+ * @internal param $ <type> $activityTypeID
*
- * @return <type> $params
+ * @return array <type> $params
*/
function _civicrm_api3_deprecated_activity_buildmailparams($result, $activityTypeID) {
// get ready for collecting data about activity to be created