[BUGFIX] PageBrowsing ViewHelper defines unused method argument
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Classes / ViewHelpers / PageBrowsingViewHelper.php
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\ViewHelpers;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Benjamin Mack (benni@typo3.org)
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 2 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 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Page browser for indexed search, and only useful here, as the
32 * regular pagebrowser
33 * so this is a cleaner "pi_browsebox" but not a real page browser
34 * functionality
35 *
36 * @author Benjamin Mack <benni@typo3.org>
37 */
38 class PageBrowsingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
39
40 /**
41 * main render function
42 *
43 * @param integer $maximumNumberOfResultPages
44 * @param integer $numberOfResults
45 * @param integer $resultsPerPage
46 * @param integer $currentPage
47 * @return the content
48 */
49 public function render($maximumNumberOfResultPages, $numberOfResults, $resultsPerPage, $currentPage = 1) {
50 $maximumNumberOfResultPages = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, 100, 10);
51 $pageCount = ceil($numberOfResults / $resultsPerPage);
52 $content = '';
53 // only show the result browser if more than one page is needed
54 if ($pageCount > 1) {
55 $currentPage = intval($currentPage);
56 // prev page
57 // show on all pages after the 1st one
58 if ($currentPage > 0) {
59 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.previous', 'indexed_search');
60 $content .= '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage - 1), $freeIndexUid) . '</li>';
61 }
62 for ($a = 0; $a < $pageCount; $a++) {
63 $min = max(0, $currentPage + 1 - ceil($maximumNumberOfResultPages / 2));
64 $max = $min + $maximumNumberOfResultPages;
65 if ($max > $pageCount) {
66 $min = $min - ($max - $pageCount);
67 }
68 if ($a >= $min && $a < $max) {
69 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.page', 'indexed_search');
70 $label = trim($label . ' ' . ($a + 1));
71 $label = $this->makecurrentPageSelector_link($label, $a, $freeIndexUid);
72 if ($a == $currentPage) {
73 $content .= '<li class="tx-indexedsearch-browselist-currentPage"><strong>' . $label . '</strong></li>';
74 } else {
75 $content .= '<li>' . $label . '</li>';
76 }
77 }
78 }
79 // next link
80 if ($currentPage + 1 < $pageCount) {
81 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.next', 'indexed_search');
82 $content = '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage + 1), $freeIndexUid) . '</li>';
83 }
84 $content = '<ul class="tx-indexedsearch-browsebox">' . $content . '</ul>';
85 }
86 return $content;
87 }
88
89 /**
90 * Used to make the link for the result-browser.
91 * Notice how the links must resubmit the form after setting the new currentPage-value in a hidden formfield.
92 *
93 * @param string $str String to wrap in <a> tag
94 * @param integer $p currentPage value
95 * @param string $freeIndexUid List of integers pointing to free indexing configurations to search. -1 represents no filtering, 0 represents TYPO3 pages only, any number above zero is a uid of an indexing configuration!
96 * @return string Input string wrapped in <a> tag with onclick event attribute set.
97 * @todo Define visibility
98 */
99 public function makecurrentPageSelector_link($str, $p, $freeIndexUid) {
100 $onclick = 'document.getElementById(\'' . $this->prefixId . '_currentPage\').value=\'' . $p . '\';' . 'document.getElementById(\'' . $this->prefixId . '_freeIndexUid\').value=\'' . rawurlencode($freeIndexUid) . '\';' . 'document.getElementById(\'' . $this->prefixId . '\').submit();return false;';
101 return '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . $str . '</a>';
102 }
103
104 }