Merge pull request #9960 from colemanw/CRM-20029
[civicrm-core.git] / api / v3 / utils.php
index 1e5400b4197b7c0c6266c6fa765e0247afd45799..1e78f7b80ee39c53b87c933e21ce0932841c7ca0 100644 (file)
@@ -825,8 +825,11 @@ function _civicrm_api3_get_options_from_params(&$params, $queryObject = FALSE, $
   $finalSort = array();
   $options['sort'] = NULL;
   if (!empty($sort)) {
-    foreach ((array) $sort as $s) {
-      if (CRM_Utils_Rule::mysqlOrderBy($s)) {
+    if (!is_array($sort)) {
+      $sort = array_map('trim', explode(',', $sort));
+    }
+    foreach ($sort as $s) {
+      if ($s == '(1)' || CRM_Utils_Rule::mysqlOrderBy($s)) {
         if ($entity && $action == 'get') {
           switch (trim(strtolower($s))) {
             case 'id':