From: monishdeb Date: Wed, 21 Oct 2015 11:15:24 +0000 (+0530) Subject: CRM-17129 fix - Checkbox custom fields for participants are not not rendered properly X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6c28d4beb322fb3159f69c8808e3d8219c3f1dee;p=civicrm-core.git CRM-17129 fix - Checkbox custom fields for participants are not not rendered properly https://issues.civicrm.org/jira/browse/CRM-17129 --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 5659fcd932..44fcca890f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1623,17 +1623,7 @@ class CRM_Contact_BAO_Query { if (in_array($id, $legacyElements) && is_array($values)) { // prior to 4.7, formValues for some attributes (e.g. group, tag) are stored in array(id1 => 1, id2 => 1), // as per the recent Search fixes $values need to be in standard array(id1, id2) format - $ids = array_keys($values, 1); - if (count($ids) > 1 || - (count($ids) == 1 && - (key($values) > 1 || - is_string(key($values)) || - (key($values) == 1 && $values[1] == 1) // handle (0 => 4), (1 => 1) - ) - ) - ) { - $values = $ids; - } + CRM_Utils_Array::formatArrayKeys($values); } } diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 419c829a5e..b5e12552ee 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1214,6 +1214,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { case 'AdvMulti-Select': case 'Multi-Select': if (is_array($value)) { + // CRM-12989 fix + CRM_Utils_Array::formatArrayKeys($value); + $checkedData = $value; } else { diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 57c03e1391..d04dd607f0 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -1018,4 +1018,25 @@ class CRM_Utils_Array { return $result; } + /** + * Convert array where key(s) holds the actual value and value(s) as 1 into array of actual values + * Ex: array('foobar' => 1, 4 => 1) formatted into array('foobar', 4) + * + * @param array $array + * @return void + */ + public static function formatArrayKeys(&$array) { + $keys = array_keys($array, 1); + if (count($keys) > 1 || + (count($keys) == 1 && + (key($array) > 1 || + is_string(key($array)) || + (key($array) == 1 && $array[1] == 1) // handle (0 => 4), (1 => 1) + ) + ) + ) { + $array = $keys; + } + } + }