Passed
Pull Request — master (#123)
by
unknown
04:06
created

SolrPaginator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTotalAmountOfItems() 0 3 1
A getAmountOfItemsOnCurrentPage() 0 3 1
A getPaginatedItems() 0 3 1
A updatePaginatedItems() 0 4 1
A __construct() 0 10 1
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