diff --git a/Classes/Controller/AbstractNewsletterController.php b/Classes/Controller/AbstractNewsletterController.php index 350d0b7e..495d5c9e 100644 --- a/Classes/Controller/AbstractNewsletterController.php +++ b/Classes/Controller/AbstractNewsletterController.php @@ -98,11 +98,11 @@ protected function setFilter(): void $filter ); } - if (isset($filter['usergroup']['__identity']) && $filter['usergroup']['__identity'] === '0') { - unset($filter['usergroup']); - } - if (array_key_exists('category', $filter) && (is_array($filter['category']) || $filter['category'] === '')) { - $filter['category'] = 0; + $clearFields = ['usergroup', 'configuration', 'category']; + foreach ($clearFields as $clearField) { + if (($filter[$clearField] ?? '0') === '0' || is_array($filter[$clearField])) { + unset($filter[$clearField]); + } } $this->request = $this->request->withArgument('filter', $filter); } diff --git a/Classes/Controller/NewsletterController.php b/Classes/Controller/NewsletterController.php index 7deee365..e5b3eccf 100644 --- a/Classes/Controller/NewsletterController.php +++ b/Classes/Controller/NewsletterController.php @@ -65,9 +65,9 @@ public function initializeListAction(): void public function listAction(Filter $filter): ResponseInterface { $this->view->assignMultiple([ - 'newsletters' => $this->newsletterRepository->findAll(), + 'newsletters' => $this->newsletterRepository->findAllAuthorized(), 'newslettersGrouped' => $this->newsletterRepository->findAllGroupedByCategories($filter), - 'configurations' => $this->configurationRepository->findAll(), + 'configurations' => $this->configurationRepository->findAllAuthorized(), 'categories' => $this->categoryRepository->findAllLuxletterCategories(), 'filter' => $filter, ]); diff --git a/Classes/Domain/Model/Dto/Filter.php b/Classes/Domain/Model/Dto/Filter.php index f09e25b9..d99cc1e0 100644 --- a/Classes/Domain/Model/Dto/Filter.php +++ b/Classes/Domain/Model/Dto/Filter.php @@ -4,121 +4,114 @@ namespace In2code\Luxletter\Domain\Model\Dto; use DateTime; +use In2code\Luxletter\Domain\Model\Category; +use In2code\Luxletter\Domain\Model\Configuration; use In2code\Luxletter\Domain\Model\Usergroup; use In2code\Luxletter\Utility\LocalizationUtility; -/** - * Class Filter - */ class Filter { - const TIME_DEFAULT = 0; - const TIME_1_WEEK = 10; - const TIME_1_MONTH = 20; - const TIME_3_MONTHS = 30; - const TIME_6_MONTHS = 40; - const TIME_1_YEAR = 50; + public const TIME_DEFAULT = 0; + public const TIME_1_WEEK = 10; + public const TIME_1_MONTH = 20; + public const TIME_3_MONTHS = 30; + public const TIME_6_MONTHS = 40; + public const TIME_1_YEAR = 50; - /** - * @var string - */ - protected $searchterm = ''; + protected string $searchterm = ''; - /** - * @var Usergroup - */ - protected $usergroup = null; + protected ?Usergroup $usergroup = null; + protected ?Category $category = null; + protected ?Configuration $configuration = null; - /** - * @var \In2code\Luxletter\Domain\Model\Category|null - */ - protected $category = null; - - /** - * @var int - */ - protected $time = self::TIME_DEFAULT; + protected int $time = self::TIME_DEFAULT; /** * This is just a dummy property, that helps to recognize if a filter is set and helps to save this to the session * * @var bool */ - protected $reset = false; + protected bool $reset = false; - /** - * @return string - */ public function getSearchterm(): string { return $this->searchterm; } - /** - * @return string[] - */ + public function isSearchtermSet(): bool + { + return $this->getSearchterm() !== ''; + } + public function getSearchterms(): array { return explode(' ', $this->getSearchterm()); } - /** - * @param string $searchterm - * @return Filter - */ public function setSearchterm(string $searchterm): self { $this->searchterm = $searchterm; return $this; } - /** - * @return Usergroup - */ public function getUsergroup(): ?Usergroup { return $this->usergroup; } - /** - * @param Usergroup|null $usergroup - * @return Filter - */ + public function isUsergroupSet(): bool + { + return $this->getUsergroup() !== null; + } + public function setUsergroup(?Usergroup $usergroup): self { $this->usergroup = $usergroup; return $this; } - /** - * @return \In2code\Luxletter\Domain\Model\Category|null - */ - public function getCategory(): ?\In2code\Luxletter\Domain\Model\Category + public function getCategory(): ?Category { return $this->category; } - /** - * @param \In2code\Luxletter\Domain\Model\Category|null $category - * @return Filter - */ - public function setCategory(?\In2code\Luxletter\Domain\Model\Category $category): Filter + public function isCategorySet(): bool + { + return $this->getCategory() !== null; + } + + public function setCategory(?Category $category): Filter { $this->category = $category; return $this; } - /** - * @return int - */ + public function getConfiguration(): ?Configuration + { + return $this->configuration; + } + + public function isConfigurationSet(): bool + { + return $this->getConfiguration() !== null; + } + + public function setConfiguration(?Configuration $configuration): self + { + $this->configuration = $configuration; + return $this; + } + public function getTime(): int { return $this->time; } - /** - * @return DateTime - */ + public function isTimeSet(): bool + { + return $this->getTime() !== self::TIME_DEFAULT; + } + public function getTimeDateStart(): DateTime { $date = new DateTime(); @@ -142,40 +135,30 @@ public function getTimeDateStart(): DateTime return $date; } - /** - * @param int $time - * @return Filter - */ public function setTime(int $time): Filter { $this->time = $time; return $this; } - /** - * @return bool - */ public function isReset(): bool { return $this->reset; } - /** - * @param bool $reset - * @return Filter - */ public function setReset(bool $reset): self { $this->reset = $reset; return $this; } - /** - * @return bool - */ public function isSet(): bool { - return $this->searchterm !== '' || $this->usergroup !== null || $this->category !== null || $this->time > 0; + return $this->isSearchtermSet() + || $this->isConfigurationSet() + || $this->isUsergroupSet() + || $this->isCategorySet() + || $this->isTimeSet(); } public function getTimeOptions(): array diff --git a/Classes/Domain/Repository/NewsletterRepository.php b/Classes/Domain/Repository/NewsletterRepository.php index c69e0b99..0c4e4e94 100644 --- a/Classes/Domain/Repository/NewsletterRepository.php +++ b/Classes/Domain/Repository/NewsletterRepository.php @@ -8,13 +8,26 @@ use In2code\Luxletter\Domain\Model\Log; use In2code\Luxletter\Domain\Model\Newsletter; use In2code\Luxletter\Domain\Model\Queue; +use In2code\Luxletter\Domain\Service\SiteService; +use In2code\Luxletter\Utility\BackendUserUtility; use In2code\Luxletter\Utility\DatabaseUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; class NewsletterRepository extends AbstractRepository { + public function findAllAuthorized(): QueryResultInterface + { + $query = $this->createQuery(); + if (BackendUserUtility::isAdministrator() === false) { + $siteService = GeneralUtility::makeInstance(SiteService::class); + $query->matching($query->in('configuration.site', array_keys($siteService->getAllowedSites()))); + } + return $query->execute(); + } + public function findLatestNewsletter(): ?Newsletter { $query = $this->createQuery(); @@ -60,8 +73,8 @@ public function findAllGroupedByCategories(Filter $filter): array protected function findAllByFilter(Filter $filter): ?QueryResultInterface { $query = $this->createQuery(); + $logicalAnd = []; if ($filter->isSet()) { - $logicalAnd = [$query->greaterThan('uid', 0)]; if ($filter->getSearchterm() !== '') { $logicalOr = []; foreach ($filter->getSearchterms() as $searchterm) { @@ -77,6 +90,15 @@ protected function findAllByFilter(Filter $filter): ?QueryResultInterface if ($filter->getTime() > 0) { $logicalAnd[] = $query->greaterThanOrEqual('crdate', $filter->getTimeDateStart()); } + if ($filter->isConfigurationSet()) { + $logicalAnd[] = $query->equals('configuration', $filter->getConfiguration()); + } + } + if (BackendUserUtility::isAdministrator() === false) { + $siteService = GeneralUtility::makeInstance(SiteService::class); + $logicalAnd[] = $query->in('configuration.site', array_keys($siteService->getAllowedSites())); + } + if ($logicalAnd !== []) { $query->matching($query->logicalAnd(...$logicalAnd)); } return $query->execute(); diff --git a/Resources/Private/Partials/Filter/NewsletterList.html b/Resources/Private/Partials/Filter/NewsletterList.html index 3ff53338..d9102cc9 100644 --- a/Resources/Private/Partials/Filter/NewsletterList.html +++ b/Resources/Private/Partials/Filter/NewsletterList.html @@ -7,7 +7,7 @@