Merge pull request #5485 from eileenmcnaughton/4.6
[civicrm-core.git] / CRM / Core / BAO / Mapping.php
index 32ac611cc36f655d435b8ff6213fd3655e38d5a3..7857c4bfd5c9f7cff9015ed7d5ae517e951120d4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
 class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
   /**
-   * class constructor
+   * Class constructor.
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * contact_id. We'll tweak this function to be more full featured over a period
-   * of time. This is the inverse function of create. It also stores all the retrieved
-   * values in the default array
+   * Fetch object based on array of properties.
    *
-   * @param array $params      (reference ) an assoc array of name/value pairs
-   * @param array $defaults    (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return object     CRM_Core_DAO_Mapping object on success, otherwise null
-   * @access public
-   * @static
+   * @return object
+   *   CRM_Core_DAO_Mapping object on success, otherwise NULL
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->copyValues($params);
     if ($mapping->find(TRUE)) {
@@ -66,16 +63,14 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * Function to delete the mapping
-   *
-   * @param int $id   mapping id
+   * Delete the mapping.
    *
-   * @return boolean
-   * @access public
-   * @static
+   * @param int $id
+   *   Mapping id.
    *
+   * @return bool
    */
-  static function del($id) {
+  public static function del($id) {
     // delete from mapping_field table
     $mappingField = new CRM_Core_DAO_MappingField();
     $mappingField->mapping_id = $id;
@@ -94,19 +89,19 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * takes an associative array and creates a contact object
+   * Takes an associative array and creates a contact object.
    *
    * The function extract all the params it needs to initialize the create a
    * contact object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params an 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
+   * @return object
+   *   CRM_Core_DAO_Mapper object on success, otherwise NULL
    */
-  static function add($params) {
+  public static function add($params) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->copyValues($params);
     $mapping->save();
@@ -115,17 +110,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * function to get the list of mappings
-   *
-   * @params string  $mappingTypeId  mapping type id
+   * Get the list of mappings.
    *
-   * @param $mappingTypeId
+   * @param string $mappingTypeId
+   *   Mapping type id.
    *
-   * @return array $mapping array of mapping name
-   * @access public
-   * @static
+   * @return array
+   *   array of mapping name
    */
-  static function getMappings($mappingTypeId) {
+  public static function getMappings($mappingTypeId) {
     $mapping = array();
     $mappingDAO = new CRM_Core_DAO_Mapping();
     $mappingDAO->mapping_type_id = $mappingTypeId;
@@ -139,17 +132,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * function to get the mapping fields
-   *
-   * @params int $mappingId  mapping id
+   * Get the mapping fields.
    *
-   * @param $mappingId
+   * @param int $mappingId
+   *   Mapping id.
    *
-   * @return array $mappingFields array of mapping fields
-   * @access public
-   * @static
+   * @return array
+   *   array of mapping fields
    */
-  static function getMappingFields($mappingId) {
+  public static function getMappingFields($mappingId) {
     //mapping is to be loaded from database
     $mapping = new CRM_Core_DAO_MappingField();
     $mapping->mapping_id = $mappingId;
@@ -193,46 +184,45 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     }
 
     return array(
-      $mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType,
-      $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue, $mappingWebsiteType,
+      $mappingName,
+      $mappingContactType,
+      $mappingLocation,
+      $mappingPhoneType,
+      $mappingImProvider,
+      $mappingRelation,
+      $mappingOperator,
+      $mappingValue,
+      $mappingWebsiteType,
     );
   }
 
   /**
-   *function to check Duplicate Mapping Name
-   *
-   * @params $nameField  string mapping Name
+   * Check Duplicate Mapping Name.
    *
-   * @params $mapTypeId string mapping Type
+   * @param string $nameField
+   *   mapping Name.
+   * @param string $mapTypeId
+   *   mapping Type.
    *
-   * @param $nameField
-   * @param $mapTypeId
-   *
-   * @return boolean
+   * @return bool
    */
-  static function checkMapping($nameField, $mapTypeId) {
+  public static function checkMapping($nameField, $mapTypeId) {
     $mapping = new CRM_Core_DAO_Mapping();
     $mapping->name = $nameField;
     $mapping->mapping_type_id = $mapTypeId;
-    if ($mapping->find(TRUE)) {
-      return TRUE;
-    }
-    else {
-      return FALSE;
-    }
+    return (bool) $mapping->find(TRUE);
   }
 
   /**
    * Function returns associated array of elements, that will be passed for search
    *
-   * @params int $smartGroupId smart group id
-   *
-   * @param $smartGroupId
+   * @param int $smartGroupId
+   *   Smart group id.
    *
-   * @return array $returnFields  associated array of elements@static
-   * @public
+   * @return array
+   *   associated array of elements
    */
-  static function getFormattedFields($smartGroupId) {
+  public static function getFormattedFields($smartGroupId) {
     $returnFields = array();
 
     //get the fields from mapping table
@@ -255,26 +245,20 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * Function to build the mapping form
-   *
-   * @params object $form        form object
-   * @params string $mappingType mapping type (Export/Import/Search Builder)
-   * @params int    $mappingId   mapping id
-   * @params mixed  $columnCount column count is int for and array for search builder
-   * @params int    $blockCount  block count (no of blocks shown)
+   * Build the mapping form.
    *
-   * @param $form
+   * @param CRM_Core_Form $form
    * @param string $mappingType
-   * @param null $mappingId
-   * @param $columnNo
+   *   (Export/Import/Search Builder).
+   * @param int $mappingId
+   * @param int $columnNo
    * @param int $blockCount
-   * @param null $exportMode
+   *   (no of blocks shown).
+   * @param NULL $exportMode
    *
    * @return void
-   * @access public
-   * @static
    */
-  static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL) {
+  public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL) {
     if ($mappingType == 'Export') {
       $name = "Map";
       $columnCount = array('1' => $columnNo);
@@ -298,8 +282,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       else {
         $form->assign('loadedMapping', $mappingId);
 
-        $params         = array('id' => $mappingId);
-        $temp           = array();
+        $params = array('id' => $mappingId);
+        $temp = array();
         $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
 
         $form->assign('savedName', $mappingDetails->name);
@@ -321,10 +305,10 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       );
     }
 
-    $defaults         = array();
+    $defaults = array();
     $hasLocationTypes = array();
     $hasRelationTypes = array();
-    $fields           = array();
+    $fields = array();
 
     if ($mappingType == 'Export') {
       $required = TRUE;
@@ -377,7 +361,10 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     //we need to unset groups, tags, notes for component export
     if ($exportMode != CRM_Export_Form_Select::CONTACT_EXPORT) {
       foreach (array(
-        'groups', 'tags', 'notes') as $value) {
+                 'groups',
+                 'tags',
+                 'notes',
+               ) as $value) {
         unset($fields['Individual'][$value]);
         unset($fields['Household'][$value]);
         unset($fields['Organization'][$value]);
@@ -391,23 +378,27 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
         if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
           $fields['Contact'][$key] = $value;
           unset($fields['Organization'][$key],
-                $fields['Household'][$key],
-                $fields['Individual'][$key]);
+            $fields['Household'][$key],
+            $fields['Individual'][$key]);
         }
       }
       if (array_key_exists('note', $fields['Contact'])) {
         $noteTitle = $fields['Contact']['note']['title'];
         $fields['Contact']['note']['title'] = $noteTitle . ': ' . ts('Body and Subject');
-        $fields['Contact']['note_body']    = array( 'title' => $noteTitle . ': ' . ts('Body only'),    'name' => 'note_body' );
-        $fields['Contact']['note_subject'] = array( 'title' => $noteTitle . ': ' . ts('Subject only'), 'name' => 'note_subject' );
+        $fields['Contact']['note_body'] = array('title' => $noteTitle . ': ' . ts('Body Only'), 'name' => 'note_body');
+        $fields['Contact']['note_subject'] = array(
+          'title' => $noteTitle . ': ' . ts('Subject Only'),
+          'name' => 'note_subject',
+        );
       }
     }
 
     if (($mappingType == 'Search Builder') || ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT)) {
       if (CRM_Core_Permission::access('CiviContribute')) {
         $fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields();
-        unset($fields['Contribution']['contribution_contact_id']);
-        unset($fields['Contribution']['contribution_status_id']);
+        foreach (array('contribution_contact_id', 'contribution_soft_credit_name', 'contribution_soft_credit_amount', 'contribution_soft_credit_type', 'contribution_soft_credit_contribution_id') as $element) {
+          unset($fields['Contribution'][$element]);
+        }
         $compArray['Contribution'] = ts('Contribution');
       }
     }
@@ -425,7 +416,6 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
           $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields);
         }
 
-        unset($fields['Participant']['participant_contact_id']);
         $compArray['Participant'] = ts('Participant');
       }
     }
@@ -461,6 +451,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       if (CRM_Core_Permission::access('CiviGrant')) {
         $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
         unset($fields['Grant']['grant_contact_id']);
+        if ($mappingType == 'Search Builder') {
+          unset($fields['Grant']['grant_type_id']);
+        }
         $compArray['Grant'] = ts('Grant');
       }
     }
