/**
* Class constructor
*/
- function __construct(&$mapperKeys, $mapperLocType = NULL, $mapperPhoneType = NULL, $mapperImProvider = NULL, $mapperRelated = NULL, $mapperRelatedContactType = NULL, $mapperRelatedContactDetails = NULL, $mapperRelatedContactLocType = NULL, $mapperRelatedContactPhoneType = NULL, $mapperRelatedContactImProvider = NULL,
+ function __construct(
+ &$mapperKeys, $mapperLocType = NULL, $mapperPhoneType = NULL, $mapperImProvider = NULL, $mapperRelated = NULL, $mapperRelatedContactType = NULL, $mapperRelatedContactDetails = NULL, $mapperRelatedContactLocType = NULL, $mapperRelatedContactPhoneType = NULL, $mapperRelatedContactImProvider = NULL,
$mapperWebsiteType = NULL, $mapperRelatedContactWebsiteType = NULL
) {
parent::__construct();
if (!empty($relationshipType)) {
$fields = array_merge($fields, array(
'related' => array(
- 'title' => ts('- related contact info -'),
+ 'title' => ts('- related contact info -'),
),
), $relationshipType);
}
$this->_updateWithId = FALSE;
if (in_array('id', $this->_mapperKeys) || ($this->_externalIdentifierIndex >= 0 && in_array($this->_onDuplicate, array(
- CRM_Import_Parser::DUPLICATE_UPDATE,
- CRM_Import_Parser::DUPLICATE_FILL,
- )))) {
+ CRM_Import_Parser::DUPLICATE_UPDATE,
+ CRM_Import_Parser::DUPLICATE_FILL,
+ )))
+ ) {
$this->_updateWithId = TRUE;
}
//check if external identifier exists in database
if (!empty($params['external_identifier']) && (!empty($params['id']) || in_array($onDuplicate, array(
- CRM_Import_Parser::DUPLICATE_SKIP,
- CRM_Import_Parser::DUPLICATE_NOCHECK,
- )))) {
+ CRM_Import_Parser::DUPLICATE_SKIP,
+ CRM_Import_Parser::DUPLICATE_NOCHECK,
+ )))
+ ) {
if ($internalCid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
if ($internalCid != CRM_Utils_Array::value('id', $params)) {
$this->_retCode = CRM_Import_Parser::NO_MATCH;
}
else {
- $newContact = $this->createContact($formatted, $contactFields, $onDuplicate, $contactId, FALSE, $this->_dedupeRuleGroupID);
- $updateflag = FALSE;
+ $newContact = $this->createContact($formatted, $contactFields, $onDuplicate, $contactId, FALSE, $this->_dedupeRuleGroupID);
+ $updateflag = FALSE;
$this->_retCode = CRM_Import_Parser::VALID;
}
}
$relationship = TRUE;
# see CRM-10433 - might return comma separate list of all dupes
- $dupeContactIDs = explode(',',$newContact['error_message']['params'][0]);
+ $dupeContactIDs = explode(',', $newContact['error_message']['params'][0]);
$dupeCount = count($dupeContactIDs);
$contactID = array_pop($dupeContactIDs);
// check to see if we had more than one duplicate contact id.
}
// check for valid related contact id in update/fill mode, CRM-4424
if (in_array($onDuplicate, array(
- CRM_Import_Parser::DUPLICATE_UPDATE,
- CRM_Import_Parser::DUPLICATE_FILL,
- )) && !empty($params[$key]['id'])) {
+ CRM_Import_Parser::DUPLICATE_UPDATE,
+ CRM_Import_Parser::DUPLICATE_FILL,
+ )) && !empty($params[$key]['id'])
+ ) {
$relatedContactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params[$key]['id'], 'contact_type');
if (!$relatedContactType) {
$errorMessage = ts("No contact found for this related contact ID: %1", array(1 => $params[$key]['id']));
}
if (!empty($relatedCsType) && (!CRM_Contact_BAO_ContactType::isAllowEdit($params[$key]['id'], $relatedCsType) &&
- $relatedCsType != CRM_Utils_Array::value('contact_sub_type', $formatting))) {
+ $relatedCsType != CRM_Utils_Array::value('contact_sub_type', $formatting))
+ ) {
$errorMessage = ts("Mismatched or Invalid contact subtype found for this related contact.") . ' ' . ts("ID: %1", array(1 => $params[$key]['id']));
array_unshift($values, $errorMessage);
return CRM_Import_Parser::NO_MATCH;
}
// update/fill related contact after getting matching Contact Ids, CRM-4424
if (in_array($onDuplicate, array(
- CRM_Import_Parser::DUPLICATE_UPDATE,
- CRM_Import_Parser::DUPLICATE_FILL,
- ))) {
+ CRM_Import_Parser::DUPLICATE_UPDATE,
+ CRM_Import_Parser::DUPLICATE_FILL,
+ ))) {
//validation of related contact subtype for update mode
//CRM-5125
$relatedCsType = NULL;
if ($valid) {
$allRelationships = CRM_Core_PseudoConstant::relationshipType('name');
$relationshipTypeId = str_replace(array(
- '_a_b',
- '_b_a',
- ), array(
- '',
- '',
- ), $key);
+ '_a_b',
+ '_b_a',
+ ), array(
+ '',
+ '',
+ ), $key);
$relationshipType = str_replace($relationshipTypeId . '_', '', $key);
$orgId = $individualId = NULL;
if ($allRelationships[$relationshipTypeId]["name_{$relationshipType}"] == 'Employee of') {
*
* @return void
*/
- public function fini() {}
+ public function fini() {
+ }
/**
* Check if an error in custom data
self::addToErrorMsg(ts('field ID'), $errorMessage);
}
// validate null values for required custom fields of type boolean
- if (!empty($customFields[$customFieldID]['is_required']) && (empty($params['custom_'.$customFieldID]) && !is_numeric($params['custom_'.$customFieldID])) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
- self::addToErrorMsg($customFields[$customFieldID]['label'].'::'.$customFields[$customFieldID]['groupTitle'], $errorMessage);
+ if (!empty($customFields[$customFieldID]['is_required']) && (empty($params['custom_' . $customFieldID]) && !is_numeric($params['custom_' . $customFieldID])) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
+ self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage);
}
//For address custom fields, we do get actual custom field value as an inner array of
}
elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
- self::addToErrorMsg($customFields[$customFieldID]['label'].'::'.$customFields[$customFieldID]['groupTitle'], $errorMessage);
+ self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage);
}
}
// need not check for label filed import
// check for values for custom fields for checkboxes and multiselect
if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') {
- $value = trim($value);
- $value = str_replace('|', ',', $value);
- $mulValues = explode(',', $value);
+ $value = trim($value);
+ $value = str_replace('|', ',', $value);
+ $mulValues = explode(',', $value);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
foreach ($mulValues as $v1) {
if (strlen($v1) == 0) {
$error = TRUE;
foreach (array(
- $countryNames,
- $countryIsoCodes,
- $limitCodes,
- ) as $values) {
+ $countryNames,
+ $countryIsoCodes,
+ $limitCodes,
+ ) as $values) {
if (in_array(trim($countryValue), $values)) {
$error = FALSE;
break;
foreach ($value as $stateValue) {
if ($stateValue['state_province']) {
if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) ||
- self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
+ self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())
+ ) {
continue;
}
else {
$newContact = NULL;
if (is_null($contactId) && ($onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK)) {
- $dupeCheck = (bool)($onDuplicate);
+ $dupeCheck = (bool) ($onDuplicate);
}
//get the prefix id etc if exists
continue;
}
elseif (in_array($key, array(
- 'email_greeting',
- 'postal_greeting',
- 'addressee',
- ))) {
+ 'email_greeting',
+ 'postal_greeting',
+ 'addressee',
+ ))) {
// CRM-4575, need to null custom
if ($params["{$key}_id"] != 4) {
$params["{$key}_custom"] = 'null';
foreach ($params as $key => $val) {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($key);
if ($customFieldID &&
- !array_key_exists($customFieldID, $addressCustomFields)) {
+ !array_key_exists($customFieldID, $addressCustomFields)
+ ) {
//we should not update Date to null, CRM-4062
if ($val && ($customFields[$customFieldID]['data_type'] == 'Date')) {
self::formatCustomDate($params, $formatted, $dateType, $key);
}
}
- if ($key == 'birth_date' && $val) {
- CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
- }
- elseif ($key == 'deceased_date' && $val) {
- CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
- }
- elseif ($key == 'is_deceased' && $val) {
- $params[$key] = CRM_Utils_String::strtoboolstr($val);
- }
- elseif ($key == 'gender') {
- //CRM-4360
- $params[$key] = $this->checkGender($val);
+ if ($key == 'birth_date' && $val) {
+ CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
+ }
+ elseif ($key == 'deceased_date' && $val) {
+ CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
+ }
+ elseif ($key == 'is_deceased' && $val) {
+ $params[$key] = CRM_Utils_String::strtoboolstr($val);
+ }
+ elseif ($key == 'gender') {
+ //CRM-4360
+ $params[$key] = $this->checkGender($val);
+ }
}
}
- }
//now format custom data.
foreach ($params as $key => $field) {
//Handling Custom Data
// note: Address custom fields will be handled separately inside _civicrm_api3_deprecated_add_formatted_param
if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) &&
- array_key_exists($customFieldID, $customFields) &&
- !array_key_exists($customFieldID, $addressCustomFields)) {
+ array_key_exists($customFieldID, $customFields) &&
+ !array_key_exists($customFieldID, $addressCustomFields)
+ ) {
$extends = CRM_Utils_Array::value('extends', $customFields[$customFieldID]);
- $htmlType = CRM_Utils_Array::value( 'html_type', $customFields[$customFieldID] );
- switch ( $htmlType ) {
- case 'Select':
- case 'Radio':
- case 'Autocomplete-Select':
- if ($customFields[$customFieldID]['data_type'] == 'String') {
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
- foreach ($customOption as $customFldID => $customValue) {
- $val = CRM_Utils_Array::value('value', $customValue);
- $label = CRM_Utils_Array::value('label', $customValue);
- $label = strtolower($label);
- $value = strtolower(trim($formatted[$key]));
- if (($value == $label) || ($value == strtolower($val))) {
- $params[$key] = $formatted[$key] = $val;
+ $htmlType = CRM_Utils_Array::value('html_type', $customFields[$customFieldID]);
+ switch ($htmlType) {
+ case 'Select':
+ case 'Radio':
+ case 'Autocomplete-Select':
+ if ($customFields[$customFieldID]['data_type'] == 'String') {
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ foreach ($customOption as $customFldID => $customValue) {
+ $val = CRM_Utils_Array::value('value', $customValue);
+ $label = CRM_Utils_Array::value('label', $customValue);
+ $label = strtolower($label);
+ $value = strtolower(trim($formatted[$key]));
+ if (($value == $label) || ($value == strtolower($val))) {
+ $params[$key] = $formatted[$key] = $val;
+ }
}
}
- }
- break;
- case 'CheckBox':
- case 'AdvMulti-Select':
- case 'Multi-Select':
-
- if (!empty($formatted[$key]) && !empty($params[$key])) {
- $mulValues = explode( ',', $formatted[$key] );
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption( $customFieldID, true );
- $formatted[$key] = array( );
- $params[$key] = array( );
- foreach ( $mulValues as $v1 ) {
- foreach ( $customOption as $v2 ) {
- if ( ( strtolower( $v2['label'] ) == strtolower( trim( $v1 ) ) ) ||
- ( strtolower( $v2['value'] ) == strtolower( trim( $v1 ) ) ) ) {
- if ( $htmlType == 'CheckBox' ) {
- $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1;
- } else {
- $params[$key][] = $formatted[$key][] = $v2['value'];
+ break;
+ case 'CheckBox':
+ case 'AdvMulti-Select':
+ case 'Multi-Select':
+
+ if (!empty($formatted[$key]) && !empty($params[$key])) {
+ $mulValues = explode(',', $formatted[$key]);
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ $formatted[$key] = array();
+ $params[$key] = array();
+ foreach ($mulValues as $v1) {
+ foreach ($customOption as $v2) {
+ if ((strtolower($v2['label']) == strtolower(trim($v1))) ||
+ (strtolower($v2['value']) == strtolower(trim($v1)))
+ ) {
+ if ($htmlType == 'CheckBox') {
+ $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1;
+ }
+ else {
+ $params[$key][] = $formatted[$key][] = $v2['value'];
+ }
}
}
}
}
- }
- break;
+ break;
}
}
}
if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) && array_key_exists($customFieldID, $customFields) &&
- !array_key_exists($customFieldID, $addressCustomFields)) {
+ !array_key_exists($customFieldID, $addressCustomFields)
+ ) {
// @todo calling api functions directly is not supported
_civicrm_api3_custom_format_params($params, $formatted, $extends);
}
// to check if not update mode and unset the fields with empty value.
if (!$this->_updateWithId && array_key_exists('custom', $formatted)) {
foreach ($formatted['custom'] as $customKey => $customvalue) {
- if (empty($formatted['custom'][$customKey][- 1]['is_required'])) {
+ if (empty($formatted['custom'][$customKey][-1]['is_required'])) {
$formatted['custom'][$customKey][-1]['is_required'] = $customFields[$customKey]['is_required'];
}
- $emptyValue = CRM_Utils_Array::value('value', $customvalue[ - 1]);
+ $emptyValue = CRM_Utils_Array::value('value', $customvalue[-1]);
if (!isset($emptyValue)) {
unset($formatted['custom'][$customKey]);
}