|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\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 TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
18
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class PageBrowserRangeViewHelper |
|
22
|
|
|
* |
|
23
|
|
|
* @author Frans Saris <[email protected]> |
|
24
|
|
|
* @author Timo Hund <[email protected]> |
|
25
|
|
|
* @package ApacheSolrForTypo3\Solr\ViewHelpers |
|
26
|
|
|
*/ |
|
27
|
|
|
class PageBrowserRangeViewHelper extends AbstractSolrFrontendViewHelper |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
use CompileWithRenderStatic; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Initializes the arguments |
|
34
|
|
|
*/ |
|
35
|
|
|
public function initializeArguments() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::initializeArguments(); |
|
38
|
|
|
$this->registerArgument('from', 'string', 'from', false, 'from'); |
|
39
|
|
|
$this->registerArgument('to', 'string', 'to', false, 'to'); |
|
40
|
|
|
$this->registerArgument('total', 'string', 'total', false, 'total'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param array $arguments |
|
45
|
|
|
* @param \Closure $renderChildrenClosure |
|
46
|
|
|
* @param RenderingContextInterface $renderingContext |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
50
|
|
|
{ |
|
51
|
|
|
$from = $arguments['from']; |
|
52
|
|
|
$to = $arguments['to']; |
|
53
|
|
|
$total = $arguments['total']; |
|
54
|
|
|
|
|
55
|
|
|
$search = self::getUsedSearchResultSetFromRenderingContext($renderingContext)->getUsedSearch(); |
|
56
|
|
|
$variableProvider = $renderingContext->getVariableProvider(); |
|
57
|
|
|
|
|
58
|
|
|
$resultsFrom = $search->getResponseBody()->start + 1; |
|
59
|
|
|
$resultsTo = $resultsFrom + count($search->getResultDocumentsRaw()) - 1; |
|
60
|
|
|
$variableProvider->add($from, $resultsFrom); |
|
61
|
|
|
$variableProvider->add($to, $resultsTo); |
|
62
|
|
|
$variableProvider->add($total, $search->getNumberOfResults()); |
|
63
|
|
|
|
|
64
|
|
|
$content = $renderChildrenClosure(); |
|
65
|
|
|
|
|
66
|
|
|
$variableProvider->remove($from); |
|
67
|
|
|
$variableProvider->remove($to); |
|
68
|
|
|
$variableProvider->remove($total); |
|
69
|
|
|
|
|
70
|
|
|
return $content; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|