mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Cache the last visited page in the list widget (#3432)
Stores the last visited page of list widgets in the session to restore to on next page load. Does not apply when filters / searches are applied. Credit to @tobias-kuendig
This commit is contained in:
parent
13596c8629
commit
55d49cbf2b
@ -263,6 +263,9 @@ class Lists extends WidgetBase
|
||||
|
||||
if ($this->showPagination) {
|
||||
$this->vars['pageCurrent'] = $this->records->currentPage();
|
||||
// Store the currently visited page number in the session so the same
|
||||
// data can be displayed when the user returns to this list.
|
||||
$this->putSession('lastVisitedPage', $this->vars['pageCurrent']);
|
||||
if ($this->showPageNumbers) {
|
||||
$this->vars['recordTotal'] = $this->records->total();
|
||||
$this->vars['pageLast'] = $this->records->lastPage();
|
||||
@ -540,8 +543,13 @@ class Lists extends WidgetBase
|
||||
$records = $model->getNested();
|
||||
}
|
||||
elseif ($this->showPagination) {
|
||||
$method = $this->showPageNumbers ? 'paginate' : 'simplePaginate';
|
||||
$records = $model->{$method}($this->recordsPerPage, $this->currentPageNumber);
|
||||
$method = $this->showPageNumbers ? 'paginate' : 'simplePaginate';
|
||||
$currentPageNumber = $this->currentPageNumber;
|
||||
if (!$currentPageNumber && empty($this->searchTerm)) {
|
||||
// Restore the last visited page from the session if available.
|
||||
$currentPageNumber = $this->getSession('lastVisitedPage');
|
||||
}
|
||||
$records = $model->{$method}($this->recordsPerPage, $currentPageNumber);
|
||||
}
|
||||
else {
|
||||
$records = $model->get();
|
||||
|
Loading…
x
Reference in New Issue
Block a user