Skip to content

Commit

Permalink
Merge pull request #7 from RRZE-Webteam/FAU-414
Browse files Browse the repository at this point in the history
[FAU-414] Add support for campo keys
  • Loading branch information
amiut authored May 24, 2024
2 parents 023a63d + df7cbd3 commit 8294700
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/schema_draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Fau\DegreeProgram\Common\Domain\AdmissionRequirement;
use Fau\DegreeProgram\Common\Domain\AdmissionRequirements;
use Fau\DegreeProgram\Common\Domain\CampoKeys;
use Fau\DegreeProgram\Common\Domain\Content;
use Fau\DegreeProgram\Common\Domain\ContentItem;
use Fau\DegreeProgram\Common\Domain\Degree;
Expand Down Expand Up @@ -150,5 +151,6 @@
DegreeProgram::STUDENT_INITIATIVES => MultilingualLink::SCHEMA,
DegreeProgram::APPLY_NOW_LINK => MultilingualLink::SCHEMA,
DegreeProgram::ENTRY_TEXT => MultilingualString::SCHEMA,
DegreeProgram::CAMPO_KEYS => CampoKeys::SCHEMA,
],
];
2 changes: 2 additions & 0 deletions config/schema_publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Fau\DegreeProgram\Common\Domain\AdmissionRequirement;
use Fau\DegreeProgram\Common\Domain\AdmissionRequirements;
use Fau\DegreeProgram\Common\Domain\CampoKeys;
use Fau\DegreeProgram\Common\Domain\Content;
use Fau\DegreeProgram\Common\Domain\ContentItem;
use Fau\DegreeProgram\Common\Domain\Degree;
Expand Down Expand Up @@ -155,5 +156,6 @@
DegreeProgram::STUDENT_INITIATIVES => MultilingualLink::SCHEMA,
DegreeProgram::APPLY_NOW_LINK => MultilingualLink::SCHEMA_REQUIRED,
DegreeProgram::ENTRY_TEXT => MultilingualString::SCHEMA_REQUIRED,
DegreeProgram::CAMPO_KEYS => CampoKeys::SCHEMA_REQUIRED,
],
];
10 changes: 10 additions & 0 deletions src/Application/DegreeProgramViewRaw.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Fau\DegreeProgram\Common\Application;

use Fau\DegreeProgram\Common\Domain\AdmissionRequirements;
use Fau\DegreeProgram\Common\Domain\CampoKeys;
use Fau\DegreeProgram\Common\Domain\Content;
use Fau\DegreeProgram\Common\Domain\Degree;
use Fau\DegreeProgram\Common\Domain\DegreeProgram;
Expand Down Expand Up @@ -75,6 +76,7 @@ private function __construct(
private MultilingualLink $studentInitiatives,
private MultilingualLink $applyNowLink,
private MultilingualString $entryText,
private CampoKeys $campoKeys,
) {
}

Expand Down Expand Up @@ -134,6 +136,7 @@ public static function fromDegreeProgram(DegreeProgram $degreeProgram): self
$data[DegreeProgram::STUDENT_INITIATIVES],
$data[DegreeProgram::APPLY_NOW_LINK],
$data[DegreeProgram::ENTRY_TEXT],
$data[DegreeProgram::CAMPO_KEYS],
);
}

Expand Down Expand Up @@ -198,6 +201,7 @@ public static function fromArray(array $data): self
),
applyNowLink: MultilingualLink::fromArray($data[DegreeProgram::APPLY_NOW_LINK]),
entryText: MultilingualString::fromArray($data[DegreeProgram::ENTRY_TEXT]),
campoKeys: CampoKeys::fromArray($data[DegreeProgram::CAMPO_KEYS]),
);
}

Expand Down Expand Up @@ -261,6 +265,7 @@ public function asArray(): array
DegreeProgram::STUDENT_INITIATIVES => $this->studentInitiatives->asArray(),
DegreeProgram::APPLY_NOW_LINK => $this->applyNowLink->asArray(),
DegreeProgram::ENTRY_TEXT => $this->entryText->asArray(),
DegreeProgram::CAMPO_KEYS => $this->campoKeys->asArray(),
];
}

Expand Down Expand Up @@ -513,4 +518,9 @@ public function entryText(): MultilingualString
{
return $this->entryText;
}

