Completed
Push — master ( 6ee2a7...5f60a5 )
by Rafael
04:29
created

Pagination::setResultsPerPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\Query\Helper;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2017 dkd Internet Service GmbH <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
28
class Pagination {
29
    /**
30
     * @var int
31
     */
32
    protected $resultsPerPage;
33
34
    /**
35
     * @var int
36
     */
37
    protected $page;
38
39
    /**
40
     * Pagination constructor.
41
     *
42
     * @param int $page
43
     * @param int $resultsPerPage
44
     */
45
    public function __construct(int $page = 0, int $resultsPerPage = 01)
46
    {
47
        $this->page = $page;
48
        $this->resultsPerPage = $resultsPerPage;
49
    }
50
51
    /**
52
     * Gets the currently showing page's number
53
     *
54
     * @return int page number currently showing
55
     */
56
    public function getPage()
57
    {
58
        return $this->page;
59
    }
60
61
    /**
62
     * Sets the page that should be shown
63
     *
64
     * @param int $page page number to show
65
     * @return void
66
     */
67
    public function setPage($page)
68
    {
69
        $this->page = max(intval($page), 0);
70
    }
71
72
    /**
73
     * Gets the index of the first result document we're showing
74
     *
75
     * @return int index of the currently first document showing
76
     */
77
    public function getStartIndex()
78
    {
79
        return ($this->page - 1) * $this->resultsPerPage;
80
    }
81
82
    /**
83
     * Gets the index of the last result document we're showing
84
     *
85
     * @return int index of the currently last document showing
86
     */
87
    public function getEndIndex()
88
    {
89
        return $this->page * $this->resultsPerPage;
90
    }
91
92
    /**
93
     * Returns the number of results that should be shown per page
94
     *
95
     * @return int number of results to show per page
96
     */
97
    public function getResultsPerPage()
98
    {
99
        return $this->resultsPerPage;
100
    }
101
102
    /**
103
     * Sets the number of results that should be shown per page
104
     *
105
     * @param int $resultsPerPage Number of results to show per page
106
     * @return void
107
     */
108
    public function setResultsPerPage($resultsPerPage)
109
    {
110
        $this->resultsPerPage = max(intval($resultsPerPage), 0);
111
    }
112
}