dev/core#41: Search Builder: Not empty with date or integer custom fields gives a...
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index 8dc1cce54fce176de1c6fe686fb002fd087b33fd..3154ed24edabadf8e4c4076b9dee404c032e3522 100644 (file)
@@ -83,6 +83,28 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     return self::$_dataType;
   }
 
+  /**
+   * Build the map of custom field's data types and there respective Util type
+   *
+   * @return array
+   *   Data data-type => CRM_Utils_Type
+   */
+  public static function dataToType() {
+    return [
+      'String' => CRM_Utils_Type::T_STRING,
+      'Int' => CRM_Utils_Type::T_INT,
+      'Float' => CRM_Utils_Type::T_FLOAT,
+      'Money' => CRM_Utils_Type::T_FLOAT,
+      'Memo' => CRM_Utils_Type::T_TEXT,
+      'Date' => CRM_Utils_Type::T_DATE,
+      'Boolean' => CRM_Utils_Type::T_BOOLEAN,
+      'StateProvince' => CRM_Utils_Type::T_INT,
+      'Country' => CRM_Utils_Type::T_INT,
+      'Link' => CRM_Utils_Type::T_STRING,
+      'ContactReference' => CRM_Utils_Type::T_INT,
+    ];
+  }
+
   /**
    * Get data to html array.
    *
@@ -691,6 +713,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       $regexp = preg_replace('/[.,;:!?]/', '', CRM_Utils_Array::value(0, $values));
       $importableFields[$key] = array(
         'name' => $key,
+        'type' => CRM_Utils_Array::value(CRM_Utils_Array::value('data_type', $values), self::dataToType()),
         'title' => CRM_Utils_Array::value('label', $values),
         'headerPattern' => '/' . preg_quote($regexp, '/') . '/',
         'import' => 1,