Skip to content

Commit

Permalink
Merge pull request #9675 from agileware/CRM-19874
Browse files Browse the repository at this point in the history
CRM-19874: Allow overriding sort in the getlist API without clobbering pager
  • Loading branch information
colemanw authored Jan 13, 2017
2 parents 9b2082e + deb188d commit 7ae669b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions api/v3/Generic/Getlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand All @@ -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,
);
}

/**
Expand Down

0 comments on commit 7ae669b

Please sign in to comment.