Passed
Pull Request — master (#2985)
by
unknown
34:31
created

PageBrowserRangeViewHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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