Passed
Pull Request — master (#123)
by
unknown
05:01
created

PageGridPaginator::updatePaginatedItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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\AbstractPaginator;
18
19
final class PageGridPaginator extends AbstractPaginator
20
{
21
    /**
22
     * @var array
23
     */
24
    private array $items;
25
26
    /**
27
     * @var int
28
     */
29
    public int $publicItemsPerPage;
30
31
    /**
32
     * @var array
33
     */
34
    private array $paginatedItems = [];
35
36
    public function __construct(
37
        array $items,
38
        int $currentPageNumber = 1,
39
        int $itemsPerPage = 10
40
    ) {
41
        $this->items = $items;
42
        $this->publicItemsPerPage = $itemsPerPage;
43
        $this->setCurrentPageNumber((int) ceil(($currentPageNumber / $this->publicItemsPerPage)));
44
        $this->setItemsPerPage($itemsPerPage);
45
46
        $this->updateInternalState();
47
    }
48
49
    /**
50
     * @return iterable|array
51
     */
52
    public function getPaginatedItems(): iterable
53
    {
54
        return $this->paginatedItems;
55
    }
56
57
    protected function updatePaginatedItems(int $itemsPerPage, int $offset): void
58
    {
59
        $this->paginatedItems = array_slice($this->items, $offset, $itemsPerPage);
60
    }
61
62
    protected function getTotalAmountOfItems(): int
63
    {
64
        return count($this->items);
65
    }
66
67
    protected function getAmountOfItemsOnCurrentPage(): int
68
    {
69
        return count($this->paginatedItems);
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getPublicItemsPerPage(): int
76
    {
77
        return $this->publicItemsPerPage;
78
    }
79
80
    /**
81
     * @param int $publicItemsPerPage
82
     */
83
    public function setPublicItemsPerPage(int $publicItemsPerPage): void
84
    {
85
        $this->publicItemsPerPage = $publicItemsPerPage;
86
    }
87
88
89
}
90