From e9ab854831a35be05af055df50a65e23fbc3c10b 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 f4606c75d0..1d9269478f 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -885,9 +885,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; } @@ -895,17 +897,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