1
|
|
|
<?php |
2
|
|
|
namespace AOE\Crawler\Backend\View; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2017 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class PaginationView |
32
|
|
|
* |
33
|
|
|
* @package AOE\Crawler\Backend\View |
34
|
|
|
*/ |
35
|
|
|
class PaginationView |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string template path |
40
|
|
|
*/ |
41
|
|
|
protected $template = 'EXT:crawler/template/pagination.php'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var int $perpage number of items perPage |
45
|
|
|
*/ |
46
|
|
|
protected $perPage; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var int $currentOffset current offset |
50
|
|
|
*/ |
51
|
|
|
protected $currentOffset; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int $totalItemCount number of total item |
55
|
|
|
*/ |
56
|
|
|
protected $totalItemCount; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string $baseUrl |
60
|
|
|
*/ |
61
|
|
|
protected $baseUrl; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Method to render the view. |
65
|
|
|
* |
66
|
|
|
* @return string html content |
67
|
|
|
*/ |
68
|
|
|
public function render() |
69
|
|
|
{ |
70
|
|
|
ob_start(); |
71
|
|
|
$this->template = GeneralUtility::getFileAbsFileName($this->template); |
72
|
|
|
include($this->template); |
73
|
|
|
$content = ob_get_contents(); |
74
|
|
|
ob_end_clean(); |
75
|
|
|
|
76
|
|
|
return $content; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the currently configured offset- |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
|
|
public function getCurrentOffset() |
84
|
|
|
{ |
85
|
|
|
return $this->currentOffset; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Method to read the number of items per page |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
|
|
public function getPerPage() |
94
|
|
|
{ |
95
|
|
|
return $this->perPage; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Method to set the current offset from start |
100
|
|
|
* |
101
|
|
|
* @param int $currentOffset |
102
|
|
|
*/ |
103
|
|
|
public function setCurrentOffset($currentOffset) |
104
|
|
|
{ |
105
|
|
|
$this->currentOffset = $currentOffset; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Number of items per page. |
110
|
|
|
* |
111
|
|
|
* @param int $perPage |
112
|
|
|
*/ |
113
|
|
|
public function setPerPage($perPage) |
114
|
|
|
{ |
115
|
|
|
$this->perPage = $perPage; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* returns the total number of items |
120
|
|
|
* @return int |
121
|
|
|
*/ |
122
|
|
|
public function getTotalItemCount() |
123
|
|
|
{ |
124
|
|
|
return $this->totalItemCount; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Method to set the total number of items in the pagination |
129
|
|
|
* |
130
|
|
|
* @param int $totalItemCount |
131
|
|
|
*/ |
132
|
|
|
public function setTotalItemCount($totalItemCount) |
133
|
|
|
{ |
134
|
|
|
$this->totalItemCount = $totalItemCount; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the total number of pages needed to display all content which |
139
|
|
|
* is paginatable |
140
|
|
|
* |
141
|
|
|
* @return float |
142
|
|
|
*/ |
143
|
|
|
public function getTotalPagesCount() |
144
|
|
|
{ |
145
|
|
|
return ceil($this->getTotalItemCount() / $this->getPerPage()); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* This method is used to caluclate the label for a pageoffset, |
150
|
|
|
* in normal cases its the internal offset + 1 |
151
|
|
|
* |
152
|
|
|
* @param int $pageoffset |
153
|
|
|
* @return int |
154
|
|
|
*/ |
155
|
|
|
protected function getLabelForPageOffset($pageoffset) |
156
|
|
|
{ |
157
|
|
|
return $pageoffset + 1; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|