8b8665c66a6378cc214cb147613dcc9c80608680
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Classes / ViewHelpers / PageBrowsingResultsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20
21 /**
22 * renders the header of the results page
23 * @internal
24 */
25 class PageBrowsingResultsViewHelper extends AbstractViewHelper implements CompilableInterface {
26
27 /**
28 * main render function
29 *
30 * @param int $numberOfResults
31 * @param int $resultsPerPage
32 * @param int $currentPage
33 * @return string the content
34 */
35 public function render($numberOfResults, $resultsPerPage, $currentPage = 1) {
36 return static::renderStatic(
37 array(
38 'numberOfResults' => $numberOfResults,
39 'resultsPerPage' => $resultsPerPage,
40 'currentPage' => $currentPage,
41 ),
42 $this->buildRenderChildrenClosure(),
43 $this->renderingContext
44 );
45 }
46
47 /**
48 * @param array $arguments
49 * @param callable $renderChildrenClosure
50 * @param RenderingContextInterface $renderingContext
51 *
52 * @return string
53 */
54 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
55 $numberOfResults = $arguments['numberOfResults'];
56 $resultsPerPage = $arguments['resultsPerPage'];
57 $currentPage = $arguments['currentPage'];
58
59 $firstResultOnPage = $currentPage * $resultsPerPage + 1;
60 $lastResultOnPage = $currentPage * $resultsPerPage + $resultsPerPage;
61 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults', 'indexed_search');
62 return sprintf($label, $firstResultOnPage, min(array($numberOfResults, $lastResultOnPage)), $numberOfResults);
63 }
64
65 }