public function campoKeys(): CampoKeys
{
return $this->campoKeys;
}
}
12 changes: 12 additions & 0 deletions src/Application/DegreeProgramViewTranslated.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Fau\DegreeProgram\Common\Application;

use Fau\DegreeProgram\Common\Domain\CampoKeys;
use Fau\DegreeProgram\Common\Domain\DegreeProgram;
use Fau\DegreeProgram\Common\Domain\DegreeProgramId;
use Fau\DegreeProgram\Common\Domain\MultilingualString;
Expand All @@ -21,6 +22,7 @@
* @psalm-import-type LanguageCodes from MultilingualString
* @psalm-import-type ImageViewType from ImageView
* @psalm-import-type NumberOfStudentsType from NumberOfStudents
* @psalm-import-type CampoKeysMap from CampoKeys
* @psalm-type DegreeProgramTranslation = array{
* link: string,
* slug: string,
Expand Down Expand Up @@ -73,6 +75,7 @@
* student_initiatives: LinkType,
* apply_now_link: LinkType,
* entry_text: string,
* campo_keys: CampoKeysMap
* }
* @psalm-type DegreeProgramViewTranslatedArrayType = DegreeProgramTranslation & array{
* id: int,
Expand Down Expand Up @@ -145,6 +148,7 @@ public function __construct(
private Link $studentInitiatives,
private Link $applyNowLink,
private string $entryText,
private CampoKeys $campoKeys,
) {
}

Expand Down Expand Up @@ -209,6 +213,7 @@ public static function empty(int $id, string $languageCode): self
studentInitiatives: Link::empty(),
applyNowLink: Link::empty(),
entryText: '',
campoKeys: CampoKeys::empty(),
);
}

Expand Down Expand Up @@ -277,6 +282,7 @@ public static function fromArray(array $data): self
studentInitiatives: Link::fromArray($data[DegreeProgram::STUDENT_INITIATIVES]),
applyNowLink: Link::fromArray($data[DegreeProgram::APPLY_NOW_LINK]),
entryText: $data[DegreeProgram::ENTRY_TEXT],
campoKeys: CampoKeys::fromArray($data[DegreeProgram::CAMPO_KEYS]),
);

if (empty($data[self::TRANSLATIONS])) {
Expand Down Expand Up @@ -350,6 +356,7 @@ public function asArray(): array
DegreeProgram::STUDENT_INITIATIVES => $this->studentInitiatives->asArray(),
DegreeProgram::APPLY_NOW_LINK => $this->applyNowLink->asArray(),
DegreeProgram::ENTRY_TEXT => $this->entryText,
DegreeProgram::CAMPO_KEYS => $this->campoKeys->asArray(),
self::TRANSLATIONS => $this->translationsAsArray(),
];
}
Expand Down Expand Up @@ -669,4 +676,9 @@ public function entryText(): string
{
return $this->entryText;
}

public function campoKeys(): CampoKeys
{
return $this->campoKeys;
}
}
25 changes: 25 additions & 0 deletions src/Application/Repository/CollectionCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* include?: array<int>,
* search?: string,
* order_by: OrderBy,
* his_codes?: array<string>
* }
*/
final class CollectionCriteria
Expand All @@ -36,6 +37,11 @@ final class CollectionCriteria
*/
private array $filters = [];

/**
* @var array<string>
*/
private array $hisCodes = [];

/**
* @var LanguageCodes|null
*/
Expand Down Expand Up @@ -170,6 +176,17 @@ public function withOrderBy(array $orderBy): self
return $instance;
}

/**
* @param array<string> $hisCodes
* @return self
*/
public function withHisCodes(array $hisCodes): self
{
$instance = clone $this;
$instance->hisCodes = $hisCodes;
return $instance;
}

/**
* @psalm-return SupportedArgs
*/
Expand All @@ -185,4 +202,12 @@ public function filters(): array
{
return $this->filters;
}

/**
* @return array<string>
*/
public function hisCodes(): array
{
return $this->hisCodes;
}
}
90 changes: 90 additions & 0 deletions src/Domain/CampoKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

namespace Fau\DegreeProgram\Common\Domain;

