From deb188d88c9e64c108a2728851e07be9711c7d71 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 13 Jan 2017 17:41:38 +1100 Subject: [PATCH] CRM-19874: Allow overriding sort in the getlist API without clobbering pager ---------------------------------------- * 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 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index a85da4d182..e151d1787b 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -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, + ); } /** -- 2.25.1