diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index efd5834ad..a5b5125f8 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -212,6 +212,20 @@ public function cgetAction(Request $request): Response $limit = (int) $this->restHelper->getLimit(); $page = (int) $this->restHelper->getPage(); + /** @var array{ + * authored?: array{ + * from: string, + * to: string, + * }, + * type?: string, + * contactId?: string, + * categoryId?: string, + * tagId?: string, + * pageId?: string, + * publishedState?: string, + * } $filter */ + $filter = $request->query->all()['filter'] ?? []; + if (null !== $locale) { $search->addQuery(new TermQuery('locale', $locale)); } @@ -235,7 +249,7 @@ public function cgetAction(Request $request): Response $search->addQuery($boolQuery); } - if (null !== ($typeString = $request->get('types'))) { + if (null !== ($typeString = $request->get('types', $filter['type'] ?? null))) { $types = \explode(',', $typeString); if (\count($types) > 1) { @@ -251,7 +265,7 @@ public function cgetAction(Request $request): Response } } - if ($contactId = $request->get('contactId')) { + if ($contactId = $request->get('contactId', $filter['contactId'] ?? null)) { $boolQuery = new BoolQuery(); $boolQuery->add(new MatchQuery('changer_contact_id', $contactId), BoolQuery::SHOULD); $boolQuery->add(new MatchQuery('creator_contact_id', $contactId), BoolQuery::SHOULD); @@ -259,19 +273,19 @@ public function cgetAction(Request $request): Response $search->addQuery($boolQuery); } - if ($categoryId = $request->get('categoryId')) { + if ($categoryId = $request->get('categoryId', $filter['categoryId'] ?? null)) { $search->addQuery(new TermQuery('excerpt.categories.id', $categoryId), BoolQuery::MUST); } - if ($tagId = $request->get('tagId')) { + if ($tagId = $request->get('tagId', $filter['tagId'] ?? null)) { $search->addQuery(new TermQuery('excerpt.tags.id', $tagId), BoolQuery::MUST); } - if ($pageId = $request->get('pageId')) { + if ($pageId = $request->get('pageId', $filter['pageId'] ?? null)) { $search->addQuery(new TermQuery('parent_page_uuid', $pageId), BoolQuery::MUST); } - if ($workflowStage = $request->get('workflowStage')) { + if ($workflowStage = $request->get('workflowStage', $filter['publishedState'] ?? null)) { $search->addQuery(new TermQuery('published_state', 'published' === $workflowStage), BoolQuery::MUST); } @@ -283,8 +297,8 @@ public function cgetAction(Request $request): Response $search->addQuery(new TermQuery('localization_state.state', 'ghost'), BoolQuery::MUST_NOT); } - $authoredFrom = $request->get('authoredFrom'); - $authoredTo = $request->get('authoredTo'); + $authoredFrom = $request->get('authoredFrom', $this->convertDateTime($filter['authored']['from'] ?? null)); + $authoredTo = $request->get('authoredTo', $this->convertDateTime($filter['authored']['to'] ?? null)); if ($authoredFrom || $authoredTo) { $search->addQuery($this->getRangeQuery('authored', $authoredFrom, $authoredTo), BoolQuery::MUST); } @@ -683,4 +697,15 @@ private function getSortFieldName(string $sortBy): ?string return null; } + + private function convertDateTime(?string $dateTimeString): ?string + { + if (!$dateTimeString) { + return null; + } + + $dateTime = new \DateTime($dateTimeString); + + return $dateTime->format('Y-m-d'); + } } diff --git a/Metadata/ListMetadataVisitor.php b/Metadata/ListMetadataVisitor.php new file mode 100644 index 000000000..e36d89278 --- /dev/null +++ b/Metadata/ListMetadataVisitor.php @@ -0,0 +1,117 @@ + + */ + private $articleTypeConfigurations; + + /** + * @param array $articleTypeConfigurations + */ + public function __construct(StructureManagerInterface $structureManager, array $articleTypeConfigurations) + { + $this->structureManager = $structureManager; + $this->articleTypeConfigurations = $articleTypeConfigurations; + } + + public function visitListMetadata(ListMetadata $listMetadata, string $key, string $locale, array $metadataOptions = []): void + { + if ('articles' !== $key) { + return; + } + + $typeField = $listMetadata->getField('type'); + + $types = $this->getTypes(); + if (1 === \count($types)) { + $typeField->setFilterType(null); + $typeField->setFilterTypeParameters(null); + + return; + } + + $options = []; + foreach ($types as $type) { + $options[$type['type']] = $type['title']; + } + + $typeField->setFilterTypeParameters(['options' => $options]); + } + + /** + * @return array + */ + private function getTypes(): array + { + $types = []; + + // prefill array with keys from configuration to keep order of configuration for tabs + foreach ($this->articleTypeConfigurations as $typeKey => $articleTypeConfiguration) { + $types[$typeKey] = [ + 'type' => $typeKey, + 'title' => $this->getTitle($typeKey), + ]; + } + + /** @var StructureBridge $structure */ + foreach ($this->structureManager->getStructures('article') as $structure) { + /** @var string|null $type */ + $type = $this->getType($structure->getStructure(), null); + $typeKey = $type ?: 'default'; + if (empty($types[$typeKey])) { + $types[$typeKey] = [ + 'type' => $typeKey, + 'title' => $this->getTitle($typeKey), + ]; + } + } + + return $types; + } + + private function getTitle(string $type): string + { + if (!\array_key_exists($type, $this->articleTypeConfigurations)) { + return \ucfirst($type); + } + + return $this->articleTypeConfigurations[$type]['translation_key']; + } +} diff --git a/Resources/config/lists/articles.xml b/Resources/config/lists/articles.xml index ad1676bb8..ce8fd1288 100644 --- a/Resources/config/lists/articles.xml +++ b/Resources/config/lists/articles.xml @@ -14,6 +14,13 @@ visibility="no" translation="sulu_admin.type" /> + + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 07065a0e4..ef46fdaf9 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -526,5 +526,15 @@ + + + + %sulu_article.types% + + + diff --git a/Resources/translations/admin.de.json b/Resources/translations/admin.de.json index 2e0b6333a..1411b8748 100644 --- a/Resources/translations/admin.de.json +++ b/Resources/translations/admin.de.json @@ -11,6 +11,9 @@ "sulu_article.additional_webspace": "Zusätzliche Webspaces", "sulu_article.shadow_article": "Shadow Artikel", "sulu_article.enable_shadow_article": "Shadow Artikel aktivieren", + "sulu_article.published_state": "Status der Veröffentlichung", + "sulu_article.published": "Veröffentlicht", + "sulu_article.not_published": "Nicht Veröffentlicht", "sulu_activity.resource.articles": "Artikel", "sulu_activity.resource.articles.translation": "Übersetzung", "sulu_activity.description.articles.created": "{userFullName} hat den Artikel \"{resourceTitle}\" erstellt", diff --git a/Resources/translations/admin.en.json b/Resources/translations/admin.en.json index b0fd5fc35..7fb46e75b 100644 --- a/Resources/translations/admin.en.json +++ b/Resources/translations/admin.en.json @@ -11,6 +11,9 @@ "sulu_article.additional_webspace": "Additional webspaces", "sulu_article.shadow_article": "Shadow Article", "sulu_article.enable_shadow_article": "Enable Shadow Article", + "sulu_article.published_state": "Published State", + "sulu_article.published": "Published", + "sulu_article.not_published": "Not Published", "sulu_activity.resource.articles": "Article", "sulu_activity.resource.articles.translation": "Translation", "sulu_activity.description.articles.created": "{userFullName} has created the article \"{resourceTitle}\"", diff --git a/composer.json b/composer.json index 1128475a2..014df2007 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "jangregor/phpstan-prophecy": "^1.0", "massive/build-bundle": "^0.3 || ^0.4 || ^0.5", "phpcr/phpcr-shell": "^1.1", + "phpspec/prophecy": "^1.15", "phpstan/phpstan": "^1.0", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0",