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
|
|
|
} |