chg: [brood:queryIndex] Added support of pagination and filtering
parent
b9292473de
commit
3fcb58c081
|
@ -101,8 +101,14 @@ class BroodsController extends AppController
|
||||||
if (!in_array($scope, $validScopes)) {
|
if (!in_array($scope, $validScopes)) {
|
||||||
throw new MethodNotAllowedException(__('Invalid scope. Valid options are: {0}', implode(', ', $validScopes)));
|
throw new MethodNotAllowedException(__('Invalid scope. Valid options are: {0}', implode(', ', $validScopes)));
|
||||||
}
|
}
|
||||||
$filter = $this->request->getQuery('quickFilter');
|
$filtering = [
|
||||||
$data = $this->Broods->queryIndex($id, $scope, $filter, true);
|
'page' => $this->request->getQuery('page', 1),
|
||||||
|
'limit' => $this->request->getQuery('limit', 20),
|
||||||
|
];
|
||||||
|
if (!empty($this->request->getQuery('quickFilter'))) {
|
||||||
|
$filtering['quickFilter'] = $this->request->getQuery('quickFilter');
|
||||||
|
}
|
||||||
|
$data = $this->Broods->queryIndex($id, $scope, $filtering, true);
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
$data = [];
|
$data = [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,11 +151,10 @@ class BroodsTable extends AppTable
|
||||||
if (empty($brood)) {
|
if (empty($brood)) {
|
||||||
throw new NotFoundException(__('Brood not found'));
|
throw new NotFoundException(__('Brood not found'));
|
||||||
}
|
}
|
||||||
$filterQuery = empty($filter) ? '' : '?quickFilter=' . urlencode($filter);
|
|
||||||
if (!empty($full)) {
|
if (!empty($full)) {
|
||||||
$filterQuery .= (empty($filterQuery) ? '?' : '&') . 'full=1';
|
$filter['full'] = 1;
|
||||||
}
|
}
|
||||||
$response = $this->HTTPClientGET(sprintf('/%s/index.json%s', $scope, $filterQuery), $brood);
|
$response = $this->HTTPClientGET(sprintf('/%s/index.json?%s', $scope, http_build_query($filter)), $brood);
|
||||||
if ($response->isOk()) {
|
if ($response->isOk()) {
|
||||||
return $response->getJson();
|
return $response->getJson();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue