From dde482e0bdd842306f0210ac669f581876fae958 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 21 Jul 2018 10:40:35 -0400 Subject: [PATCH] Deprecate redundant array util function --- CRM/Admin/Page/AJAX.php | 6 +++--- CRM/Utils/Array.php | 17 ++++++----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 85f1c0fbb7..1fef6d99e8 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -265,8 +265,8 @@ class CRM_Admin_Page_AJAX { $recipientMapping = array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels)); $output = array( - 'sel4' => CRM_Utils_Array::toKeyValueRows($dateFieldLabels), - 'sel5' => CRM_Utils_Array::toKeyValueRows($entityRecipientLabels), + 'sel4' => CRM_Utils_Array::makeNonAssociative($dateFieldLabels), + 'sel5' => CRM_Utils_Array::makeNonAssociative($entityRecipientLabels), 'recipientMapping' => $recipientMapping, ); @@ -291,7 +291,7 @@ class CRM_Admin_Page_AJAX { )); CRM_Utils_JSON::output(array( - 'recipients' => CRM_Utils_Array::toKeyValueRows(CRM_Core_BAO_ActionSchedule::getRecipientListing($mappingID, $recipientType)), + 'recipients' => CRM_Utils_Array::makeNonAssociative(CRM_Core_BAO_ActionSchedule::getRecipientListing($mappingID, $recipientType)), )); } diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 99a7fd7018..b8ea524749 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -866,9 +866,13 @@ class CRM_Utils_Array { * This is necessary to preserve sort order when sending an array through json_encode. * * @param array $associative + * Ex: ['foo' => 'bar']. * @param string $keyName + * Ex: 'key'. * @param string $valueName + * Ex: 'value'. * @return array + * Ex: [0 => ['key' => 'foo', 'value' => 'bar']]. */ public static function makeNonAssociative($associative, $keyName = 'key', $valueName = 'value') { $output = array(); @@ -1037,19 +1041,10 @@ class CRM_Utils_Array { * @param string $valueField * Ex: 'value'. * @return array - * Ex: array( - * 0 => array('key' => 'foo', 'value' => 'bar') - * ). + * @deprecated */ public static function toKeyValueRows($array, $keyField = 'key', $valueField = 'value') { - $result = array(); - foreach ($array as $key => $value) { - $result[] = array( - $keyField => $key, - $valueField => $value, - ); - } - return $result; + return self::makeNonAssociative($array, $keyField, $valueField); } /** -- 2.25.1