Skip to content

Commit

Permalink
[FEATURE] Also add site select to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Mar 4, 2024
1 parent 9074c5d commit ca0f202
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public function initializeListAction(): void
public function listAction(Filter $filter): ResponseInterface
{
$this->view->assignMultiple([
'newsletters' => $this->newsletterRepository->findAllAuthorized(),
'filter' => $filter,
'newsletters' => $this->newsletterRepository->findAllAuthorized($filter),
'newslettersGrouped' => $this->newsletterRepository->findAllGroupedByCategories($filter),
'configurations' => $this->configurationRepository->findAllAuthorized(),
'categories' => $this->categoryRepository->findAllLuxletterCategories(),
'filter' => $filter,
]);

$this->addDocumentHeaderForNewsletterController();
Expand Down
44 changes: 44 additions & 0 deletions Classes/Domain/Model/Dto/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use In2code\Luxletter\Domain\Model\Category;
use In2code\Luxletter\Domain\Model\Configuration;
use In2code\Luxletter\Domain\Model\Usergroup;
use In2code\Luxletter\Domain\Service\SiteService;
use In2code\Luxletter\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Filter
{
Expand All @@ -19,6 +21,7 @@ class Filter
public const TIME_1_YEAR = 50;

protected string $searchterm = '';
protected string $site = '';

protected ?Usergroup $usergroup = null;
protected ?Category $category = null;
Expand Down Expand Up @@ -54,6 +57,22 @@ public function setSearchterm(string $searchterm): self
return $this;
}

public function getSite(): string
{
return $this->site;
}

public function isSiteSet(): bool
{
return $this->getSite() !== '';
}

public function setSite(string $site): self
{
$this->site = $site;
return $this;
}

public function getUsergroup(): ?Usergroup
{
return $this->usergroup;
Expand Down Expand Up @@ -155,6 +174,7 @@ public function setReset(bool $reset): self
public function isSet(): bool
{
return $this->isSearchtermSet()
|| $this->isSiteSet()
|| $this->isConfigurationSet()
|| $this->isUsergroupSet()
|| $this->isCategorySet()
Expand All @@ -173,4 +193,28 @@ public function getTimeOptions(): array
self::TIME_1_YEAR => LocalizationUtility::translate($llPrefix . self::TIME_1_YEAR),
];
}

/**
* Get all sites on which the current editor has reading access
*
* @return array
*/
public function getAllowedSites(): array
{
$siteService = GeneralUtility::makeInstance(SiteService::class);
return $siteService->getAllowedSites();
}

/**
* Always return given site or all available sites, so this can be always used in sql queries even for admins
*
* @return array
*/
public function getSitesForFilter(): array
{
if ($this->isSiteSet()) {
return [$this->getSite()];
}
return array_merge(array_keys($this->getAllowedSites()), ['']);
}
}
19 changes: 11 additions & 8 deletions Classes/Domain/Repository/NewsletterRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
use In2code\Luxletter\Utility\BackendUserUtility;
use In2code\Luxletter\Utility\DatabaseUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
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
/**
* Find all newsletters, no matter what filter is set (to show "add new" button in output)
*
* @param Filter $filter
* @return QueryResultInterface
* @throws InvalidQueryException
*/
public function findAllAuthorized(Filter $filter): QueryResultInterface
{
$query = $this->createQuery();
if (BackendUserUtility::isAdministrator() === false) {
Expand Down Expand Up @@ -94,13 +102,8 @@ protected function findAllByFilter(Filter $filter): ?QueryResultInterface
$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));
}
$logicalAnd[] = $query->in('configuration.site', $filter->getSitesForFilter());
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}

