1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Pagination; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
18
|
|
|
use TYPO3\CMS\Core\Pagination\AbstractPaginator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ResultsPaginator |
22
|
|
|
* |
23
|
|
|
* @author Rudy Gnodde <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ResultsPaginator extends AbstractPaginator |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var SearchResultSet |
29
|
|
|
*/ |
30
|
|
|
protected $resultSet; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param SearchResultSet $resultSet |
34
|
|
|
* @param int $currentPageNumber |
35
|
|
|
* @param int $itemsPerPage |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
SearchResultSet $resultSet, |
39
|
|
|
int $currentPageNumber = 1, |
40
|
|
|
int $itemsPerPage = 10 |
41
|
|
|
) { |
42
|
|
|
$this->resultSet = $resultSet; |
43
|
|
|
$this->setCurrentPageNumber($currentPageNumber); |
44
|
|
|
$this->setItemsPerPage($itemsPerPage); |
45
|
|
|
|
46
|
|
|
$this->updateInternalState(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return iterable |
51
|
|
|
*/ |
52
|
|
|
public function getPaginatedItems(): iterable |
53
|
|
|
{ |
54
|
|
|
return $this->resultSet->getSearchResults(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $itemsPerPage |
59
|
|
|
* @param int $offset |
60
|
|
|
*/ |
61
|
|
|
public function updatePaginatedItems(int $itemsPerPage, int $offset): void |
62
|
|
|
{ |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function getAmountOfItemsOnCurrentPage(): int |
69
|
|
|
{ |
70
|
|
|
return $this->resultSet->getSearchResults()->count(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function getTotalAmountOfItems(): int |
77
|
|
|
{ |
78
|
|
|
return $this->resultSet->getAllResultCount(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|