Passed
Pull Request — master (#1308)
by Timo
22:26
created

PageBrowserRangeViewHelper::renderStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1.0013

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 16
cts 18
cp 0.8889
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 3
crap 1.0013
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Frontend;
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 23
    public function initializeArguments()
36
    {
37 23
        parent::initializeArguments();
38 23
        $this->registerArgument('from', 'string', 'from', false, 'from');
39 23
        $this->registerArgument('to', 'string', 'to', false, 'to');
40 23
        $this->registerArgument('total', 'string', 'total', false, 'total');
41 23
    }
42
43
    /**
44
     * @param array $arguments
45
     * @param \Closure $renderChildrenClosure
46
     * @param RenderingContextInterface $renderingContext
47
     * @return string
48
     */
49 19
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
50
    {
51 19
        $from = $arguments['from'];
52 19
        $to = $arguments['to'];
53 19
        $total = $arguments['total'];
54
55 19
        $search = self::getUsedSearchResultSetFromRenderingContext($renderingContext)->getUsedSearch();
56 19
        $variableProvider = $renderingContext->getVariableProvider();
57
58 19
        $resultsFrom = $search->getResponseBody()->start + 1;
59 19
        $resultsTo = $resultsFrom + count($search->getResultDocumentsRaw()) - 1;
60 19
        $variableProvider->add($from, $resultsFrom);
61 19
        $variableProvider->add($to, $resultsTo);
62 19
        $variableProvider->add($total, $search->getNumberOfResults());
63
64 19
        $content = $renderChildrenClosure();
65
66 19
        $variableProvider->remove($from);
67 19
        $variableProvider->remove($to);
68 19
        $variableProvider->remove($total);
69
70 19
        return $content;
71
    }
72
}
73