Expand Down
16 changes: 14 additions & 2 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,22 @@
<source>Searchterm</source>
<target state="translated">Suchbegriff</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.sitesall.labelprepend">
<source>All sites</source>
<target state="translated">Alle Sites</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.category.label">
<source>Category</source>
<target state="translated">Kategorie</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.category.labelprepend">
<source>All categories</source>
<target state="translated">Alle Kategorien</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.configuration.labelprepend">
<source>All senders</source>
<target state="translated">Alle Absender</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.submit">
<source>Filter now</source>
<target state="translated">Jetzt filtern</target>
Expand All @@ -214,8 +226,8 @@
<target state="translated">Zeitpunkt</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.time.0">
<source>Show all newsletters</source>
<target state="translated">Zeige alle Newsletter</target>
<source>All newsletters</source>
<target state="translated">Alle Newsletter</target>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.time.10">
<source>Show newsletters from the last week</source>
Expand Down
11 changes: 10 additions & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,18 @@
<trans-unit id="module.newsletter.list.filter.search.placeholder">
<source>Searchterm</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.sitesall.labelprepend">
<source>All sites</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.category.label">
<source>Category</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.category.labelprepend">
<source>All categories</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.configuration.labelprepend">
<source>All senders</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.submit">
<source>Filter now</source>
</trans-unit>
Expand All @@ -162,7 +171,7 @@
<source>Time</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.time.0">
<source>Show all newsletters</source>
<source>All newsletters</source>
</trans-unit>
<trans-unit id="module.newsletter.list.filter.time.10">
<source>Show newsletters from the last week</source>
Expand Down
64 changes: 41 additions & 23 deletions Resources/Private/Partials/Filter/NewsletterList.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,56 @@ <h5><f:translate key="module.newsletter.list.filter.search.label">search</f:tran
</button>
</div>

<div class="input-group form-group">
<f:form.select
id="site"
class="form-control form-select"
property="site"
options="{filter.allowedSites}"
prependOptionLabel="{f:translate(key:'module.newsletter.list.filter.sitesall.labelprepend')}"
prependOptionValue=""
optionValueField="identifier"
optionLabelField="configuration.websiteTitle"
value="{filter.site}" />
<button type="button" class="btn btn-default" data-global-event="click" data-action-focus="#site">
<core:icon identifier="actions-globe" size="small" />
</button>
</div>
</div>


<div class="col-xl-4 col-md-6 mb-3">
<h5><f:translate key="module.newsletter.list.filter.category.label">Category</f:translate></h5>

<div class="input-group form-group">
<label for="categoryScoring" class="hidden">
<f:translate key="module.newsletter.list.filter.category.label">Category</f:translate>
</label>
<f:form.select
property="category"
options="{categories}"
optionLabelField="title"
optionValueField="uid"
prependOptionValue="0"
prependOptionLabel="{f:translate(key:'module.newsletter.list.filter.category.labelprepend')}"
class="form-control form-select"
id="categoryScoring"/>
<button type="button" class="btn btn-default" data-global-event="click" data-action-focus="#categoryScoring">
<core:icon identifier="actions-tag" />
</button>
</div>

<div class="input-group form-group">
<f:form.select
id="configuration"
class="form-control form-select"
property="configuration"
options="{configurations}"
prependOptionLabel=""
prependOptionLabel="{f:translate(key:'module.newsletter.list.filter.configuration.labelprepend')}"
prependOptionValue="0"
optionValueField="uid"
optionLabelField="title"
value="{filter.configuration}" />
value="{filter.configuration.uid}" />
<button type="button" class="btn btn-default" data-global-event="click" data-action-focus="#configuration">
<core:icon identifier="actions-user" size="small" />
</button>
Expand All @@ -60,27 +99,6 @@ <h5><f:translate key="module.newsletter.list.filter.time.label">Time</f:translat
</button>
</div>

<div class="input-group form-group">
<label for="categoryScoring" class="hidden">
<f:translate key="module.newsletter.list.filter.category.label">Category</f:translate>
</label>
<f:form.select
property="category"
options="{categories}"
optionLabelField="title"
optionValueField="uid"
prependOptionValue="0"
prependOptionLabel=""
class="form-control form-select"
id="categoryScoring"/>
<button type="button" class="btn btn-default" data-global-event="click" data-action-focus="#categoryScoring">
<core:icon identifier="actions-tag" />
</button>
</div>
</div>


<div class="col-xl-4 col-md-6 mb-3" style="display: flex; flex-direction: column; justify-content: flex-end;">
<div style="display: flex; justify-content: space-between;">
<f:comment>Clear filter</f:comment>
<f:if condition="{filter.set}">
Expand Down

0 comments on commit ca0f202

Please sign in to comment.