Passed
Branch master (5f6eff)
by Rafael
04:03
created

PageBrowserRangeViewHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
wmc 2
eloc 24
dl 0
loc 48
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 6 1
A renderStatic() 0 26 1
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
 */
26
class PageBrowserRangeViewHelper extends AbstractSolrFrontendViewHelper
27
{
28
29
    use CompileWithRenderStatic;
30
31
    /**
32
     * Initializes the arguments
33
     */
34 35
    public function initializeArguments()
35
    {
36 35
        parent::initializeArguments();
37 35
        $this->registerArgument('from', 'string', 'from', false, 'from');
38 35
        $this->registerArgument('to', 'string', 'to', false, 'to');
39 35
        $this->registerArgument('total', 'string', 'total', false, 'total');
40 35
    }
41
42
    /**
43
     * @param array $arguments
44
     * @param \Closure $renderChildrenClosure
45
     * @param RenderingContextInterface $renderingContext
46
     * @return string
47
     */
48 28
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
49
    {
50 28
        $from = $arguments['from'];
51 28
        $to = $arguments['to'];
52 28
        $total = $arguments['total'];
53
54 28
        $resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
55 28
        $search = $resultSet->getUsedSearch();
56 28
        $variableProvider = $renderingContext->getVariableProvider();
57
58 28
        $numberOfResultsOnPage = $resultSet->getSearchResults()->getCount();
59 28
        $numberOfAllResults = $resultSet->getAllResultCount();
60
61 28
        $resultsFrom = $search->getResponseBody()->start + 1;
62 28
        $resultsTo = $resultsFrom + $numberOfResultsOnPage - 1;
63 28
        $variableProvider->add($from, $resultsFrom);
64 28
        $variableProvider->add($to, $resultsTo);
65 28
        $variableProvider->add($total, $numberOfAllResults);
66
67 28
        $content = $renderChildrenClosure();
68
69 28
        $variableProvider->remove($from);
70 28
        $variableProvider->remove($to);
71 28
        $variableProvider->remove($total);
72
73 28
        return $content;
74
    }
75
}
76