From 817cf27cde4e98d832312378d1af2eca167f1c76 Mon Sep 17 00:00:00 2001 From: atif-shaikh Date: Tue, 24 Jun 2014 20:06:31 +0530 Subject: [PATCH] CRM-14782 fix --- CRM/Contact/Import/Form/MapField.php | 13 +++++++++++-- CRM/Contact/Import/Parser/Contact.php | 17 +++++++++++------ CRM/Core/BAO/CustomField.php | 2 ++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 195d36649f..f7f0a2adad 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -57,6 +57,8 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { protected $_dedupeFields; + protected static $customFields; + /** * Attempt to match header labels with our mapper fields * FIXME: This is essentially the same function as parent::defaultFromHeader @@ -152,8 +154,15 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { } } + $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields); + self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType); + foreach(self::$customFields as $key => $attr) { + if (!empty($attr['is_required'])) { + $highlightedFields[] = "custom_$key"; + } + } $this->assign('highlightedFields', $highlightedFields); - $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $this->formatCustomFieldName($this->_mapperFields)); + $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames); $columnNames = array(); //get original col headers from csv if present. @@ -977,7 +986,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { */ function formatCustomFieldName(&$fields) { //CRM-2676, replacing the conflict for same custom field name from different custom group. - $fieldIds = $formattedFieldNames = array(); + $fieldIds = $formattedFieldNames = self::$customFields = array(); foreach ($fields as $key => $value) { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $fieldIds[] = $customFieldId; diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index e9fff31521..184bc25861 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1146,6 +1146,11 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { if (!array_key_exists($customFieldID, $customFields)) { self::addToErrorMsg(ts('field ID'), $errorMessage); } + + if ($customFields[$customFieldID]['is_required'] && (empty($params['custom_'.$customFieldID]) && $params['custom_'.$customFieldID] !== 0) && $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 //values so need to modify if (array_key_exists($customFieldID, $addressCustomFields)) { @@ -1870,7 +1875,11 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { self::formatCustomDate($params, $formatted, $dateType, $key); } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') { - $params[$key] = CRM_Utils_String::strtoboolstr($val); + if (empty($val) && !empty($params['id']) && !is_numeric($val) && $this->_onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { + unset($params[$key]); + } + else { + $params[$key] = CRM_Utils_String::strtoboolstr($val); } } @@ -1888,14 +1897,10 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { $params[$key] = $this->checkGender($val); } } + } //now format custom data. foreach ($params as $key => $field) { - if (!isset($field) || empty($field)){ - unset($params[$key]); - continue; - } - if (is_array($field)) { $isAddressCustomField = FALSE; foreach ($field as $value) { diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index c56c9a9433..0801e2a2bc 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -495,6 +495,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $cfTable.default_value, $cfTable.options_per_line, $cfTable.text_length, $cfTable.custom_group_id, + $cfTable.is_required, $cgTable.extends, $cfTable.is_search_range, $cgTable.extends_entity_column_value, $cgTable.extends_entity_column_id, @@ -569,6 +570,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $fields[$dao->id]['option_group_id'] = $dao->option_group_id; $fields[$dao->id]['date_format'] = $dao->date_format; $fields[$dao->id]['time_format'] = $dao->time_format; + $fields[$dao->id]['is_required'] = $dao->is_required; } CRM_Core_BAO_Cache::setItem($fields, -- 2.25.1