Completed
Push — master ( ee9c7d...9819c1 )
by Rafael
14:45
created

PageBrowserRangeViewHelper::renderStatic()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1.0013

Importance

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