/**
* @psalm-type CampoKeysMap = array<value-of<self::SUPPORTED_CAMPO_KEYS>, string>
*/
final class CampoKeys
{
public const SCHEMA = [
'type' => 'object',
'properties' => [
DegreeProgram::DEGREE => [
'type' => 'string',
],
DegreeProgram::AREA_OF_STUDY => [
'type' => 'string',
],
DegreeProgram::LOCATION => [
'type' => 'string',
],
],
];

public const SCHEMA_REQUIRED = [
'type' => 'object',
'properties' => [
DegreeProgram::DEGREE => [
'type' => 'string',
],
DegreeProgram::AREA_OF_STUDY => [
'type' => 'string',
],
DegreeProgram::LOCATION => [
'type' => 'string',
],
],
];

public const SUPPORTED_CAMPO_KEYS = [
DegreeProgram::DEGREE,
DegreeProgram::AREA_OF_STUDY,
DegreeProgram::LOCATION,
];

private const HIS_CODE_DELIMITER = '|';

private function __construct(
/**
* @var CampoKeysMap $map
*/
private array $map
) {
}

public static function empty(): self
{
return new self([]);
}

/**
* @param CampoKeysMap $map
*/
public static function fromArray(array $map): self
{
return new self($map);
}

public static function fromHisCode(string $hisCode): self
{
$parts = explode(self::HIS_CODE_DELIMITER, $hisCode);
$map = [
DegreeProgram::DEGREE => $parts[0] ?? null,
DegreeProgram::AREA_OF_STUDY => $parts[1] ?? null,
DegreeProgram::LOCATION => $parts[6] ?? null,
];

return new self(array_filter($map, fn($value) => !is_null($value)));
}

/**
* @return CampoKeysMap
*/
public function asArray(): array
{
return $this->map;
}
}
10 changes: 10 additions & 0 deletions src/Domain/DegreeProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @psalm-import-type AdmissionRequirementsType from AdmissionRequirements
* @psalm-import-type DegreeType from Degree
* @psalm-import-type NumberOfStudentsType from NumberOfStudents
* @psalm-import-type CampoKeysMap from CampoKeys
* @psalm-type DegreeProgramArrayType = array{
* id: int,
* slug: MultilingualStringType,
Expand Down Expand Up @@ -67,6 +68,7 @@
* student_initiatives: MultilingualLinkType,
* apply_now_link: MultilingualLinkType,
* entry_text: MultilingualStringType,
* campo_keys: CampoKeysMap,
* }
*/
final class DegreeProgram
Expand Down Expand Up @@ -122,6 +124,7 @@ final class DegreeProgram
public const NOTES_FOR_INTERNATIONAL_APPLICANTS = 'notes_for_international_applicants';
public const STUDENT_INITIATIVES = 'student_initiatives';
public const APPLY_NOW_LINK = 'apply_now_link';
public const CAMPO_KEYS = 'campo_keys';

private IntegersListChangeset $combinationsChangeset;
private IntegersListChangeset $limitedCombinationsChangeset;
Expand Down Expand Up @@ -315,6 +318,10 @@ public function __construct(
* Eingeschränkt Kombinationsmöglichkeiten
*/
private DegreeProgramIds $limitedCombinations,
/**
* CampoKeys
*/
private CampoKeys $campoKeys,
) {

$this->combinationsChangeset = IntegersListChangeset::new(
Expand Down Expand Up @@ -451,6 +458,7 @@ private function update(array $data): void
$this->studentInitiatives = MultilingualLink::fromArray($data[self::STUDENT_INITIATIVES]);
$this->applyNowLink = MultilingualLink::fromArray($data[self::APPLY_NOW_LINK]);
$this->entryText = MultilingualString::fromArray($data[self::ENTRY_TEXT]);
$this->campoKeys = CampoKeys::fromArray($data[self::CAMPO_KEYS]);

$this->combinationsChangeset = $this
->combinationsChangeset
Expand Down Expand Up @@ -515,6 +523,7 @@ private function update(array $data): void
* student_initiatives: MultilingualLink,
* apply_now_link: MultilingualLink,
* entry_text: MultilingualString,
* campo_keys: CampoKeys,
* }
* @internal Only for repositories usage
* phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
Expand Down Expand Up @@ -574,6 +583,7 @@ public function asArray(): array
self::STUDENT_INITIATIVES => $this->studentInitiatives,
self::APPLY_NOW_LINK => $this->applyNowLink,
self::ENTRY_TEXT => $this->entryText,
self::CAMPO_KEYS => $this->campoKeys,
];
}

Expand Down
Loading

0 comments on commit 8294700

Please sign in to comment.