Skip to content

Commit

Permalink
feat: add campo keys to degree program
Browse files Browse the repository at this point in the history
  • Loading branch information
amiut committed May 15, 2024
1 parent 58c96a8 commit 0ec4447
Show file tree
Hide file tree
Showing 15 changed files with 343 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] ?? []), // TODO: check to see why undefined value is possible. It gives fatal on revision repository due to null value.
);
}

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;
}
}
11 changes: 11 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 Down Expand Up @@ -73,6 +74,7 @@
* student_initiatives: LinkType,
* apply_now_link: LinkType,
* entry_text: string,
* campo_keys: array<string, string>
* }
* @psalm-type DegreeProgramViewTranslatedArrayType = DegreeProgramTranslation & array{
* id: int,
Expand Down Expand Up @@ -145,6 +147,7 @@ public function __construct(
private Link $studentInitiatives,
private Link $applyNowLink,
private string $entryText,
private CampoKeys $campoKeys,
) {
}

Expand Down Expand Up @@ -209,6 +212,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 +281,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 +355,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 +675,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;
}
}
133 changes: 133 additions & 0 deletions src/Domain/CampoKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

declare(strict_types=1);

namespace Fau\DegreeProgram\Common\Domain;

use InvalidArgumentException;

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 = '|';

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

private function __construct()
{
}

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

/**
* @psalm-param array<string, string> $data
*/
public static function fromArray(array $data): self
{
$instance = new self();

foreach ($data as $key => $value) {
$instance->set($key, $value);
}

return $instance;
}

public static function fromHisCode(string $hisCode): self
{
$parts = explode(self::HIS_CODE_DELIMITER, $hisCode);

$instance = new self();

if (isset($parts[0])) {
$instance->set(DegreeProgram::DEGREE, $parts[0]);
}

if (isset($parts[1])) {
$instance->set(DegreeProgram::AREA_OF_STUDY, $parts[1]);
}

if (isset($parts[6])) {
$instance->set(DegreeProgram::LOCATION, $parts[6]);
}

return $instance;
}

public function set(string $key, string $value): self
{
if (! in_array($key, self::SUPPORTED_CAMPO_KEYS)) {

Check warning on line 98 in src/Domain/CampoKeys.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Not using strict comparison for in_array; supply true for third argument.
throw new InvalidArgumentException('Unsupported field key.');
}

$this->map[$key] = $value;
return $this;
}

public function degree(): ?string
{
return $this->get(DegreeProgram::DEGREE);
}

public function areaOfStudy(): ?string
{
return $this->get(DegreeProgram::AREA_OF_STUDY);
}

public function studyLocation(): ?string
{
return $this->get(DegreeProgram::LOCATION);
}

public function get(string $key): ?string
{
return $this->map[$key] ?? null;
}

/**
* @return array<string, string>
*/
public function asArray(): array
{
return $this->map;
}
}
9 changes: 9 additions & 0 deletions src/Domain/DegreeProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* student_initiatives: MultilingualLinkType,
* apply_now_link: MultilingualLinkType,
* entry_text: MultilingualStringType,
* campo_keys: array<string, string>,
* }
*/
final class DegreeProgram
Expand Down Expand Up @@ -122,6 +123,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 +317,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 +457,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 +522,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 +582,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 0ec4447

Please sign in to comment.