1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
9
|
|
|
* |
10
|
|
|
* @license GNU General Public License version 3 or later. |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Kitodo\Dlf\Pagination; |
16
|
|
|
|
17
|
|
|
use TYPO3\CMS\Core\Pagination\PaginationInterface; |
18
|
|
|
use TYPO3\CMS\Core\Pagination\PaginatorInterface; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
final class PageGridPagination implements PaginationInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var PageGridPaginator |
25
|
|
|
*/ |
26
|
|
|
protected $paginator; |
27
|
|
|
|
28
|
|
|
public function __construct(PaginatorInterface $paginator) |
29
|
|
|
{ |
30
|
|
|
$this->paginator = $paginator; |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getPreviousPageNumber(): ?int |
34
|
|
|
{ |
35
|
|
|
$previousPage = (int) (($this->paginator->getCurrentPageNumber() - 1) * $this->paginator->getPublicItemsPerPage()) - ($this->paginator->getPublicItemsPerPage() - 1); |
36
|
|
|
|
37
|
|
|
if ($previousPage > $this->paginator->getNumberOfPages()) { |
38
|
|
|
return null; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $previousPage >= $this->getFirstPageNumber() |
42
|
|
|
? $previousPage |
43
|
|
|
: null |
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getNextPageNumber(): ?int |
48
|
|
|
{ |
49
|
|
|
$nextPage = (int) ($this->paginator->getCurrentPageNumber() * count($this->paginator->getPaginatedItems()) + 1); |
50
|
|
|
|
51
|
|
|
return $nextPage <= $this->paginator->getNumberOfPages() |
52
|
|
|
? $nextPage |
53
|
|
|
: null |
54
|
|
|
; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getFirstPageNumber(): int |
58
|
|
|
{ |
59
|
|
|
return 1; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getLastPageNumber(): int |
63
|
|
|
{ |
64
|
|
|
return $this->paginator->getNumberOfPages(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getStartRecordNumber(): int |
68
|
|
|
{ |
69
|
|
|
if ($this->paginator->getCurrentPageNumber() > $this->paginator->getNumberOfPages()) { |
70
|
|
|
return 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->paginator->getKeyOfFirstPaginatedItem() + 1; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getEndRecordNumber(): int |
77
|
|
|
{ |
78
|
|
|
if ($this->paginator->getCurrentPageNumber() > $this->paginator->getNumberOfPages()) { |
79
|
|
|
return 0; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->paginator->getKeyOfLastPaginatedItem() + 1; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return int[] |
87
|
|
|
*/ |
88
|
|
|
public function getAllPageNumbers(): array |
89
|
|
|
{ |
90
|
|
|
return range($this->getFirstPageNumber(), $this->getLastPageNumber()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.