Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to pagination helper #2174

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions application/src/View/Helper/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Pagination extends AbstractHelper
*/
protected $fragment;

protected $options;

/**
* Construct the helper.
*
Expand All @@ -44,14 +46,18 @@ public function __construct(Paginator $paginator)
/**
* Configure the pagination.
*
* Options:
* - page_key: The page # key passed in the URL query (defualt: "page")
*
* @param string|null $partialName Name of view script
* @param int|null $totalCount The total record count
* @param int|null $currentPage The current page number
* @param int|null $perPage The number of records per page
* @param array $options
* @return self
*/
public function __invoke($partialName = null, $totalCount = null, $currentPage = null,
$perPage = null
$perPage = null, array $options = []
) {
if (null !== $totalCount) {
$this->getPaginator()->setTotalCount($totalCount);
Expand All @@ -63,6 +69,7 @@ public function __invoke($partialName = null, $totalCount = null, $currentPage =
$this->getPaginator()->setPerPage($perPage);
}
$this->partialName = $partialName ?: self::PARTIAL_NAME;
$this->options = $options;
return $this;
}

Expand Down Expand Up @@ -99,6 +106,7 @@ public function __toString()
'lastPageUrl' => $this->getUrl($pageCount),
'pagelessUrl' => $this->getPagelessUrl(),
'offset' => $paginator->getOffset(),
'options' => $this->options,
]
);
}
Expand Down Expand Up @@ -127,7 +135,7 @@ public function setFragment($fragment)
protected function getUrl($page)
{
$query = $this->getView()->params()->fromQuery();
$query['page'] = (int) $page;
$query[$this->options['page_key'] ?? 'page'] = (int) $page;
if (isset($query['sort_by_default'])) {
// Do not emit sort_by if the sort_by_default flag is set.
unset($query['sort_by']);
Expand Down
1 change: 1 addition & 0 deletions application/test/OmekaTest/View/Helper/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function testToString()
'lastPageUrl' => null,
'pagelessUrl' => null,
'offset' => null,
'options' => [],
])
)
->will($this->returnValue(''));
Expand Down
2 changes: 1 addition & 1 deletion application/view/common/linked-resources.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use Laminas\Form\Element\Select;

// Set up pagination.
$pagination = $this->pagination(null, $totalCount, $page, $perPage);
$pagination = $this->pagination(null, $totalCount, $page, $perPage, ['page_key' => 'linked_resources_page']);
$fragment = 'resources-linked';
$pagination->setFragment($fragment);

Expand Down
2 changes: 1 addition & 1 deletion application/view/common/pagination.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (isset($query['sort_by_default'])) {
<?php if ($totalCount): ?>
<form method="GET" action="">
<?php echo $this->queryToHiddenInputs($removeQueries); ?>
<input type="text" name="page" class="page-input-top" value="<?php echo $currentPage; ?>" size="4" <?php echo ($pageCount == 1) ? 'readonly' : ''; ?> aria-label="<?php echo $translate('Page'); ?>">
<input type="text" name="<?php echo $this->escapeHtml($options['page_key'] ?? 'page'); ?>" class="page-input-top" value="<?php echo $currentPage; ?>" size="4" <?php echo ($pageCount == 1) ? 'readonly' : ''; ?> aria-label="<?php echo $translate('Page'); ?>">
<span class="page-count"><?php echo sprintf($translate('of %s'), $pageCount); ?></span>
</form>

Expand Down
2 changes: 1 addition & 1 deletion application/view/omeka/admin/item/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $itemMedia = $item->media();
<div id="resources-linked" class="section">
<?php if ($item->subjectValueTotalCount()): ?>
<?php echo $item->displaySubjectValues([
'page' => $this->params()->fromQuery('page', 1),
'page' => $this->params()->fromQuery('linked_resources_page', 1),
'perPage' => 25,
'resourceProperty' => $this->params()->fromQuery('resource_property'),
]); ?>
Expand Down
Loading