@@ -479,9 +472,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $csRelationships = array();
 
       if ($mappingType == 'Export') {
-        $subTypeRelationshipTypes =
-          CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
-                                                                   FALSE, 'label', TRUE, $subType);
+        $subTypeRelationshipTypes
+          CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
+            FALSE, 'label', TRUE, $subType);
 
         foreach ($subTypeRelationshipTypes as $key => $var) {
           if (!array_key_exists($key, $fields[$val['parent']])) {
@@ -543,20 +536,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
 
-    /* FIXME: dirty hack to make the default option show up first.  This
-         * avoids a mozilla browser bug with defaults on dynamically constructed
-         * selector widgets. */
-
-
+    // FIXME: dirty hack to make the default option show up first.  This
+    // avoids a mozilla browser bug with defaults on dynamically constructed
+    // selector widgets.
     if ($defaultLocationType) {
       $defaultLocation = $locationTypes[$defaultLocationType->id];
       unset($locationTypes[$defaultLocationType->id]);
-      $locationTypes = array(
-        $defaultLocationType->id => $defaultLocation) + $locationTypes;
+      $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes;
     }
 
-    $locationTypes = array(
-      ' ' => ts('Primary')) + $locationTypes;
+    $locationTypes = array(' ' => ts('Primary')) + $locationTypes;
 
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
@@ -565,8 +554,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $contactTypes = array('Contact' => ts('Contacts')) + $contactTypes;
     }
 
-    $sel1 =
-      array('' => ts('- select record type -')) + $contactTypes + $compArray;
+    $sel1 = array('' => ts('- select record type -')) + $contactTypes + $compArray;
 
     foreach ($sel1 as $key => $sel) {
       if ($key) {
@@ -579,9 +567,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
     }
 
-    $sel3['']    = NULL;
-    $sel5['']    = NULL;
-    $phoneTypes  = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
+    $sel3[''] = NULL;
+    $sel5[''] = NULL;
+    $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     asort($phoneTypes);
 
@@ -609,8 +597,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
     }
 
-    //Array for core fields and relationship custom data
-
+    // Array for core fields and relationship custom data
     $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
 
     if ($mappingType == 'Export') {
@@ -622,18 +609,18 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
               // FIX ME: For now let's not expose custom data related to relationship
               $relationshipCustomFields = array();
               //$relationshipCustomFields    = self::getRelationTypeCustomGroupData( $id );
-              //asort( $relationshipCustomFields ) ;
+              //asort($relationshipCustomFields);
 
               $relationshipType = new CRM_Contact_BAO_RelationshipType();
               $relationshipType->id = $id;
               if ($relationshipType->find(TRUE)) {
                 $direction = "contact_sub_type_$second";
                 if (isset($relationshipType->$direction)) {
-                  $relatedFields = array_merge((array)$relatedMapperFields[$relationshipType->$direction], (array)$relationshipCustomFields);
+                  $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->$direction], (array) $relationshipCustomFields);
                 }
                 else {
                   $target_type = 'contact_type_' . $second;
-                  $relatedFields = array_merge((array)$relatedMapperFields[$relationshipType->$target_type], (array)$relationshipCustomFields);
+                  $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->$target_type], (array) $relationshipCustomFields);
                 }
               }
               $relationshipType->free();
