From 722b14e88ac40a4475d83db7614a9678193c1100 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 15 Nov 2016 15:32:29 +0530 Subject: [PATCH] minor optimization --- api/v3/utils.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/api/v3/utils.php b/api/v3/utils.php index 1cd0214a08..3f4e5cc611 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -886,9 +886,11 @@ function _civicrm_api3_get_options_from_params(&$params, $queryObject = FALSE, $ 'is_count' => $is_count, 'return' => !empty($returnProperties) ? $returnProperties : array(), ); + $finalSort = array(); - if (is_array($sort)) { - foreach ($sort as $s) { + $options['sort'] = NULL; + if (!empty($sort)) { + foreach ((array) $sort as $s) { if (CRM_Utils_Rule::mysqlOrderBy($s)) { $finalSort[] = $s; } @@ -896,17 +898,8 @@ function _civicrm_api3_get_options_from_params(&$params, $queryObject = FALSE, $ throw new API_Exception("Unknown field specified for sort. Cannot order by '$s'"); } } + $options['sort'] = implode(', ', $finalSort); } - elseif ($sort) { - if (CRM_Utils_Rule::mysqlOrderBy($sort)) { - $finalSort[] = $sort; - } - else { - throw new API_Exception("Unknown field specified for sort. Cannot order by '$sort'"); - } - } - - $options['sort'] = !empty($finalSort) ? implode(', ', $finalSort) : NULL; if ($options['sort'] && stristr($options['sort'], 'SELECT')) { throw new API_Exception('invalid string in sort options'); -- 2.25.1