1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Common; |
14
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Solr\SolrSearch; |
16
|
|
|
use TYPO3\CMS\Core\Pagination\AbstractPaginator; |
17
|
|
|
|
18
|
|
|
class SolrPaginator extends AbstractPaginator |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var SolrSearch |
22
|
|
|
*/ |
23
|
|
|
private SolrSearch $solrSearch; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private array $paginatedItems = []; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
SolrSearch $solrSearch, |
32
|
|
|
int $currentPageNumber = 1, |
33
|
|
|
int $itemsPerPage = 25 |
34
|
|
|
) { |
35
|
|
|
$this->solrSearch = $solrSearch; |
36
|
|
|
$this->setCurrentPageNumber($currentPageNumber); |
37
|
|
|
$this->setItemsPerPage($itemsPerPage); |
38
|
|
|
|
39
|
|
|
$this->updateInternalState(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function updatePaginatedItems(int $itemsPerPage, int $offset): void |
43
|
|
|
{ |
44
|
|
|
$this->solrSearch->submit($offset, $itemsPerPage); |
45
|
|
|
$this->paginatedItems = $this->solrSearch->toArray(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function getTotalAmountOfItems(): int |
49
|
|
|
{ |
50
|
|
|
return $this->solrSearch->count(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function getAmountOfItemsOnCurrentPage(): int |
54
|
|
|
{ |
55
|
|
|
return count($this->paginatedItems); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getPaginatedItems(): iterable |
59
|
|
|
{ |
60
|
|
|
return $this->paginatedItems; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|