From 81943b50043cd9ac84381423d07788fa3a8c684b Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Wed, 18 Dec 2024 09:04:50 +0200 Subject: [PATCH 1/3] feat: introduce editableOnly method for admin-only taxonomy visibility and editing --- src/Infrastructure/Content/Taxonomy/Taxonomy.php | 14 ++++++++++++++ tests/unit/Content/TaxonomyTest.php | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Infrastructure/Content/Taxonomy/Taxonomy.php b/src/Infrastructure/Content/Taxonomy/Taxonomy.php index f92502e..589ef9c 100644 --- a/src/Infrastructure/Content/Taxonomy/Taxonomy.php +++ b/src/Infrastructure/Content/Taxonomy/Taxonomy.php @@ -48,6 +48,20 @@ final public static function hidden(): static ); } + final public static function editableOnly(): static + { + return self::default()->merge( + [ + 'public' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => false, + 'show_in_rest' => true, + 'meta_box_cb' => false, + ] + ); + } + final public function args(): array { return $this->args; diff --git a/tests/unit/Content/TaxonomyTest.php b/tests/unit/Content/TaxonomyTest.php index 5563fb4..36beb4b 100644 --- a/tests/unit/Content/TaxonomyTest.php +++ b/tests/unit/Content/TaxonomyTest.php @@ -50,6 +50,22 @@ public function testTaxonomyArgGeneration(): void DegreeTaxonomy::public()->args() ); + $this->assertSame( + [ + 'label' => 'Degrees', + 'labels' => $expectedLabels, + 'hierarchical' => true, + 'rest_base' => 'degree', + 'public' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => false, + 'show_in_rest' => true, + 'meta_box_cb' => false, + ], + DegreeTaxonomy::editableOnly()->args() + ); + $this->assertSame( [ 'label' => 'Degrees', From c5de598f6bbea279b2c3a351929473cd95365327 Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Fri, 20 Dec 2024 13:09:33 +0200 Subject: [PATCH 2/3] feat: update search keyword filter to handle multi-word queries --- .../Repository/WpQueryArgsBuilder.php | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/Infrastructure/Repository/WpQueryArgsBuilder.php b/src/Infrastructure/Repository/WpQueryArgsBuilder.php index 8f3f41d..140dbe4 100644 --- a/src/Infrastructure/Repository/WpQueryArgsBuilder.php +++ b/src/Infrastructure/Repository/WpQueryArgsBuilder.php @@ -270,31 +270,28 @@ private function applyTaxonomyFilter(Filter $filter, WpQueryArgs $queryArgs): Wp private function applySearchFilter(SearchKeywordFilter $filter, WpQueryArgs $queryArgs, ?string $languageCode = null): WpQueryArgs { - if (!$languageCode) { - return $queryArgs->withMetaQueryItem( - [ - 'relation' => 'OR', - [ - 'key' => 'fau_degree_program_searchable_content_' . MultilingualString::EN, - 'value' => $filter->value(), - 'compare' => 'LIKE', - ], - [ - 'key' => 'fau_degree_program_searchable_content_' . MultilingualString::DE, - 'value' => $filter->value(), - 'compare' => 'LIKE', - ], - ] - ); - } + $keywords = array_filter(array_map('trim', explode(' ', $filter->value()))); + $metaKeyPrefix = 'fau_degree_program_searchable_content_'; + $metaKeys = $languageCode + ? [$metaKeyPrefix . $languageCode] + : [$metaKeyPrefix . MultilingualString::EN, $metaKeyPrefix . MultilingualString::DE]; + + $metaQuery = array_reduce($keywords, static function ($metaQuery, $keyword) use ($metaKeys): array { + $keywordConditions = array_values(array_map( + static fn($key) => [ + 'key' => $key, + 'value' => $keyword, + 'compare' => 'LIKE', + ], + $metaKeys + )); - return $queryArgs->withMetaQueryItem( - [ - 'key' => 'fau_degree_program_searchable_content_' . $languageCode, - 'value' => $filter->value(), - 'compare' => 'LIKE', - ] - ); + $metaQuery[] = ['relation' => 'OR'] + $keywordConditions; + + return $metaQuery; + }, ['relation' => 'AND']); + + return $queryArgs->withMetaQueryItem($metaQuery); } private function currentTerm(CollectionCriteria $criteria): ?WP_Term From 4f02dfc748855136e1332015e58bad83dcf8c6a2 Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Fri, 20 Dec 2024 15:08:55 +0200 Subject: [PATCH 3/3] refactor: improve code readability --- psalm-baseline.xml | 1 - src/Infrastructure/Repository/WpQueryArgsBuilder.php | 11 ++++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 24e38e5..24c3ea5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -38,7 +38,6 @@ - diff --git a/src/Infrastructure/Repository/WpQueryArgsBuilder.php b/src/Infrastructure/Repository/WpQueryArgsBuilder.php index 140dbe4..52f5a36 100644 --- a/src/Infrastructure/Repository/WpQueryArgsBuilder.php +++ b/src/Infrastructure/Repository/WpQueryArgsBuilder.php @@ -17,15 +17,12 @@ use Fau\DegreeProgram\Common\Application\Filter\SubjectGroupFilter; use Fau\DegreeProgram\Common\Application\Filter\TeachingLanguageFilter; use Fau\DegreeProgram\Common\Application\Repository\CollectionCriteria; -use Fau\DegreeProgram\Common\Domain\CampoKeys; use Fau\DegreeProgram\Common\Domain\DegreeProgram; use Fau\DegreeProgram\Common\Domain\MultilingualString; use Fau\DegreeProgram\Common\Infrastructure\Content\PostType\DegreeProgramPostType; use Fau\DegreeProgram\Common\Infrastructure\Content\Taxonomy\BachelorOrTeachingDegreeAdmissionRequirementTaxonomy; use Fau\DegreeProgram\Common\Infrastructure\Content\Taxonomy\MasterDegreeAdmissionRequirementTaxonomy; use Fau\DegreeProgram\Common\Infrastructure\Content\Taxonomy\TaxonomiesList; -use Fau\DegreeProgram\Common\Infrastructure\Content\Taxonomy\TeachingDegreeHigherSemesterAdmissionRequirementTaxonomy; -use RuntimeException; use WP_Term; /** @@ -272,19 +269,19 @@ private function applySearchFilter(SearchKeywordFilter $filter, WpQueryArgs $que { $keywords = array_filter(array_map('trim', explode(' ', $filter->value()))); $metaKeyPrefix = 'fau_degree_program_searchable_content_'; - $metaKeys = $languageCode + $metaKeys = is_string($languageCode) && $languageCode ? [$metaKeyPrefix . $languageCode] : [$metaKeyPrefix . MultilingualString::EN, $metaKeyPrefix . MultilingualString::DE]; - $metaQuery = array_reduce($keywords, static function ($metaQuery, $keyword) use ($metaKeys): array { - $keywordConditions = array_values(array_map( + $metaQuery = array_reduce($keywords, static function (array $metaQuery, string $keyword) use ($metaKeys): array { + $keywordConditions = array_map( static fn($key) => [ 'key' => $key, 'value' => $keyword, 'compare' => 'LIKE', ], $metaKeys - )); + ); $metaQuery[] = ['relation' => 'OR'] + $keywordConditions;