Merge pull request #3927 from eileenmcnaughton/CRM-15168
[civicrm-core.git] / CRM / Core / BAO / Mapping.php
index 606dd28dec4835f1998fcc238554bf128a0f80ad..7ec58dbafec9c05b28c1a598988d2db5183e4dba 100644 (file)
@@ -100,13 +100,13 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
    * contact object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params         (reference) an assoc array of name/value pairs
+   * @param array  $params an array of name/value pairs
    *
    * @return object    CRM_Core_DAO_Mapper object on success, otherwise null
    * @access public
    * @static
    */
-  static function add(&$params) {
+  static function add($params) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->copyValues($params);
     $mapping->save();
@@ -841,7 +841,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
         }
         //Fix for Search Builder
         if ($mappingType == 'Export') {
-          if (!isset($mappingId)) {
+          if (!isset($mappingId) || $i >= count(reset($mappingName))) {
             if (isset($formValues['mapper']) &&
               isset($formValues['mapper'][$x][$i][1]) &&
               array_key_exists($formValues['mapper'][$x][$i][1], $relationshipTypes)
@@ -988,7 +988,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
    * @return array $returnFields  formatted associated array of elements@static
    * @public
    */
-  static function &formattedFields(&$params, $row = FALSE) {
+  static function formattedFields(&$params, $row = FALSE) {
     $fields = array();
 
     if (empty($params) || !isset($params['mapper'])) {
@@ -1042,6 +1042,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
           // CRM-14563: we store checkbox, multi-select and adv-multi select custom field using separator, hence it
           // needs special handling.
           if ($cfID = CRM_Core_BAO_CustomField::getKeyID($v[1])) {
+            $isCustomField = TRUE;
             $customFieldType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'html_type');
             $specialHTMLType = array(
               'CheckBox',
@@ -1062,6 +1063,13 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
             }
           }
 
+          // CRM-14983: verify if values are comma separated convert to array
+          if (!is_array($value) && (strpos($value,',') !== false || strstr($value, '(')) && empty($isCustomField) && $params['operator'][$key][$k] == 'IN') {
+            preg_match('#\((.*?)\)#', $value, $match);
+            $tmpArray = explode(',', $match[1]);
+            $value = array_combine(array_values($tmpArray),array_values($tmpArray));
+          }
+
           if ($row) {
             $fields[] = array(
               $fldName,