diff --git a/src/Criteria/NewsCriteriaBuilder.php b/src/Criteria/NewsCriteriaBuilder.php index f3e1d2b..2409df2 100644 --- a/src/Criteria/NewsCriteriaBuilder.php +++ b/src/Criteria/NewsCriteriaBuilder.php @@ -13,7 +13,6 @@ namespace Codefog\NewsCategoriesBundle\Criteria; use Codefog\HasteBundle\Model\DcaRelationsModel; -use Codefog\NewsCategoriesBundle\Exception\CategoryFilteringNotAppliedException; use Codefog\NewsCategoriesBundle\Exception\CategoryNotFoundException; use Codefog\NewsCategoriesBundle\Exception\NoNewsException; use Codefog\NewsCategoriesBundle\FrontendModule\CumulativeFilterModule; @@ -67,8 +66,6 @@ public function getCriteriaForArchiveModule(array $archives, int $begin, int $en $this->setRegularListCriteria($criteria, $module); } catch (NoNewsException) { return null; - } catch (CategoryFilteringNotAppliedException $e) { - // noop } return $criteria; @@ -77,7 +74,7 @@ public function getCriteriaForArchiveModule(array $archives, int $begin, int $en /** * Get the criteria for list module. */ - public function getCriteriaForListModule(array $archives, bool|null $featured, Module $module, bool $throwOnFilteringNotApplied = false): NewsCriteria|null + public function getCriteriaForListModule(array $archives, bool|null $featured, Module $module): NewsCriteria|null { $criteria = new NewsCriteria($this->framework, $this->tokenChecker); @@ -94,14 +91,10 @@ public function getCriteriaForListModule(array $archives, bool|null $featured, M $this->setRelatedListCriteria($criteria, $module); } else { // Set the regular list criteria - $this->setRegularListCriteria($criteria, $module, $throwOnFilteringNotApplied); + $this->setRegularListCriteria($criteria, $module); } } catch (NoNewsException) { return null; - } catch (CategoryFilteringNotAppliedException $e) { - if ($throwOnFilteringNotApplied) { - throw $e; - } } return $criteria; @@ -123,8 +116,6 @@ public function getCriteriaForMenuModule(array $archives, Module $module): NewsC $this->setRegularListCriteria($criteria, $module); } catch (NoNewsException) { return null; - } catch (CategoryFilteringNotAppliedException $e) { - // noop } return $criteria; @@ -138,12 +129,9 @@ public function getCriteriaForMenuModule(array $archives, Module $module): NewsC */ private function setRegularListCriteria(NewsCriteria $criteria, Module $module): void { - $filteringApplied = false; - // Filter by default categories if (!empty($default = StringUtil::deserialize($module->news_filterDefault, true))) { $criteria->setDefaultCategories($default); - $filteringApplied = true; } // Filter by multiple active categories @@ -177,13 +165,13 @@ private function setRegularListCriteria(NewsCriteria $criteria, Module $module): } } } - - $filteringApplied = true; } + + return; } + // Filter by active category - elseif ($module->news_filterCategories) { - /** @var Input $input */ + if ($module->news_filterCategories) { $input = $this->framework->getAdapter(Input::class); $param = $this->manager->getParameterName(); @@ -196,14 +184,8 @@ private function setRegularListCriteria(NewsCriteria $criteria, Module $module): } $criteria->setCategory($category->id, (bool) $module->news_filterPreserve, (bool) $module->news_includeSubcategories); - - $filteringApplied = true; } } - - if (!$filteringApplied) { - throw new CategoryFilteringNotAppliedException(); - } } /** diff --git a/src/EventListener/NewsListener.php b/src/EventListener/NewsListener.php index 43552a8..060421e 100644 --- a/src/EventListener/NewsListener.php +++ b/src/EventListener/NewsListener.php @@ -14,7 +14,6 @@ use Codefog\NewsCategoriesBundle\Criteria\NewsCriteria; use Codefog\NewsCategoriesBundle\Criteria\NewsCriteriaBuilder; -use Codefog\NewsCategoriesBundle\Exception\CategoryFilteringNotAppliedException; use Codefog\NewsCategoriesBundle\Exception\CategoryNotFoundException; use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Exception\PageNotFoundException; @@ -31,12 +30,8 @@ public function __construct(private readonly NewsCriteriaBuilder $searchBuilder) #[AsHook('newsListCountItems')] public function onNewsListCountItems(array $archives, bool|null $featured, ModuleNewsList $module): int { - try { - if (null === ($criteria = $this->getCriteria($archives, $featured, $module))) { - return 0; - } - } catch (CategoryFilteringNotAppliedException $e) { - return false; + if (null === ($criteria = $this->getCriteria($archives, $featured, $module))) { + return 0; } return NewsModel::countBy($criteria->getColumns(), $criteria->getValues()); @@ -48,12 +43,8 @@ public function onNewsListCountItems(array $archives, bool|null $featured, Modul #[AsHook('newsListFetchItems')] public function onNewsListFetchItems(array $archives, bool|null $featured, int $limit, int $offset, ModuleNewsList $module): Collection|null { - try { - if (null === ($criteria = $this->getCriteria($archives, $featured, $module))) { - return null; - } - } catch (CategoryFilteringNotAppliedException $e) { - return false; + if (null === ($criteria = $this->getCriteria($archives, $featured, $module))) { + return null; } $criteria->setLimit($limit); @@ -69,7 +60,7 @@ public function onNewsListFetchItems(array $archives, bool|null $featured, int $ private function getCriteria(array $archives, bool|null $featured, ModuleNewsList $module): NewsCriteria|null { try { - $criteria = $this->searchBuilder->getCriteriaForListModule($archives, $featured, $module, true); + $criteria = $this->searchBuilder->getCriteriaForListModule($archives, $featured, $module); } catch (CategoryNotFoundException $e) { throw new PageNotFoundException($e->getMessage(), 0, $e); } diff --git a/src/Exception/CategoryFilteringNotAppliedException.php b/src/Exception/CategoryFilteringNotAppliedException.php deleted file mode 100644 index aec8295..0000000 --- a/src/Exception/CategoryFilteringNotAppliedException.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @license MIT - */ - -namespace Codefog\NewsCategoriesBundle\Exception; - -class CategoryFilteringNotAppliedException extends \RuntimeException -{ -}