Merge pull request #7253 from jitendrapurohit/CRM-17520
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index 5ada16367fc84028e90c80dca7caad906b96f43e..08ac5c9c02f346c1c9807e65eedd82e54e44b40f 100644 (file)
@@ -1165,16 +1165,19 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     switch ($html_type) {
       case 'Radio':
         if ($data_type == 'Boolean') {
-          $option = array('No', 'Yes');
+          $options = array('No', 'Yes');
+        }
+        else {
+          $options = $option;
         }
         if (is_array($value)) {
           $display = NULL;
           foreach ($value as $data) {
-            $display .= $display ? ', ' . $option[$data] : $option[$data];
+            $display .= $display ? ', ' . $options[$data] : $options[$data];
           }
         }
         else {
-          $display = CRM_Utils_Array::value($value, $option);
+          $display = CRM_Utils_Array::value($value, $options);
         }
         break;
 
@@ -1211,6 +1214,11 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       case 'AdvMulti-Select':
       case 'Multi-Select':
         if (is_array($value)) {
+          if ($html_type == 'CheckBox') {
+            // CRM-12989 fix
+            CRM_Utils_Array::formatArrayKeys($value);
+          }
+
           $checkedData = $value;
         }
         else {
@@ -1253,19 +1261,22 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
 
       case 'Select State/Province':
       case 'Multi-Select State/Province':
-        $display = NULL;
-        $option = CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE);
-        foreach ((array) $value as $data) {
-          $display .= $display ? ', ' . $option[$data] : $option[$data];
-        }
-        break;
-
       case 'Select Country':
       case 'Multi-Select Country':
-        $countries = CRM_Core_PseudoConstant::country(FALSE, FALSE);
+        if (strstr($html_type, 'State/Province')) {
+          $option = CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE);
+        }
+        else {
+          $option = CRM_Core_PseudoConstant::country(FALSE, FALSE);
+        }
+        // process multi-select state/country field values
+        if (!is_array($value)) {
+          $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
+        }
+
         $display = NULL;
-        foreach ((array) $value as $countryID) {
-          $display .= $display ? ', ' . $countries[$countryID] : $countries[$countryID];
+        foreach ($value as $data) {
+          $display .= ($display && !empty($option[$data])) ? ', ' . $option[$data] : $option[$data];
         }
         break;
 
@@ -1430,6 +1441,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param int $fileID
    * @param bool $absolute
    *
+   * @param string $multiRecordWhereClause
+   *
    * @return array
    */
   public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL) {
@@ -1615,13 +1628,7 @@ SELECT id
       $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select'
     ) {
       if ($value) {
-        // Note that only during merge this is not an array,
-        // and you can directly use value, CRM-4385
-        if (is_array($value)) {
-          $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-              array_values($value)
-            ) . CRM_Core_DAO::VALUE_SEPARATOR;
-        }
+        $value = CRM_Utils_Array::implodePadded($value);
       }
       else {
         $value = '';