Skip to content

Commit

Permalink
Merge pull request #1386 from omeka/custom-perpage
Browse files Browse the repository at this point in the history
Fetch page and per_page from query if none provided
  • Loading branch information
zerocrates authored Mar 12, 2019
2 parents e0abe28 + a3e2954 commit 16b1cb5
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion application/src/Controller/Admin/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function sidebarSelectAction()
{
$this->setBrowseDefaults('id');
$response = $this->api()->search('assets', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('assets', $response->getContent());
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/Admin/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function browseAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('items', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$formDeleteSelected = $this->getForm(ConfirmForm::class);
$formDeleteSelected->setAttribute('action', $this->url()->fromRoute(null, ['action' => 'batch-delete'], true));
Expand Down Expand Up @@ -87,7 +87,7 @@ public function sidebarSelectAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('items', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('items', $response->getContent());
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/Admin/ItemSetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function browseAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('item_sets', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$formDeleteSelected = $this->getForm(ConfirmForm::class);
$formDeleteSelected->setAttribute('action', $this->url()->fromRoute(null, ['action' => 'batch-delete'], true));
Expand Down Expand Up @@ -130,7 +130,7 @@ public function sidebarSelectAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('item_sets', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('itemSets', $response->getContent());
Expand Down
2 changes: 1 addition & 1 deletion application/src/Controller/Admin/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function browseAction()
{
$this->setBrowseDefaults('id');
$response = $this->api()->search('jobs', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('jobs', $response->getContent());
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/Admin/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function browseAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('media', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$formDeleteSelected = $this->getForm(ConfirmForm::class);
$formDeleteSelected->setAttribute('action', $this->url()->fromRoute(null, ['action' => 'batch-delete'], true));
Expand Down Expand Up @@ -137,7 +137,7 @@ public function sidebarSelectAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('media', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('media', $response->getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function browseAction()
{
$this->setBrowseDefaults('label', 'asc');
$response = $this->api()->search('resource_templates', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('resourceTemplates', $response->getContent());
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function browseAction()
{
$this->setBrowseDefaults('email', 'asc');
$response = $this->api()->search('users', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$formDeleteSelected = $this->getForm(ConfirmForm::class);
$formDeleteSelected->setAttribute('action', $this->url()->fromRoute(null, ['action' => 'batch-delete'], true));
Expand Down Expand Up @@ -80,7 +80,7 @@ public function sidebarSelectAction()
{
$this->setBrowseDefaults('created');
$response = $this->api()->search('users', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('users', $response->getContent());
Expand Down
6 changes: 3 additions & 3 deletions application/src/Controller/Admin/VocabularyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function browseAction()
{
$this->setBrowseDefaults('label', 'asc');
$response = $this->api()->search('vocabularies', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('vocabularies', $response->getContent());
Expand Down Expand Up @@ -217,7 +217,7 @@ public function propertiesAction()
$this->getRequest()->getQuery()->set('vocabulary_id', $this->params('id'));
$propResponse = $this->api()->search('properties', $this->params()->fromQuery());
$vocabResponse = $this->api()->read('vocabularies', $this->params('id'));
$this->paginator($propResponse->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($propResponse->getTotalResults());

$view = new ViewModel;
$view->setVariable('properties', $propResponse->getContent());
Expand All @@ -235,7 +235,7 @@ public function classesAction()
$this->getRequest()->getQuery()->set('vocabulary_id', $this->params('id'));
$classResponse = $this->api()->search('resource_classes', $this->params()->fromQuery());
$vocabResponse = $this->api()->read('vocabularies', $this->params('id'));
$this->paginator($classResponse->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($classResponse->getTotalResults());

$view = new ViewModel;
$view->setVariable('resourceClasses', $classResponse->getContent());
Expand Down
2 changes: 1 addition & 1 deletion application/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function indexAction()

$this->setBrowseDefaults('title', 'asc');
$response = $this->api()->search('sites', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('sites', $response->getContent());
Expand Down
2 changes: 1 addition & 1 deletion application/src/Controller/Site/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function browseAction()
}

$response = $this->api()->search('items', $query);
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());
$items = $response->getContent();

$view->setVariable('site', $site);
Expand Down
2 changes: 1 addition & 1 deletion application/src/Controller/Site/ItemSetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function browseAction()
$query = $this->params()->fromQuery();
$query['site_id'] = $site->id();
$response = $this->api()->search('item_sets', $query);
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());
$itemSets = $response->getContent();

$view = new ViewModel;
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/SiteAdmin/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function indexAction()
{
$this->setBrowseDefaults('title', 'asc');
$response = $this->api()->search('sites', $this->params()->fromQuery());
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setVariable('sites', $response->getContent());
Expand Down Expand Up @@ -451,7 +451,7 @@ public function sidebarItemSelectAction()

$response = $this->api()->search('items', $query);
$items = $response->getContent();
$this->paginator($response->getTotalResults(), $this->params()->fromQuery('page'));
$this->paginator($response->getTotalResults());

$view = new ViewModel;
$view->setTerminal(true);
Expand Down
9 changes: 7 additions & 2 deletions application/src/Mvc/Controller/Plugin/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ public function __construct(HelperPluginManager $viewHelpers)
/**
* Set variables to the pagination view helper.
*
* @param int|null $totalCount The total record count
* @param int $totalCount The total record count
* @param int|null $currentPage The current page number
* @param int|null $perPage The number of records per page
* @param string|null $partialName Name of view script
*/
public function __invoke($totalCount, $currentPage, $perPage = null, $partialName = null)
public function __invoke($totalCount, $currentPage = null, $perPage = null, $partialName = null)
{
// Fetch variables from the query if none provided.
$query = $this->getController()->getRequest()->getQuery();
$currentPage = $currentPage ?: $query->get('page', $currentPage);
$perPage = $perPage ?: $query->get('per_page', $perPage);

$pagination = $this->viewHelpers->get('pagination');
$pagination($partialName, $totalCount, $currentPage, $perPage);
}
Expand Down

0 comments on commit 16b1cb5

Please sign in to comment.