CRM-14782 fix
authoratif-shaikh <shaikh388@gmail.com>
Tue, 24 Jun 2014 14:36:31 +0000 (20:06 +0530)
committeratif-shaikh <shaikh388@gmail.com>
Thu, 26 Jun 2014 15:08:14 +0000 (20:38 +0530)
CRM/Contact/Import/Form/MapField.php
CRM/Contact/Import/Parser/Contact.php
CRM/Core/BAO/CustomField.php

index 195d36649fe11e28ff5677427efa5e49f5558d3a..f7f0a2adad6014db560fac904eec98c278a8aca1 100644 (file)
@@ -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;
index e9fff3152111e899ca5566ea063852dbbf4606af..184bc25861d90a58fc7066cb338e35f307cd21d4 100644 (file)
@@ -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) {
index c56c9a943398f29f6dc2c4e46736965746e9edf5..0801e2a2bca884a80761983cf669f6ce1afc7bfe 100644 (file)
@@ -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,