Ensure normalized filtersettings
This commit is contained in:
@@ -61,19 +61,19 @@ class AjaxSearchController extends ActionController
|
||||
|
||||
public function initializeSearchresultAction()
|
||||
{
|
||||
$forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$forcedConceptUids = GeneralUtility::intExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$this->processFilterSettingsArgument($forcedConceptUids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $filterSettings
|
||||
*/
|
||||
public function searchresultAction(array $filterSettings)
|
||||
public function searchresultAction(array $filterSettings): void
|
||||
{
|
||||
$dateSelected = false;
|
||||
$organic = true;
|
||||
$forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$excludedConceptUids = GeneralUtility::trimExplode(',', $this->settings['excludedConceptUids']);
|
||||
$forcedConceptUids = GeneralUtility::intExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$excludedConceptUids = GeneralUtility::intExplode(',', $this->settings['excludedConceptUids'], true);
|
||||
|
||||
if (isset($filterSettings['dateFrom']) || isset($filterSettings['dateTo'])) {
|
||||
$dateSelected = true;
|
||||
|
||||
@@ -94,7 +94,7 @@ class SearchController extends ActionController
|
||||
$filterSettings = $filterSettingsEncoder->decode($encodedFilterSettings);
|
||||
$this->request->setArgument('filterSettings', $filterSettings);
|
||||
}
|
||||
$forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$forcedConceptUids = GeneralUtility::intExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$this->processFilterSettingsArgument($forcedConceptUids);
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ class SearchController extends ActionController
|
||||
{
|
||||
$dateSelected = false;
|
||||
$organic = true;
|
||||
$forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$excludedConceptUids = GeneralUtility::trimExplode(',', $this->settings['excludedConceptUids']);
|
||||
$forcedConceptUids = GeneralUtility::intExplode(',', $this->settings['forcedConceptUids'], true);
|
||||
$excludedConceptUids = GeneralUtility::intExplode(',', $this->settings['excludedConceptUids']);
|
||||
|
||||
if (!empty($filterSettings['dateFrom']) || !empty($filterSettings['dateTo'])) {
|
||||
$dateSelected = true;
|
||||
|
||||
@@ -2,34 +2,9 @@
|
||||
|
||||
namespace EP\EpProducts\Service;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2016 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Domain\Model\Dto\FilterOptions;
|
||||
use EP\EpProducts\Domain\Model\SearchResult;
|
||||
use EP\EpProducts\Domain\Repository\DateRepository;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -40,23 +15,16 @@ class FilterService implements SingletonInterface
|
||||
public const DURATION_SHORT = 4;
|
||||
public const DURATION_LONG = 5;
|
||||
|
||||
/**
|
||||
* @var \EP\EpProducts\Domain\Repository\DateRepository
|
||||
*/
|
||||
protected $dateRepository;
|
||||
|
||||
/**
|
||||
* @var ConfigurationManagerInterface
|
||||
*/
|
||||
protected $configurationManager;
|
||||
|
||||
/**
|
||||
* @param DateRepository $dateRepository
|
||||
* @param ConfigurationManagerInterface $configurationManager
|
||||
*/
|
||||
public function __construct(DateRepository $dateRepository, ConfigurationManagerInterface $configurationManager)
|
||||
public function __construct(ConfigurationManagerInterface $configurationManager)
|
||||
{
|
||||
$this->dateRepository = $dateRepository;
|
||||
$this->configurationManager = $configurationManager;
|
||||
}
|
||||
|
||||
@@ -64,6 +32,7 @@ class FilterService implements SingletonInterface
|
||||
{
|
||||
$optionsResolver = new OptionsResolver();
|
||||
$optionsResolver->setDefaults([
|
||||
'productsPid' => null,
|
||||
'priceRanges' => [],
|
||||
'countryUids' => [],
|
||||
'regionUids' => [],
|
||||
@@ -80,6 +49,22 @@ class FilterService implements SingletonInterface
|
||||
'pax' => 0,
|
||||
'bus' => null,
|
||||
]);
|
||||
foreach (['productsPid', 'hotelUid', 'productUid', 'nights', 'pax'] as $key) {
|
||||
$optionsResolver->setNormalizer($key, function (Options $options, $value) {
|
||||
return null !== $value ? (int)$value : null;
|
||||
});
|
||||
}
|
||||
foreach (['priceRanges', 'countryUids', 'regionUids', 'cityUids', 'conceptUids', 'boardTypes', 'hotelTypes', 'roomTypes'] as $key) {
|
||||
$optionsResolver->setNormalizer($key, function (Options $options, $value) {
|
||||
if (empty($value)) {
|
||||
return [];
|
||||
}
|
||||
return array_map('intval', $value);
|
||||
});
|
||||
}
|
||||
$optionsResolver->setNormalizer('bus', function (Options $options, $value) {
|
||||
return null !== $value ? (bool)$value : null;
|
||||
});
|
||||
|
||||
$filterSettings = $optionsResolver->resolve($filterSettings);
|
||||
|
||||
@@ -88,14 +73,14 @@ class FilterService implements SingletonInterface
|
||||
}
|
||||
|
||||
$typoScriptSettings = $this->getTypoScriptSettings();
|
||||
$filterSettings['productsPid'] = $typoScriptSettings['productsPid'] ?? null;
|
||||
$filterSettings['productsPid'] = $typoScriptSettings['productsPid'] ? (int)$typoScriptSettings['productsPid'] : null;
|
||||
|
||||
return $filterSettings;
|
||||
}
|
||||
|
||||
public function getFilterSettingsFromSearchParams(array $searchParams, array $forcedConceptUids = []): array
|
||||
{
|
||||
$filterSettings = $this->getNormalizedFilterSettings([], $forcedConceptUids);
|
||||
$filterSettings = [];
|
||||
|
||||
if ($searchParams['destinationType'] && $searchParams['destinationUid']) {
|
||||
switch ($searchParams['destinationType']) {
|
||||
@@ -123,18 +108,18 @@ class FilterService implements SingletonInterface
|
||||
$filterSettings['priceRanges'] = [ $searchParams['priceRange'] ];
|
||||
}
|
||||
if ($searchParams['pax']) {
|
||||
$filterSettings['pax'] = (int)$searchParams['pax'];
|
||||
$filterSettings['pax'] = $searchParams['pax'];
|
||||
}
|
||||
if ($searchParams['nights']) {
|
||||
$filterSettings['nights'] = (int)$searchParams['nights'];
|
||||
$filterSettings['nights'] = $searchParams['nights'];
|
||||
}
|
||||
|
||||
return $filterSettings;
|
||||
return $this->getNormalizedFilterSettings($filterSettings, $forcedConceptUids);
|
||||
}
|
||||
|
||||
public function getFilterSettingsFromStaticSearchParams(array $staticSearchParams): array
|
||||
{
|
||||
$filterSettings = $this->getNormalizedFilterSettings();
|
||||
$filterSettings = [];
|
||||
|
||||
if (!empty($staticSearchParams['country'])) {
|
||||
$filterSettings['countryUids'] = [ $staticSearchParams['country'] ];
|
||||
@@ -143,7 +128,7 @@ class FilterService implements SingletonInterface
|
||||
$filterSettings['regionUids'] = [ $staticSearchParams['region'] ];
|
||||
}
|
||||
if (!empty($staticSearchParams['concept'])) {
|
||||
$filterSettings['conceptUids'] = GeneralUtility::trimExplode(',', $staticSearchParams['concept'], true);
|
||||
$filterSettings['conceptUids'] = GeneralUtility::intExplode(',', $staticSearchParams['concept'], true);
|
||||
}
|
||||
if (!empty($staticSearchParams['hotel'])) {
|
||||
$filterSettings['hotelUid'] = $staticSearchParams['hotel'];
|
||||
@@ -152,10 +137,10 @@ class FilterService implements SingletonInterface
|
||||
$filterSettings['productUid'] = $staticSearchParams['product'];
|
||||
}
|
||||
if (!empty($staticSearchParams['hotel_types'])) {
|
||||
$filterSettings['hotelTypes'] = GeneralUtility::trimExplode(',', $staticSearchParams['hotel_types'], true);
|
||||
$filterSettings['hotelTypes'] = GeneralUtility::intExplode(',', $staticSearchParams['hotel_types'], true);
|
||||
}
|
||||
if (!empty($staticSearchParams['bus'])) {
|
||||
$filterSettings['bus'] = (bool)$staticSearchParams['bus'];
|
||||
$filterSettings['bus'] = $staticSearchParams['bus'];
|
||||
}
|
||||
if (!empty($staticSearchParams['date_from']) && $staticSearchParams['date_from'] !== '0000-00-00') {
|
||||
$filterSettings['dateFrom'] = $staticSearchParams['date_from'];
|
||||
@@ -163,11 +148,11 @@ class FilterService implements SingletonInterface
|
||||
if (!empty($staticSearchParams['date_to']) && $staticSearchParams['date_to'] !== '0000-00-00') {
|
||||
$filterSettings['dateTo'] = $staticSearchParams['date_to'];
|
||||
}
|
||||
if (!empty($staticSearchParams['pax']) && (int)$staticSearchParams['pax'] > 0) {
|
||||
$filterSettings['pax'] = (int)$staticSearchParams['pax'];
|
||||
if (!empty($staticSearchParams['pax']) && $staticSearchParams['pax'] > 0) {
|
||||
$filterSettings['pax'] = $staticSearchParams['pax'];
|
||||
}
|
||||
|
||||
return $filterSettings;
|
||||
return $this->getNormalizedFilterSettings($filterSettings);
|
||||
}
|
||||
|
||||
public function collectFilterOptionsFromSearchResult(SearchResult $searchResult): FilterOptions
|
||||
@@ -302,15 +287,16 @@ class FilterService implements SingletonInterface
|
||||
|
||||
public function getFiltersettingsFromSettings(array $settings): array
|
||||
{
|
||||
$filterSettings = $this->getNormalizedFilterSettings();
|
||||
if (isset($settings['regionUid']) && (int) $settings['regionUid'] > 0) {
|
||||
$filterSettings = [];
|
||||
|
||||
if (isset($settings['regionUid']) && (int)$settings['regionUid'] > 0) {
|
||||
$filterSettings['regionUids'] = [ $settings['regionUid'] ];
|
||||
} elseif (isset($settings['countryUid']) && (int) $settings['countryUid'] > 0) {
|
||||
$filterSettings['countryUids'] = [ $settings['countryUid'] ];
|
||||
} elseif (isset($settings['hotelUid']) && (int) $settings['hotelUid'] > 0) {
|
||||
$filterSettings['hotelUid'] = $settings['hotelUid'];
|
||||
}
|
||||
$conceptUids = GeneralUtility::trimExplode(',', $settings['conceptUid'], true);
|
||||
$conceptUids = GeneralUtility::intExplode(',', $settings['conceptUid'], true);
|
||||
if ($conceptUids) {
|
||||
$filterSettings['conceptUids'] = $conceptUids;
|
||||
}
|
||||
@@ -328,11 +314,11 @@ class FilterService implements SingletonInterface
|
||||
$filterSettings['bus'] = true;
|
||||
}
|
||||
if (array_key_exists('hotelTypes', $settings)) {
|
||||
$hotelTypes = GeneralUtility::trimExplode(',', $settings['hotelTypes'], true);
|
||||
$hotelTypes = GeneralUtility::intExplode(',', $settings['hotelTypes'], true);
|
||||
$filterSettings['hotelTypes'] = $hotelTypes;
|
||||
}
|
||||
|
||||
return $filterSettings;
|
||||
return $this->getNormalizedFilterSettings($filterSettings);
|
||||
}
|
||||
|
||||
protected function getTypoScriptSettings(): array
|
||||
|
||||
Reference in New Issue
Block a user