116 lines
4.3 KiB
PHP
116 lines
4.3 KiB
PHP
<?php
|
|
namespace WapplerSystems\Meilisearch\Widget;
|
|
|
|
/*
|
|
* This file is part of the TYPO3 CMS project.
|
|
*
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, either version 2
|
|
* of the License, or any later version.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*
|
|
* The TYPO3 project - inspiring people to share!
|
|
*/
|
|
|
|
use WapplerSystems\Meilisearch\ConnectionManager;
|
|
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSetService;
|
|
use WapplerSystems\Meilisearch\Search;
|
|
use WapplerSystems\Meilisearch\System\Configuration\ConfigurationManager;
|
|
use WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext;
|
|
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
|
use WapplerSystems\Meilisearch\Util;
|
|
use WapplerSystems\Meilisearch\Widget\WidgetRequest;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController as CoreAbstractWidgetController;
|
|
|
|
/**
|
|
* Class AbstractWidgetController
|
|
*
|
|
* @author Frans Saris <frans@beech.it>
|
|
* @author Timo Hund <timo.hund@dkd.de>
|
|
*/
|
|
class AbstractWidgetController extends CoreAbstractWidgetController
|
|
{
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $supportedRequestTypes = [WidgetRequest::class];
|
|
|
|
/**
|
|
* @var ConfigurationManager
|
|
*/
|
|
private $meilisearchConfigurationManager;
|
|
|
|
/**
|
|
* @var \WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext
|
|
*/
|
|
protected $controllerContext;
|
|
|
|
/**
|
|
* @param \WapplerSystems\Meilisearch\System\Configuration\ConfigurationManager
|
|
*/
|
|
public function injectMeilisearchConfigurationManager(ConfigurationManager $configurationManager)
|
|
{
|
|
$this->meilisearchConfigurationManager = $configurationManager;
|
|
}
|
|
|
|
/**
|
|
* Initialize the controller context
|
|
*
|
|
* @return \WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext ControllerContext to be passed to the view
|
|
* @api
|
|
*/
|
|
protected function buildControllerContext()
|
|
{
|
|
/** @var $controllerContext \WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext */
|
|
$controllerContext = $this->objectManager->get(MeilisearchControllerContext::class);
|
|
$controllerContext->setRequest($this->request);
|
|
$controllerContext->setResponse($this->response);
|
|
if ($this->arguments !== null) {
|
|
$controllerContext->setArguments($this->arguments);
|
|
}
|
|
$controllerContext->setUriBuilder($this->uriBuilder);
|
|
$typoScriptConfiguration = $this->meilisearchConfigurationManager->getTypoScriptConfiguration();
|
|
$controllerContext->setTypoScriptConfiguration($typoScriptConfiguration);
|
|
|
|
$this->setActiveSearchResultSet($controllerContext);
|
|
|
|
return $controllerContext;
|
|
}
|
|
|
|
/**
|
|
* @param \WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext $controllerContext
|
|
* @return \WapplerSystems\Meilisearch\Mvc\Controller\MeilisearchControllerContext
|
|
*/
|
|
protected function setActiveSearchResultSet($controllerContext)
|
|
{
|
|
$resultSetService = $this->initializeSearch($controllerContext->getTypoScriptConfiguration());
|
|
$lastResult = $resultSetService->getLastResultSet();
|
|
if (!is_null($lastResult)) {
|
|
$controllerContext->setSearchResultSet($lastResult);
|
|
}
|
|
|
|
return $controllerContext;
|
|
}
|
|
|
|
/**
|
|
* @param TypoScriptConfiguration $typoScriptConfiguration
|
|
* @return SearchResultSetService
|
|
*/
|
|
protected function initializeSearch(TypoScriptConfiguration $typoScriptConfiguration)
|
|
{
|
|
/** @var \WapplerSystems\Meilisearch\ConnectionManager $meilisearchConnection */
|
|
$meilisearchConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($GLOBALS['TSFE']->id, Util::getLanguageUid(), $GLOBALS['TSFE']->MP);
|
|
$search = GeneralUtility::makeInstance(Search::class, /** @scrutinizer ignore-type */ $meilisearchConnection);
|
|
|
|
return GeneralUtility::makeInstance(
|
|
SearchResultSetService::class,
|
|
/** @scrutinizer ignore-type */ $typoScriptConfiguration,
|
|
/** @scrutinizer ignore-type */ $search
|
|
);
|
|
}
|
|
}
|