Skip to content

Commit 9a754f8

Browse files
committed
feat: use parent term as the data source for 'German language skills for international students' filter and column, if exists
1 parent 34731ed commit 9a754f8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Infrastructure/Repository/WordPressDatabaseDegreeProgramRepository.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function getById(DegreeProgramId $degreeProgramId): DegreeProgram
182182
true
183183
),
184184
germanLanguageSkillsForInternationalStudents: $this->bilingualLinkFromTerm(
185-
$this->firstTerm(
185+
$this->firstTopTerm(
186186
$post,
187187
GermanLanguageSkillsForInternationalStudentsTaxonomy::KEY,
188188
)
@@ -273,6 +273,27 @@ private function firstTerm(WP_Post $post, string $taxonomy): ?WP_Term
273273
return $terms[0];
274274
}
275275

276+
private function firstTopTerm(WP_Post $post, string $taxonomy): ?WP_Term
277+
{
278+
$terms = get_the_terms($post, $taxonomy);
279+
280+
if (!is_array($terms)) {
281+
return null;
282+
}
283+
284+
if (!isset($terms[0]) || !$terms[0] instanceof WP_Term) {
285+
return null;
286+
}
287+
288+
if (!$terms[0]->parent) {
289+
return $terms[0];
290+
}
291+
292+
$parent = get_term($terms[0]->parent);
293+
294+
return $parent instanceof WP_Term ? $parent : $terms[0];
295+
}
296+
276297
private function degree(WP_Post $post): Degree
277298
{
278299
$term = $this->firstTerm($post, DegreeTaxonomy::KEY);

0 commit comments

Comments
 (0)