@@ -645,7 +632,6 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
 
       //Location Type for relationship fields
-
       foreach ($sel5 as $k => $v) {
         if ($v) {
           foreach ($v as $rel => $fields) {
@@ -676,9 +662,19 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
     //special fields that have location, hack for primary location
     $specialFields = array(
-      'street_address', 'supplemental_address_1', 'supplemental_address_2',
-      'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2',
-      'state_province', 'country', 'phone', 'email', 'im',
+      'street_address',
+      'supplemental_address_1',
+      'supplemental_address_2',
+      'city',
+      'postal_code',
+      'postal_code_suffix',
+      'geo_code_1',
+      'geo_code_2',
+      'state_province',
+      'country',
+      'phone',
+      'email',
+      'im',
     );
 
     if (isset($mappingId)) {
@@ -686,7 +682,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
       list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider,
         $mappingRelation, $mappingOperator, $mappingValue
-      ) = CRM_Core_BAO_Mapping::getMappingFields($mappingId);
+        ) = CRM_Core_BAO_Mapping::getMappingFields($mappingId);
 
       $blkCnt = count($mappingName);
       if ($blkCnt >= $blockCount) {
@@ -883,9 +879,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$name}";
     if (!empty($nullArray)) {
-      $js      .= "var nullArray = [";
+      $js .= "var nullArray = [";
       $elements = array();
-      $seen     = array();
+      $seen = array();
       foreach ($nullArray as $element) {
         $key = "{$element[0]}, {$element[1]}, {$element[2]}";
         if (!isset($seen[$key])) {
@@ -896,7 +892,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $js .= implode(', ', $elements);
       $js .= "]";
       $js .= "
-                for(var i=0;i<nullArray.length;i++) {
+                for (var i=0;i<nullArray.length;i++) {
                     if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {
                         {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';
                     }
@@ -904,9 +900,9 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 ";
     }
     if (!empty($noneArray)) {
-      $js      .= "var noneArray = [";
+      $js .= "var noneArray = [";
       $elements = array();
-      $seen     = array();
+      $seen = array();
       foreach ($noneArray as $element) {
         $key = "{$element[0]}, {$element[1]}, {$element[2]}";
         if (!isset($seen[$key])) {
@@ -917,7 +913,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $js .= implode(', ', $elements);
       $js .= "]";
       $js .= "
-                for(var i=0;i<noneArray.length;i++) {
+                for (var i=0;i<noneArray.length;i++) {
                     if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {
   {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';
                     }
@@ -934,17 +930,17 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     $form->setDefaultAction('refresh');
   }
 
-  /* Function returns all custom fields with group title and
-   * field label
-   * @relationshipTypeId related relationship type id
-   * @return $groupTitle all custom field titles
-   */
   /**
-   * @param $relationshipTypeId
+   * Function returns all custom fields with group title and
+   * field label
+   *
+   * @param int $relationshipTypeId
+   *   Related relationship type id.
    *
    * @return array
+   *   all custom field titles
    */
-  function getRelationTypeCustomGroupData($relationshipTypeId) {
+  public function getRelationTypeCustomGroupData($relationshipTypeId) {
 
     $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', NULL, NULL, $relationshipTypeId, NULL, NULL);
     $groupTitle = array();
@@ -956,14 +952,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
 
   /**
-   * Function returns all  Custom group Names
+   * Function returns all  Custom group Names.
    *
-   * @param related $customfieldId
+   * @param int $customfieldId
+   *   Related file id.
    *
-   * @internal param \related $customfieldId custom field id
-   * @return null|string $customGroupName all custom group names@static
+   * @return null|string
+   *   $customGroupName all custom group names
    */
-  static function getCustomGroupName($customfieldId) {
+  public static function getCustomGroupName($customfieldId) {
     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($customfieldId)) {
       $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
       $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
@@ -979,16 +976,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   /**
    * Function returns associated array of elements, that will be passed for search
    *
-   * @params array   $params associated array of submitted values
-   * @params boolean $row    row no of the fields
-   *
-   * @param $params
+   * @param array $params
+   *   Associated array of submitted values.
    * @param bool $row
+   *   Row no of the fields.
+   *
    *
-   * @return array $returnFields  formatted associated array of elements@static
-   * @public
+   * @return array
+   *   formatted associated array of elements
    */
-  static function formattedFields(&$params, $row = FALSE) {
+  public static function formattedFields(&$params, $row = FALSE) {
     $fields = array();
 
     if (empty($params) || !isset($params['mapper'])) {
@@ -1002,8 +999,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
         if (in_array($v[0], $types)) {
           if ($contactType && $contactType != $v[0]) {
             CRM_Core_Error::fatal(ts("Cannot have two clauses with different types: %1, %2",
-                array(1 => $contactType, 2 => $v[0])
-              ));
+              array(1 => $contactType, 2 => $v[0])
+            ));
           }
           $contactType = $v[0];
         }
@@ -1033,7 +1030,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
           }
 
           if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_'
-            && substr($fldName, 0, 10) != 'financial_') {
+            && substr($fldName, 0, 10) != 'financial_'
+            && substr($fldName, 0, 8) != 'payment_') {
             if (substr($fldName, 0, 13) != 'contribution_') {
               $fldName = 'contribution_' . $fldName;
             }
@@ -1042,13 +1040,14 @@ 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',
               'Multi-Select',
               'AdvMulti-Select',
               'Multi-Select State/Province',
-              'Multi-Select Country'
+              'Multi-Select Country',
             );
 
             // override the operator to handle separator ( note: this might have some performance issues )
@@ -1062,6 +1061,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,
@@ -1103,17 +1109,15 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
         0,
       );
     }
-
-
     return $fields;
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @return array
    */
-  static function &returnProperties(&$params) {
+  public static function &returnProperties(&$params) {
     $fields = array(
       'contact_type' => 1,
       'contact_sub_type' => 1,
@@ -1168,23 +1172,23 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
   }
 
   /**
-   * save the mapping field info for search builder / export given the formvalues
+   * Save the mapping field info for search builder / export given the formvalues
    *
-   * @param array $params       asscociated array of formvalues
-   * @param int   $mappingId    mapping id
+   * @param array $params
+   *   Asscociated array of formvalues.
+   * @param int $mappingId
+   *   Mapping id.
    *
-   * @return null
-   * @static
-   * @access public
+   * @return NULL
    */
-  static function saveMappingFields(&$params, $mappingId) {
+  public static function saveMappingFields(&$params, $mappingId) {
     //delete mapping fields records for exixting mapping
     $mappingFields = new CRM_Core_DAO_MappingField();
     $mappingFields->mapping_id = $mappingId;
     $mappingFields->delete();
 
     if (empty($params['mapper'])) {
-      return;
+      return NULL;
     }
 
     //save record in mapping field table
@@ -1256,5 +1260,5 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       }
     }
   }
-}
 
+}