CRM-19874: Allow overriding sort in the getlist API without clobbering pager
authorFrancis Whittle <francis@agileware.com.au>
Fri, 13 Jan 2017 06:41:38 +0000 (17:41 +1100)
committerAgileware Support <support@agileware.com.au>
Fri, 13 Jan 2017 06:43:44 +0000 (17:43 +1100)
----------------------------------------
* CRM-19874: Allow overriding sort in the getlist API without clobbering pager
  https://issues.civicrm.org/jira/browse/CRM-19874

api/v3/Generic/Getlist.php

index a85da4d182c8c75e624ac7c79ba2a0a33d45b80b..e151d1787b11b5078caa992ad863112fd6d8f538 100644 (file)
@@ -114,14 +114,8 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults
   $request += $apiDefaults + $defaults;
   // Default api params
   $params = array(
-    'options' => array(
-      // Adding one extra result allows us to see if there are any more
-      'limit' => $resultsPerPage + 1,
-      // Because sql is zero-based
-      'offset' => ($request['page_num'] - 1) * $resultsPerPage,
-      'sort' => $request['label_field'],
-    ),
     'sequential' => 1,
+    'options' => array(),
   );
   // When searching e.g. autocomplete
   if ($request['input']) {
@@ -138,6 +132,15 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults
     $params[$request['id_field']] = is_array($request['id']) ? array('IN' => $request['id']) : $request['id'];
   }
   $request['params'] += $params;
+
+  $request['params']['options'] += array(
+    // Add pagination parameters
+    'sort' => $request['label_field'],
+    // Adding one extra result allows us to see if there are any more
+    'limit' => $resultsPerPage + 1,
+    // Because sql is zero-based
+    'offset' => ($request['page_num'] - 1) * $resultsPerPage,
+  );
 }
 
 /**