Skip to content

Commit

Permalink
Merge branch 'main' into FAU-443
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyian committed Dec 26, 2024
2 parents 7d49552 + 97b104c commit f9b1698
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
</file>
<file src="src/Infrastructure/Repository/WpQueryArgsBuilder.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[!$languageCode]]></code>
<code><![CDATA[!$orderBy]]></code>
<code><![CDATA[!$taxonomy]]></code>
<code><![CDATA[$languageCode]]></code>
Expand Down
14 changes: 14 additions & 0 deletions src/Infrastructure/Content/Taxonomy/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 20 additions & 26 deletions src/Infrastructure/Repository/WpQueryArgsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/Content/TaxonomyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f9b1698

Please sign in to comment.