Passed
Pull Request — master (#1317)
by
unknown
21:24
created

AbstractWidgetController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 69.69%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 78
ccs 23
cts 33
cp 0.6969
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A injectSolrConfigurationManager() 0 4 1
A buildControllerContext() 0 17 2
A setActiveSearchResultSet() 0 10 2
A initializeSearch() 0 8 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Widget;
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 ApacheSolrForTypo3\Solr\ConnectionManager;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService;
19
use ApacheSolrForTypo3\Solr\Search;
20
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
21
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext;
22
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
23
use ApacheSolrForTypo3\Solr\Widget\WidgetRequest;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController as CoreAbstractWidgetController;
26
27
/**
28
 * Class AbstractWidgetController
29
 *
30
 * @author Frans Saris <[email protected]>
31
 * @author Timo Hund <[email protected]>
32
 * @package ApacheSolrForTypo3\Solr\Widget
33
 */
34
class AbstractWidgetController extends CoreAbstractWidgetController
35
{
36
37
    /**
38
     * @var array
39
     */
40
    protected $supportedRequestTypes = [WidgetRequest::class];
41
42
    /**
43
     * @var ConfigurationManager
44
     */
45
    private $solrConfigurationManager;
46
47
    /**
48
     * @var \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext
49
     */
50
    protected $controllerContext;
51
52
    /**
53
     * @param \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager
54
     */
55 24
    public function injectSolrConfigurationManager(ConfigurationManager $configurationManager)
56
    {
57 24
        $this->solrConfigurationManager = $configurationManager;
58 24
    }
59
60
    /**
61
     * Initialize the controller context
62
     *
63
     * @return \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext ControllerContext to be passed to the view
64
     * @api
65
     */
66 24
    protected function buildControllerContext()
67
    {
68
        /** @var $controllerContext \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext */
69 24
        $controllerContext = $this->objectManager->get(SolrControllerContext::class);
70 24
        $controllerContext->setRequest($this->request);
71 24
        $controllerContext->setResponse($this->response);
72 24
        if ($this->arguments !== null) {
73 24
            $controllerContext->setArguments($this->arguments);
74
        }
75 24
        $controllerContext->setUriBuilder($this->uriBuilder);
76 24
        $typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptConfiguration();
77 24
        $controllerContext->setTypoScriptConfiguration($typoScriptConfiguration);
78
79 24
        $this->setActiveSearchResultSet($controllerContext);
80
81 24
        return $controllerContext;
82
    }
83
84
    /**
85
     * @param \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext $controllerContext
86
     * @return \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext
87
     */
88 23
    protected function setActiveSearchResultSet($controllerContext)
89
    {
90 23
        $resultSetService = $this->initializeSearch($controllerContext->getTypoScriptConfiguration());
91 23
        $lastResult = $resultSetService->getLastResultSet();
92 23
        if (!is_null($lastResult)) {
93
            $controllerContext->setSearchResultSet($lastResult);
94
        }
95
96 23
        return $controllerContext;
97
    }
98
99
    /**
100
     * @param TypoScriptConfiguration $typoScriptConfiguration
101
     * @return SearchResultSetService
102
     */
103 23
    protected function initializeSearch(TypoScriptConfiguration $typoScriptConfiguration)
104
    {
105
        /** @var \ApacheSolrForTypo3\Solr\ConnectionManager $solrConnection */
106 23
        $solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($GLOBALS['TSFE']->id, $GLOBALS['TSFE']->sys_language_uid, $GLOBALS['TSFE']->MP);
107 23
        $search = GeneralUtility::makeInstance(Search::class, $solrConnection);
108
109 23
        return GeneralUtility::makeInstance(SearchResultSetService::class, $typoScriptConfiguration, $search);
110
    }
111
}
112