1 | <?php |
||
25 | class PaginateController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController { |
||
26 | /** |
||
27 | * Configuration Array |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $configuration = array('itemsPerPage' => 5, 'insertAbove' => FALSE, 'insertBelow' => TRUE, |
||
32 | 'maximumVisiblePages' => 7); |
||
33 | |||
34 | /** |
||
35 | * All objects |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $objects; |
||
40 | |||
41 | /** |
||
42 | * Current Page |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $currentPage = 1; |
||
47 | |||
48 | /** |
||
49 | * Number of pages |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $numberOfPages = 1; |
||
54 | |||
55 | /** |
||
56 | * Items per pages |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $itemsPerPage = 0; |
||
61 | |||
62 | /** |
||
63 | * Initialize Action of the widget controller |
||
64 | * |
||
65 | * @todo Replace deprecated method |
||
66 | * @return void |
||
67 | */ |
||
68 | public function initializeAction() { |
||
69 | $this->objects = $this->widgetConfiguration['objects']; |
||
70 | \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule( |
||
71 | $this->configuration, $this->widgetConfiguration['configuration'], TRUE); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Returns the items per page |
||
76 | * |
||
77 | * @return int the items per page |
||
78 | */ |
||
79 | public function getItemsPerPage() { |
||
82 | |||
83 | /** |
||
84 | * Sets the items per page |
||
85 | * |
||
86 | * @param int $itemsPerPage The items per page |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public function setItemsPerPage($itemsPerPage) { |
||
91 | if (empty($itemsPerPage)) { |
||
92 | $this->itemsPerPage = (integer)$this->configuration['itemsPerPage']; |
||
93 | } else { |
||
94 | $this->itemsPerPage = $itemsPerPage; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Returns the number of pages |
||
100 | * |
||
101 | * @return int |
||
102 | */ |
||
103 | public function getNumberOfPages() { |
||
106 | |||
107 | /** |
||
108 | * Sets the number of pages |
||
109 | * |
||
110 | * @param int $numberOfPages The number of pages |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function setNumberOfPages($numberOfPages) { |
||
117 | |||
118 | /** |
||
119 | * Returns the current page |
||
120 | * |
||
121 | * @return int the current page |
||
122 | */ |
||
123 | public function getCurrentPage() { |
||
126 | |||
127 | /** |
||
128 | * Sets the current page and limits it between 1 and $this->numberOfPages. |
||
129 | * |
||
130 | * @param int $currentPage The current page |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | public function setCurrentPage($currentPage) { |
||
135 | $this->currentPage = $currentPage; |
||
136 | if ($this->currentPage < 1) { |
||
137 | $this->currentPage = 1; |
||
138 | } elseif ($this->currentPage > $this->numberOfPages) { |
||
139 | $this->currentPage = $this->numberOfPages; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Returns all visible objects within a range, |
||
145 | * depending on itemsPerPage and the currentPage. |
||
146 | * |
||
147 | * @param \TYPO3\CMS\Extbase\Persistence\QueryResult|array $objects The list of objects |
||
148 | * |
||
149 | * @return array<mixed> the list of visible objects |
||
150 | */ |
||
151 | public function getVisibleObjects($objects) { |
||
166 | |||
167 | /** |
||
168 | * Index action of the widget controller |
||
169 | * |
||
170 | * @param int $currentPage The current page |
||
171 | * @param int $itemsPerPage The items per page |
||
172 | * |
||
173 | * @return void |
||
174 | */ |
||
175 | public function indexAction($currentPage = 1, $itemsPerPage = 0) { |
||
189 | |||
190 | /** |
||
191 | * Returns an array with the keys "pages", "current", |
||
192 | * "numberOfPages", "nextPage" & "previousPage" |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | protected function buildPagination() { |
||
224 | |||
225 | /** |
||
226 | * Adds the nextPage and the previousPage to the pagination array |
||
227 | * |
||
228 | * @param array $pagination The pagination array which get previous and |
||
229 | * next page |
||
230 | * |
||
231 | * @return array the pagination array which contains some meta data and |
||
232 | * another array which are the pages |
||
233 | */ |
||
234 | protected function addPreviousAndNextPage($pagination) { |
||
244 | } |