Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FAU-434] Include campo keys from all related terms to degree program data #17

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Domain/CampoKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
namespace Fau\DegreeProgram\Common\Domain;

/**
* @psalm-type CampoKeysMap = array<value-of<self::SUPPORTED_CAMPO_KEYS>, string>
* @psalm-type CampoKeysMap = array<value-of<self::SUPPORTED_CAMPO_KEYS>, array<int, string>|string>
shvlv marked this conversation as resolved.
Show resolved Hide resolved
*/
final class CampoKeys
{
public const SCHEMA = [
'type' => 'object',
'properties' => [
DegreeProgram::DEGREE => [
'type' => 'string',
'type' => 'array',
],
DegreeProgram::AREA_OF_STUDY => [
'type' => 'string',
'type' => 'array',
],
DegreeProgram::LOCATION => [
'type' => 'string',
'type' => 'array',
],
],
];
Expand All @@ -28,13 +28,13 @@ final class CampoKeys
'type' => 'object',
'properties' => [
DegreeProgram::DEGREE => [
'type' => 'string',
'type' => 'array',
],
DegreeProgram::AREA_OF_STUDY => [
'type' => 'string',
'type' => 'array',
],
DegreeProgram::LOCATION => [
'type' => 'string',
'type' => 'array',
],
],
];
Expand Down
14 changes: 4 additions & 10 deletions src/Infrastructure/Repository/CampoKeysRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function degreeProgramCampoKeys(DegreeProgramId $degreeProgramId): CampoK
continue;
}

$map[$campoKeyType] = $campoKey;
$map[$campoKeyType][$term->term_id] = $campoKey;
}

return CampoKeys::fromArray($map);
Expand All @@ -60,7 +60,6 @@ public function degreeProgramCampoKeys(DegreeProgramId $degreeProgramId): CampoK
/**
* Return a map of taxonomy keys to terms based on a given HIS code.
*
* @throws RuntimeException
* @return array<string, int>
*/
public function taxonomyToTermsMapFromCampoKeys(CampoKeys $campoKeys): array
Expand All @@ -70,19 +69,14 @@ public function taxonomyToTermsMapFromCampoKeys(CampoKeys $campoKeys): array
$campoKeys = $campoKeys->asArray();

foreach (self::TAXONOMY_TO_CAMPO_KEY_MAP as $taxonomy => $campoKeyType) {
$campoKey = $campoKeys[$campoKeyType] ?? '';
$campoKey = $campoKeys[$campoKeyType] ?? null;

if ($campoKey === '') {
if (!is_string($campoKey) || $campoKey === '') {
continue;
}

$term = $this->findTermByCampoKey($taxonomy, $campoKey);

if (! $term instanceof WP_Term) {
throw new RuntimeException('Could not find term for Campo key: ' . $campoKey);
}

$result[$taxonomy] = $term->term_id;
$result[$taxonomy] = $term instanceof WP_Term ? $term->term_id : 0;
}

return $result;
Expand Down
10 changes: 3 additions & 7 deletions src/Infrastructure/Repository/WpQueryArgsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,9 @@ public function applyHisCodes(array $hisCodes, WpQueryArgs $queryArgs): WpQueryA
'relation' => 'AND',
];

try {
$taxonomyToTermMapping = $this->campoKeysRepository->taxonomyToTermsMapFromCampoKeys(
CampoKeys::fromHisCode($hisCode)
);
} catch (RuntimeException) {
continue;
}
$taxonomyToTermMapping = $this->campoKeysRepository->taxonomyToTermsMapFromCampoKeys(
CampoKeys::fromHisCode($hisCode)
);

if (count($taxonomyToTermMapping) === 0) {
continue;
Expand Down