59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http;
|
|
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
|
|
class CourseOutline
|
|
{
|
|
public function title(LicenseArticle $article): string
|
|
{
|
|
$release = $article->currentRelease;
|
|
|
|
if ($release === null) {
|
|
return $article->code;
|
|
}
|
|
|
|
$release->loadMissing([
|
|
'rootCompositionVersion.composition',
|
|
'rootElementVersion.element',
|
|
]);
|
|
|
|
$composition = $release->rootCompositionVersion?->composition;
|
|
$element = $release->rootElementVersion?->element;
|
|
|
|
return (filled($composition?->display_title) ? $composition->display_title : null)
|
|
?? $composition?->designation
|
|
?? (filled($element?->display_title) ? $element->display_title : null)
|
|
?? $element?->working_title
|
|
?? $release->classification_note
|
|
?? $article->code;
|
|
}
|
|
|
|
public function kindLabel(LicenseArticle $article): ?string
|
|
{
|
|
$release = $article->currentRelease;
|
|
|
|
if ($release === null) {
|
|
return null;
|
|
}
|
|
|
|
$release->loadMissing([
|
|
'rootCompositionVersion.composition.editorialContentKind',
|
|
'rootElementVersion.element.editorialContentKind',
|
|
]);
|
|
|
|
$editorial = $release->rootCompositionVersion?->composition?->editorialContentKind?->label
|
|
?? $release->rootElementVersion?->element?->editorialContentKind?->label;
|
|
|
|
if ($editorial !== null) {
|
|
return $editorial;
|
|
}
|
|
|
|
$kind = $release->rootCompositionVersion?->composition?->kind;
|
|
|
|
return $kind instanceof CompositionKind ? $kind->label() : null;
|
|
}
|
|
}
|