From e6e67da351cafb488265f3b1071f3e01d5357fb6 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 3 Jun 2015 12:12:18 -0400 Subject: [PATCH] Added configurable pagination to checked out items. --- config/vufind/config.ini | 4 ++ .../Controller/MyResearchController.php | 40 +++++++++++++++---- .../templates/myresearch/checkedout.phtml | 27 +++++++++++++ .../templates/myresearch/checkedout.phtml | 27 +++++++++++++ .../templates/Helpers/pagination.phtml | 21 ++++++++++ .../templates/myresearch/checkedout.phtml | 27 +++++++++++++ 6 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 themes/jquerymobile/templates/Helpers/pagination.phtml diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 36894183207..0cb8f55cdb5 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -217,6 +217,10 @@ title_level_holds_mode = "disabled" ; Whether support for multiple library cards is enabled. Default is false. ;library_cards = true +; The number of checked out items to display per page; 0 for no limit (may cause +; memory problems for users with huge numbers of items). Default = 50. +;checked_out_page_size = 50 + ; This section allows you to determine how the users will authenticate. ; You can use an LDAP directory, the local ILS (or multiple ILSes through ; the MultiILS option), the VuFind database (Database), Shibboleth, SIP2, diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 8ed0096c7dc..0013932c359 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -1052,8 +1052,28 @@ class MyResearchController extends AbstractBase // Get checked out item details: $result = $catalog->getMyTransactions($patron); - $transactions = []; - foreach ($result as $current) { + + // Get page size: + $config = $this->getConfig(); + $limit = isset($config->Catalog->checked_out_page_size) + ? $config->Catalog->checked_out_page_size : 50; + + // Build paginator if needed: + if ($limit > 0 && $limit < count($result)) { + $adapter = new \Zend\Paginator\Adapter\ArrayAdapter($result); + $paginator = new \Zend\Paginator\Paginator($adapter); + $paginator->setItemCountPerPage($limit); + $paginator->setCurrentPageNumber($this->params()->fromQuery('page', 1)); + $pageStart = $paginator->getAbsoluteItemNumber(1) - 1; + $pageEnd = $paginator->getAbsoluteItemNumber($limit) - 1; + } else { + $paginator = false; + $pageStart = 0; + $pageEnd = count($result); + } + + $transactions = $hiddenTransactions = []; + foreach ($result as $i => $current) { // Add renewal details if appropriate: $current = $this->renewals()->addRenewDetails( $catalog, $current, $renewStatus @@ -1065,15 +1085,19 @@ class MyResearchController extends AbstractBase $renewForm = true; } - // Build record driver: - $transactions[] = $this->getDriverForILSRecord($current); + // Build record driver (only for the current visible page): + if ($i >= $pageStart && $i <= $pageEnd) { + $transactions[] = $this->getDriverForILSRecord($current); + } else { + $hiddenTransactions[] = $current; + } } return $this->createViewModel( - [ - 'transactions' => $transactions, 'renewForm' => $renewForm, - 'renewResult' => $renewResult - ] + compact( + 'transactions', 'renewForm', 'renewResult', 'paginator', + 'hiddenTransactions' + ) ); } diff --git a/themes/blueprint/templates/myresearch/checkedout.phtml b/themes/blueprint/templates/myresearch/checkedout.phtml index bda1cf0de3a..c4396ce151a 100644 --- a/themes/blueprint/templates/myresearch/checkedout.phtml +++ b/themes/blueprint/templates/myresearch/checkedout.phtml @@ -25,6 +25,32 @@ <br /> <? endif; ?> + <? if ($paginator): ?> + <?=$this->transEsc("Showing")?> + <? $start = $paginator->getAbsoluteItemNumber(1); + $end = $paginator->getAbsoluteItemNumber($paginator->getItemCountPerPage()); + $total = $paginator->getTotalItemCount(); + ?> + <strong><?=$this->localizedNumber($start)?></strong> - <strong><?=$this->localizedNumber($end > $total ? $total : $end)?></strong> + <?=$this->transEsc('of')?> <strong><?=$this->localizedNumber($total)?></strong> + <? endif; ?> + + <? foreach ($hiddenTransactions as $ilsDetails): ?> + <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?> + <? $renewDetails = $this->renewResult[$ilsDetails['item_id']]; ?> + <? $prefix = isset($ilsDetails['title']) ? $ilsDetails['title'] : $ilsDetails['item_id']; ?> + <? if (isset($renewDetails['success']) && $renewDetails['success']): ?> + <div class="success"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_success')?></div> + <? else: ?> + <div class="error"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_fail')?><? if (isset($renewDetails['sysMessage'])): ?>: <?=$this->escapeHtml($renewDetails['sysMessage'])?><? endif; ?></div> + <? endif; ?> + <? endif; ?> + <? if (isset($ilsDetails['renewable']) && $ilsDetails['renewable'] && isset($ilsDetails['renew_details'])): ?> + <? $safeId = preg_replace('/[^a-zA-Z0-9]/', '', $ilsDetails['renew_details']); ?> + <input type="hidden" name="renewAllIDS[]" value="<?=$this->escapeHtmlAttr($ilsDetails['renew_details'])?>" /> + <? endif; ?> + <? endforeach; ?> + <ul class="recordSet"> <? $i = 0; foreach ($this->transactions as $resource): ?> <? $ilsDetails = $resource->getExtraDetail('ils_details'); ?> @@ -133,6 +159,7 @@ <? endforeach; ?> </ul> <? if ($this->renewForm): ?></form><? endif; ?> + <?=$paginator ? $this->paginationControl($paginator, 'Sliding', 'Helpers/pagination.phtml') : ''?> <? else: ?> <?=$this->transEsc('You do not have any items checked out')?>. <? endif; ?> diff --git a/themes/bootstrap3/templates/myresearch/checkedout.phtml b/themes/bootstrap3/templates/myresearch/checkedout.phtml index 0a9352124d2..338e039fb65 100644 --- a/themes/bootstrap3/templates/myresearch/checkedout.phtml +++ b/themes/bootstrap3/templates/myresearch/checkedout.phtml @@ -22,6 +22,32 @@ </div> <? endif; ?> + <? if ($paginator): ?> + <?=$this->transEsc("Showing")?> + <? $start = $paginator->getAbsoluteItemNumber(1); + $end = $paginator->getAbsoluteItemNumber($paginator->getItemCountPerPage()); + $total = $paginator->getTotalItemCount(); + ?> + <strong><?=$this->localizedNumber($start)?></strong> - <strong><?=$this->localizedNumber($end > $total ? $total : $end)?></strong> + <?=$this->transEsc('of')?> <strong><?=$this->localizedNumber($total)?></strong> + <? endif; ?> + + <? foreach ($hiddenTransactions as $ilsDetails): ?> + <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?> + <? $renewDetails = $this->renewResult[$ilsDetails['item_id']]; ?> + <? $prefix = isset($ilsDetails['title']) ? $ilsDetails['title'] : $ilsDetails['item_id']; ?> + <? if (isset($renewDetails['success']) && $renewDetails['success']): ?> + <div class="alert alert-success"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_success')?></div> + <? else: ?> + <div class="alert alert-danger"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_fail')?><? if (isset($renewDetails['sysMessage'])): ?>: <?=$this->escapeHtml($renewDetails['sysMessage'])?><? endif; ?></div> + <? endif; ?> + <? endif; ?> + <? if (isset($ilsDetails['renewable']) && $ilsDetails['renewable'] && isset($ilsDetails['renew_details'])): ?> + <? $safeId = preg_replace('/[^a-zA-Z0-9]/', '', $ilsDetails['renew_details']); ?> + <input class="pull-left" type="hidden" name="renewAllIDS[]" value="<?=$this->escapeHtmlAttr($ilsDetails['renew_details'])?>" /> + <? endif; ?> + <? endforeach; ?> + <? $i = 0; foreach ($this->transactions as $resource): ?> <hr/> <? $ilsDetails = $resource->getExtraDetail('ils_details'); ?> @@ -125,6 +151,7 @@ </div> <? endforeach; ?> <? if ($this->renewForm): ?></form><? endif; ?> + <?=$paginator ? $this->paginationControl($paginator, 'Sliding', 'Helpers/pagination.phtml') : ''?> <? else: ?> <?=$this->transEsc('You do not have any items checked out')?>. <? endif; ?> diff --git a/themes/jquerymobile/templates/Helpers/pagination.phtml b/themes/jquerymobile/templates/Helpers/pagination.phtml new file mode 100644 index 00000000000..242fc41abaf --- /dev/null +++ b/themes/jquerymobile/templates/Helpers/pagination.phtml @@ -0,0 +1,21 @@ +<? if ($this->pageCount): ?> +<div data-role="controlgroup" data-type="horizontal" align="center"> + +<!-- Previous page link --> +<? if (isset($this->previous)): ?> + <? $newParams = $this->params; $newParams['page'] = $this->previous; ?> + <a rel="external" data-role="button" data-rel="back" href="<?= $this->currentPath() . '?' . http_build_query($newParams); ?>"> + « <?=$this->transEsc('Prev')?> + </a> +<? endif; ?> + +<!-- Next page link --> +<? if (isset($this->next)): ?> + <? $newParams = $this->params; $newParams['page'] = $this->next; ?> + <a rel="external" data-role="button" href="<?= $this->currentPath() . '?' . http_build_query($newParams); ?>"> + <?=$this->transEsc('Next');?> » + </a> +<? endif; ?> + +</div> +<? endif; ?> \ No newline at end of file diff --git a/themes/jquerymobile/templates/myresearch/checkedout.phtml b/themes/jquerymobile/templates/myresearch/checkedout.phtml index c570eb6cec1..addfc387aee 100644 --- a/themes/jquerymobile/templates/myresearch/checkedout.phtml +++ b/themes/jquerymobile/templates/myresearch/checkedout.phtml @@ -19,6 +19,32 @@ </fieldset> <? endif; ?> + <? if ($paginator): ?> + <?=$this->transEsc("Showing")?> + <? $start = $paginator->getAbsoluteItemNumber(1); + $end = $paginator->getAbsoluteItemNumber($paginator->getItemCountPerPage()); + $total = $paginator->getTotalItemCount(); + ?> + <strong><?=$this->localizedNumber($start)?></strong> - <strong><?=$this->localizedNumber($end > $total ? $total : $end)?></strong> + <?=$this->transEsc('of')?> <strong><?=$this->localizedNumber($total)?></strong> + <? endif; ?> + + <? foreach ($hiddenTransactions as $ilsDetails): ?> + <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?> + <? $renewDetails = $this->renewResult[$ilsDetails['item_id']]; ?> + <? $prefix = isset($ilsDetails['title']) ? $ilsDetails['title'] : $ilsDetails['item_id']; ?> + <? if (isset($renewDetails['success']) && $renewDetails['success']): ?> + <div class="info"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_success')?></div> + <? else: ?> + <div class="error"><?=$this->escapeHtml($prefix . ': ') . $this->transEsc('renew_fail')?><? if (isset($renewDetails['sysMessage'])): ?>: <?=$this->escapeHtml($renewDetails['sysMessage'])?><? endif; ?></div> + <? endif; ?> + <? endif; ?> + <? if (isset($ilsDetails['renewable']) && $ilsDetails['renewable'] && isset($ilsDetails['renew_details'])): ?> + <? $safeId = preg_replace('/[^a-zA-Z0-9]/', '', $ilsDetails['renew_details']); ?> + <input type="hidden" name="renewAllIDS[]" value="<?=$this->escapeHtmlAttr($ilsDetails['renew_details'])?>" /> + <? endif; ?> + <? endforeach; ?> + <ul class="results checkedout-list" data-role="listview"> <? foreach ($this->transactions as $resource): ?> <? $ilsDetails = $resource->getExtraDetail('ils_details'); ?> @@ -114,6 +140,7 @@ </fieldset> </form> <? endif; ?> + <?=$paginator ? $this->paginationControl($paginator, 'Sliding', 'Helpers/pagination.phtml') : ''?> <? else: ?> <p><?=$this->transEsc('You do not have any items checked out')?>.</p> <? endif; ?> -- GitLab