From 51e01296f1b6d8e665ca7ed23596e2e0d3d2d263 Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Fri, 1 Mar 2024 10:53:52 +0100 Subject: [PATCH] [BUGFIX] ->isFilterSet() should not return true when filter is build with a timePeriod in constructor Because we stumbled of shortener list view where "clear filter" button was always shown even if there was no filter given. Because before this commit, every timePeriod different to default triggers the isSet() (because isFilterSet() was true), no matter if the value was given via POST param (filter) or from constructor. Now we make a difference between constructor and setter value. For whatever reason extbase property mapper uses constructor injection in FilterDto if the variable has the same name as a property. To prevent this, because we need to use the setter setTimePeriodDefault(), we need a different variable name for the first parameter in the constructor now. --- Classes/Controller/AbstractController.php | 4 +-- Classes/Domain/Model/Transfer/FilterDto.php | 27 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index 49f288cc..cdc04885 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -135,7 +135,7 @@ public function initializeAction() * Always set a default FilterDto even if there are no filter params. In addition, remove categoryScoring with 0 to * avoid propertymapping exceptions * - * @param int $timePeriod + * @param int $timePeriod if anything else then default (0) is given, $filter->isPeriodSet() will be true * @return void * @throws NoSuchArgumentException */ @@ -149,7 +149,7 @@ protected function setFilter(int $timePeriod = FilterDto::PERIOD_DEFAULT): void if ($this->request->hasArgument('filter') === false) { $filter = BackendUtility::getFilterArrayFromSession($this->getActionName(), $this->getControllerName()); if ($filter === []) { - $filter['timePeriod'] = $timePeriod; + $filter['timePeriodDefault'] = $timePeriod; } } else { $filter = (array)$this->request->getArgument('filter'); diff --git a/Classes/Domain/Model/Transfer/FilterDto.php b/Classes/Domain/Model/Transfer/FilterDto.php index a62cf119..d9142c25 100644 --- a/Classes/Domain/Model/Transfer/FilterDto.php +++ b/Classes/Domain/Model/Transfer/FilterDto.php @@ -55,6 +55,12 @@ class FilterDto protected int $limit = 0; protected int $scoring = 0; + + /** + * Needed to compare with timePeriod to check if given from filter or by default + * @var int + */ + protected int $timePeriodDefault = self::PERIOD_DEFAULT; protected int $timePeriod = self::PERIOD_DEFAULT; protected int $identified = self::IDENTIFIED_ALL; @@ -87,9 +93,12 @@ class FilterDto protected ?Visitor $visitor = null; protected ?Company $company = null; - public function __construct(int $timePeriod = self::PERIOD_DEFAULT) + /** + * @param int $timePeriodValue Must be a different variable name then "timePeriod" or "timePeriodDefault" + */ + public function __construct(int $timePeriodValue = self::PERIOD_DEFAULT) { - $this->setTimePeriod($timePeriod); + $this->setTimePeriodDefault($timePeriodValue); } public function getSearchterm(): string @@ -232,7 +241,7 @@ public function getTimePeriod(): int public function isTimePeriodSet(): bool { - return $this->timePeriod !== self::PERIOD_DEFAULT; + return $this->timePeriod !== $this->timePeriodDefault; } public function setTimePeriod(int $timePeriod): self @@ -241,6 +250,18 @@ public function setTimePeriod(int $timePeriod): self return $this; } + public function getTimePeriodDefault(): int + { + return $this->timePeriodDefault; + } + + public function setTimePeriodDefault(int $timePeriodDefault): self + { + $this->timePeriodDefault = $timePeriodDefault; + $this->timePeriod = $timePeriodDefault; + return $this; + } + public function getIdentified(): int { return $this->identified;