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/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/src/Infrastructure/Repository/WpQueryArgsBuilder.php b/src/Infrastructure/Repository/WpQueryArgsBuilder.php index 8f3f41d..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; /** @@ -270,31 +267,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 = is_string($languageCode) && $languageCode + ? [$metaKeyPrefix . $languageCode] + : [$metaKeyPrefix . MultilingualString::EN, $metaKeyPrefix . MultilingualString::DE]; + + $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 ); - } - 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 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',