697 lines
24 KiB
PHP
697 lines
24 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use App\Domain\Catalog\ArticleRelease;
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\CompositionMember;
|
|
use App\Domain\Catalog\CompositionVersion;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\ContentVersionStatus;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Domain\Catalog\IdentityDimensionValue;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Domain\Catalog\OfferStatus;
|
|
use App\Filament\Resources\Combinations\CombinationResource;
|
|
use App\Filament\Resources\Courses\CourseResource;
|
|
use App\Filament\Resources\Exercises\ExerciseResource;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class EditorialCatalog
|
|
{
|
|
/**
|
|
* @return list<array<string, string|null>>
|
|
*/
|
|
public function rows(CompositionVersion $version, int $exceptCompositionId): array
|
|
{
|
|
$version->loadMissing([
|
|
'members.contentElementVersion.element.editorialContentKind',
|
|
'members.nestedCompositionVersion.composition.editorialContentKind',
|
|
]);
|
|
$rows = [];
|
|
|
|
foreach ($version->members as $member) {
|
|
$target = $member->content_element_version_id
|
|
? 'element:'.$member->content_element_version_id
|
|
: 'composition:'.$member->nested_composition_version_id;
|
|
$row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true);
|
|
|
|
if ($row === null) {
|
|
continue;
|
|
}
|
|
|
|
$row['role'] = $member->role;
|
|
$rows[] = $row;
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string|null>|null
|
|
*/
|
|
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false): ?array
|
|
{
|
|
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
|
return null;
|
|
}
|
|
|
|
if ($match[1] === 'element') {
|
|
$version = ContentElementVersion::query()
|
|
->with('element.editorialContentKind')
|
|
->find($match[2]);
|
|
|
|
if (! $version instanceof ContentElementVersion || $version->status !== ContentVersionStatus::Bereit) {
|
|
return null;
|
|
}
|
|
|
|
$element = $version->element;
|
|
$kind = $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class);
|
|
$title = filled($element->display_title) ? $element->display_title : $element->working_title;
|
|
|
|
return [
|
|
'target' => 'element:'.$version->id,
|
|
'title' => $title,
|
|
'kind' => $kind,
|
|
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
|
'tone' => $this->tone((string) $element->output_class, $kind),
|
|
'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path),
|
|
'version_label' => 'Fassung '.$version->number,
|
|
'identity' => 'medium:'.$element->id,
|
|
'open_url' => route('content.preview', $version),
|
|
'open_label' => 'Medium ansehen',
|
|
'edit_url' => null,
|
|
];
|
|
}
|
|
|
|
$version = CompositionVersion::query()
|
|
->with('composition.editorialContentKind')
|
|
->find($match[2]);
|
|
|
|
if (! $version instanceof CompositionVersion || $version->status !== ContentVersionStatus::Bereit) {
|
|
return null;
|
|
}
|
|
|
|
if (! $allowSelf && (int) $version->composition_id === $exceptCompositionId) {
|
|
return null;
|
|
}
|
|
|
|
$composition = $version->composition;
|
|
$kind = $composition->editorialContentKind?->label
|
|
?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung');
|
|
|
|
return [
|
|
'target' => 'composition:'.$version->id,
|
|
'title' => $this->compositionTitle($composition),
|
|
'kind' => $kind,
|
|
'summary' => (string) ($composition->summary ?? ''),
|
|
'tone' => $this->tone('', $kind),
|
|
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
|
'version_label' => 'Fassung '.$version->number,
|
|
'identity' => 'zusammenstellung:'.$composition->id,
|
|
'open_url' => null,
|
|
'open_label' => null,
|
|
'edit_url' => self::editUrl($composition),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return list<array<string, string|null>>
|
|
*/
|
|
public function search(string $query, string $scope, int $exceptCompositionId): array
|
|
{
|
|
$query = trim($query);
|
|
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
|
$limit = $scope === 'alles' ? 20 : 40;
|
|
$rows = [];
|
|
|
|
if ($scope !== 'module') {
|
|
$elements = ContentElementVersion::query()
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->with('element.editorialContentKind')
|
|
->whereHas('element', function ($builder) use ($query, $like): void {
|
|
if ($query === '') {
|
|
return;
|
|
}
|
|
|
|
$builder->where('working_title', 'like', $like)
|
|
->orWhere('display_title', 'like', $like)
|
|
->orWhere('summary', 'like', $like);
|
|
})
|
|
->orderByDesc('id')
|
|
->limit($limit)
|
|
->get();
|
|
|
|
foreach ($elements as $version) {
|
|
$row = $this->rowForTarget('element:'.$version->id, $exceptCompositionId);
|
|
|
|
if ($row !== null) {
|
|
$rows[] = $row;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($scope !== 'medien') {
|
|
$versions = CompositionVersion::query()
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->where('composition_id', '!=', $exceptCompositionId)
|
|
->with('composition.editorialContentKind')
|
|
->whereHas('composition', function ($builder) use ($scope, $query, $like): void {
|
|
if ($scope === 'module') {
|
|
$builder->where('kind', CompositionKind::Uebung);
|
|
}
|
|
|
|
if ($query === '') {
|
|
return;
|
|
}
|
|
|
|
$builder->where(function ($inner) use ($like): void {
|
|
$inner->where('designation', 'like', $like)
|
|
->orWhere('display_title', 'like', $like)
|
|
->orWhere('summary', 'like', $like);
|
|
});
|
|
})
|
|
->orderByDesc('id')
|
|
->limit($limit)
|
|
->get();
|
|
|
|
foreach ($versions as $version) {
|
|
$row = $this->rowForTarget('composition:'.$version->id, $exceptCompositionId);
|
|
|
|
if ($row !== null) {
|
|
$rows[] = $row;
|
|
}
|
|
}
|
|
}
|
|
|
|
return array_slice($rows, 0, 40);
|
|
}
|
|
|
|
/**
|
|
* @return array{items: list<array<string, string|null>>, more: bool}
|
|
*/
|
|
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId): array
|
|
{
|
|
$query = trim($query);
|
|
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
|
$limit = 48;
|
|
$rows = [];
|
|
$dimensionId = ctype_digit($dimension) ? (int) $dimension : 0;
|
|
|
|
if ($kind !== 'modul') {
|
|
$elements = ContentElementVersion::query()
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->with('element.editorialContentKind')
|
|
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
|
$this->constrainElement($builder, $query, $like, $kind, $dimensionId);
|
|
})
|
|
->orderByDesc('id')
|
|
->limit($limit + 1)
|
|
->get();
|
|
|
|
foreach ($elements as $version) {
|
|
$row = $this->rowForTarget('element:'.$version->id, $exceptCompositionId);
|
|
|
|
if ($row !== null) {
|
|
$rows[] = $row;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (in_array($kind, ['alle', 'modul'], true)) {
|
|
$versions = CompositionVersion::query()
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->where('composition_id', '!=', $exceptCompositionId)
|
|
->with('composition.editorialContentKind')
|
|
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
|
if ($kind === 'modul') {
|
|
$builder->where('kind', CompositionKind::Uebung);
|
|
}
|
|
|
|
if ($dimensionId > 0) {
|
|
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
|
|
}
|
|
|
|
if ($query === '') {
|
|
return;
|
|
}
|
|
|
|
$builder->where(function ($inner) use ($like): void {
|
|
$inner->where('designation', 'like', $like)
|
|
->orWhere('display_title', 'like', $like)
|
|
->orWhere('summary', 'like', $like);
|
|
});
|
|
})
|
|
->orderByDesc('id')
|
|
->limit($limit + 1)
|
|
->get();
|
|
|
|
foreach ($versions as $version) {
|
|
$row = $this->rowForTarget('composition:'.$version->id, $exceptCompositionId);
|
|
|
|
if ($row !== null) {
|
|
$rows[] = $row;
|
|
}
|
|
}
|
|
}
|
|
|
|
return [
|
|
'items' => array_slice($rows, 0, $limit),
|
|
'more' => count($rows) > $limit,
|
|
];
|
|
}
|
|
|
|
public function tone(string $outputClass, string $kindLabel): string
|
|
{
|
|
$value = mb_strtolower($outputClass.' '.$kindLabel);
|
|
|
|
return match (true) {
|
|
str_contains($value, 'film') => 'film',
|
|
str_contains($value, 'hör'), str_contains($value, 'audio') => 'audio',
|
|
str_contains($value, 'dokument'), str_contains($value, 'pdf') => 'dokument',
|
|
str_contains($value, 'modul'), str_contains($value, 'programm') => 'modul',
|
|
default => 'text',
|
|
};
|
|
}
|
|
|
|
public function cardUrl(string $kind, int $id, ?string $path): ?string
|
|
{
|
|
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
|
return null;
|
|
}
|
|
|
|
return route('editorial.card', ['kind' => $kind, 'subject' => $id]);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<ContentElement> $builder
|
|
*/
|
|
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId): void
|
|
{
|
|
$outputs = match ($kind) {
|
|
'film' => ['film'],
|
|
'text' => ['text'],
|
|
'dokument' => ['pdf', 'document'],
|
|
default => null,
|
|
};
|
|
|
|
if ($outputs !== null) {
|
|
$builder->whereIn('output_class', $outputs);
|
|
}
|
|
|
|
if ($dimensionId > 0) {
|
|
$builder->whereIn('id', $this->dimensionSubjectIds(ContentElement::class, $dimensionId));
|
|
}
|
|
|
|
if ($query === '') {
|
|
return;
|
|
}
|
|
|
|
$builder->where(function ($inner) use ($like): void {
|
|
$inner->where('working_title', 'like', $like)
|
|
->orWhere('display_title', 'like', $like)
|
|
->orWhere('summary', 'like', $like)
|
|
->orWhere('description', 'like', $like);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param class-string<Model> $class
|
|
* @return list<int>
|
|
*/
|
|
private function dimensionSubjectIds(string $class, int $dimensionId): array
|
|
{
|
|
return IdentityDimensionValue::query()
|
|
->where('subject_type', (new $class)->getMorphClass())
|
|
->where('editorial_dimension_value_id', $dimensionId)
|
|
->where('origin', 'direkt')
|
|
->pluck('subject_id')
|
|
->map(fn (mixed $id): int => (int) $id)
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @return list<array{target: string, label: string}>
|
|
*/
|
|
public function alternatives(string $identity, int $exceptCompositionId): array
|
|
{
|
|
if (preg_match('/^(medium|zusammenstellung):(\d+)$/', $identity, $match) !== 1) {
|
|
return [];
|
|
}
|
|
|
|
$options = [];
|
|
|
|
if ($match[1] === 'medium') {
|
|
$versions = ContentElementVersion::query()
|
|
->where('content_element_id', $match[2])
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->orderBy('number')
|
|
->get();
|
|
|
|
foreach ($versions as $version) {
|
|
$options[] = [
|
|
'target' => 'element:'.$version->id,
|
|
'label' => 'Fassung '.$version->number,
|
|
];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
if ((int) $match[2] === $exceptCompositionId) {
|
|
return [];
|
|
}
|
|
|
|
$versions = CompositionVersion::query()
|
|
->where('composition_id', $match[2])
|
|
->where('status', ContentVersionStatus::Bereit)
|
|
->orderBy('number')
|
|
->get();
|
|
|
|
foreach ($versions as $version) {
|
|
$options[] = [
|
|
'target' => 'composition:'.$version->id,
|
|
'label' => 'Fassung '.$version->number,
|
|
];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
public function defaultRole(string $kind): string
|
|
{
|
|
$kind = mb_strtolower($kind);
|
|
|
|
return match (true) {
|
|
str_contains($kind, 'film') => 'Film',
|
|
str_contains($kind, 'hör') || str_contains($kind, 'audio') => 'Hörstück',
|
|
str_contains($kind, 'modul') => 'Modul',
|
|
str_contains($kind, 'programm') => 'Programm',
|
|
str_contains($kind, 'text'), str_contains($kind, 'dokument'), str_contains($kind, 'merkblatt'), str_contains($kind, 'unterlage') => 'Unterlage',
|
|
default => 'Bestandteil',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public function usage(CompositionVersion $version): array
|
|
{
|
|
$lines = [];
|
|
$parents = CompositionMember::query()
|
|
->where('nested_composition_version_id', $version->id)
|
|
->with('compositionVersion.composition')
|
|
->get();
|
|
|
|
foreach ($parents as $member) {
|
|
$parent = $member->compositionVersion?->composition;
|
|
$name = $parent instanceof Composition ? $this->compositionTitle($parent) : 'Zusammenstellung';
|
|
$lines[] = $name.', Rolle '.$member->role;
|
|
}
|
|
|
|
$articles = ArticleRelease::query()
|
|
->where('root_composition_version_id', $version->id)
|
|
->with('article')
|
|
->get();
|
|
|
|
foreach ($articles as $release) {
|
|
$lines[] = 'Lizenzartikel '.$release->article->code.', Stand '.$release->number;
|
|
}
|
|
|
|
return $lines;
|
|
}
|
|
|
|
/**
|
|
* @return array{text: string, number: int|null, released_number: int|null}
|
|
*/
|
|
public function stand(Composition $composition): array
|
|
{
|
|
$ready = $composition->versions
|
|
->filter(fn (CompositionVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
|
->sortByDesc('number')
|
|
->values();
|
|
$latest = $ready->first();
|
|
$release = app(CompositionDisplayRelease::class);
|
|
$released = $ready->first(fn (CompositionVersion $version): bool => $release->isReleased($version));
|
|
|
|
$draft = is_array($composition->working_draft) && $composition->working_draft !== [];
|
|
|
|
if (! $latest instanceof CompositionVersion) {
|
|
return [
|
|
'text' => $draft ? 'Entwurf gespeichert' : 'Noch ohne Fassung',
|
|
'number' => null,
|
|
'released_number' => $released instanceof CompositionVersion ? $released->number : null,
|
|
];
|
|
}
|
|
|
|
$visible = $released instanceof CompositionVersion;
|
|
$text = 'Fassung '.$latest->number.($visible ? ', in der Mitgliederbibliothek' : ', nicht in der Mitgliederbibliothek');
|
|
$text = ($draft ? 'Entwurf gespeichert. ' : '').$text;
|
|
|
|
if ($visible && $released->number !== $latest->number) {
|
|
$text .= '. Angezeigt wird Fassung '.$released->number;
|
|
}
|
|
|
|
return [
|
|
'text' => $text,
|
|
'number' => $latest->number,
|
|
'released_number' => $visible ? $released->number : null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return list<array{label: string, tone: string}>
|
|
*/
|
|
public function statusChips(Composition $composition, bool $offered): array
|
|
{
|
|
$stand = $this->stand($composition);
|
|
$chips = [];
|
|
|
|
if ($stand['number'] === null) {
|
|
$chips[] = [
|
|
'label' => str_contains($stand['text'], 'Entwurf') ? 'Entwurf gespeichert' : 'Noch ohne Fassung',
|
|
'tone' => 'yellow',
|
|
];
|
|
} else {
|
|
$chips[] = ['label' => 'Fassung '.$stand['number'], 'tone' => 'ink'];
|
|
|
|
if (str_starts_with($stand['text'], 'Entwurf gespeichert')) {
|
|
$chips[] = ['label' => 'Entwurf offen', 'tone' => 'yellow'];
|
|
}
|
|
|
|
$chips[] = $stand['released_number'] !== null
|
|
? ['label' => 'In der Mitgliederbibliothek', 'tone' => 'pine']
|
|
: ['label' => 'Nicht in der Mitgliederbibliothek', 'tone' => 'quiet'];
|
|
|
|
if ($stand['released_number'] !== null && $stand['released_number'] !== $stand['number']) {
|
|
$chips[] = ['label' => 'Bibliothek zeigt Fassung '.$stand['released_number'], 'tone' => 'pine'];
|
|
}
|
|
}
|
|
|
|
$chips[] = ['label' => 'Nicht auf der Website', 'tone' => 'quiet'];
|
|
$chips[] = $offered
|
|
? ['label' => 'Angebot aktiv', 'tone' => 'pine']
|
|
: ['label' => 'Kein aktives Angebot', 'tone' => 'quiet'];
|
|
|
|
return $chips;
|
|
}
|
|
|
|
/**
|
|
* @return list<int>
|
|
*/
|
|
public function offeredCompositionIds(): array
|
|
{
|
|
$articleIds = DB::table('resolved_scopes')
|
|
->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id')
|
|
->where('offer_versions.status', OfferStatus::Aktiv->value)
|
|
->pluck('resolved_scopes.license_article_id');
|
|
|
|
if ($articleIds->isEmpty()) {
|
|
return [];
|
|
}
|
|
|
|
$releaseIds = LicenseArticle::query()
|
|
->whereIn('id', $articleIds)
|
|
->whereNotNull('current_release_id')
|
|
->pluck('current_release_id');
|
|
$versionIds = ArticleRelease::query()
|
|
->whereIn('id', $releaseIds)
|
|
->whereNotNull('root_composition_version_id')
|
|
->pluck('root_composition_version_id');
|
|
|
|
return CompositionVersion::query()
|
|
->whereIn('id', $versionIds)
|
|
->pluck('composition_id')
|
|
->map(fn (mixed $id): int => (int) $id)
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $members
|
|
* @return list<array{id: int, title: string, image: string}>
|
|
*/
|
|
public function filmPictures(array $members): array
|
|
{
|
|
$versionIds = [];
|
|
|
|
foreach ($members as $member) {
|
|
$target = (string) ($member['target'] ?? '');
|
|
|
|
if (preg_match('/^element:(\d+)$/', $target, $match) === 1) {
|
|
$versionIds[] = (int) $match[1];
|
|
}
|
|
}
|
|
|
|
if ($versionIds === []) {
|
|
return [];
|
|
}
|
|
|
|
$pictures = [];
|
|
|
|
foreach (ContentElementVersion::query()->with('element')->whereIn('id', $versionIds)->get() as $version) {
|
|
$element = $version->element;
|
|
|
|
if (! $element instanceof ContentElement || $element->output_class !== 'film') {
|
|
continue;
|
|
}
|
|
|
|
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path);
|
|
|
|
if ($image === null || isset($pictures[$element->id])) {
|
|
continue;
|
|
}
|
|
|
|
$pictures[$element->id] = [
|
|
'id' => $element->id,
|
|
'title' => filled($element->display_title) ? $element->display_title : $element->working_title,
|
|
'image' => $image,
|
|
];
|
|
}
|
|
|
|
return array_values($pictures);
|
|
}
|
|
|
|
/**
|
|
* @return list<array{id: int, title: string, image: string, kind: string}>
|
|
*/
|
|
public function mediaPictures(string $query): array
|
|
{
|
|
$query = trim($query);
|
|
|
|
if (mb_strlen($query) < 2) {
|
|
return [];
|
|
}
|
|
|
|
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
|
|
|
return ContentElement::query()
|
|
->where('thumbnail_path', 'like', 'vorschau/%')
|
|
->where(function ($builder) use ($like): void {
|
|
$builder->where('working_title', 'like', $like)
|
|
->orWhere('display_title', 'like', $like)
|
|
->orWhere('summary', 'like', $like);
|
|
})
|
|
->orderBy('working_title')
|
|
->limit(12)
|
|
->get()
|
|
->map(function (ContentElement $element): ?array {
|
|
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path);
|
|
|
|
if ($image === null) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'id' => $element->id,
|
|
'title' => filled($element->display_title) ? $element->display_title : $element->working_title,
|
|
'image' => $image,
|
|
'kind' => $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class),
|
|
];
|
|
})
|
|
->filter()
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $members
|
|
* @return array{url: ?string, note: ?string, own: bool}
|
|
*/
|
|
public function cover(Composition $composition, array $members): array
|
|
{
|
|
$own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path);
|
|
|
|
if ($own !== null) {
|
|
return ['url' => $own, 'note' => null, 'own' => true];
|
|
}
|
|
|
|
$films = $this->filmPictures($members);
|
|
|
|
if (count($films) === 1) {
|
|
return [
|
|
'url' => $films[0]['image'],
|
|
'note' => 'Vorschlag aus dem Film '.$films[0]['title'],
|
|
'own' => false,
|
|
];
|
|
}
|
|
|
|
return ['url' => null, 'note' => null, 'own' => false];
|
|
}
|
|
|
|
public function create(string $designation, CompositionKind $kind): Composition
|
|
{
|
|
$composition = app(ContentService::class)->createComposition($designation, $kind);
|
|
$slug = match ($kind) {
|
|
CompositionKind::Kurs => 'programm',
|
|
CompositionKind::Uebung => 'modul',
|
|
default => null,
|
|
};
|
|
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
|
|
|
|
if ($editorial !== null) {
|
|
$composition->editorial_content_kind_id = $editorial->id;
|
|
$composition->save();
|
|
}
|
|
|
|
return $composition;
|
|
}
|
|
|
|
public static function editUrl(Composition $composition): string
|
|
{
|
|
$kind = $composition->kind instanceof CompositionKind
|
|
? $composition->kind
|
|
: CompositionKind::from((string) $composition->kind);
|
|
$resource = match ($kind) {
|
|
CompositionKind::Kurs => CourseResource::class,
|
|
CompositionKind::Kombination => CombinationResource::class,
|
|
CompositionKind::Uebung => ExerciseResource::class,
|
|
};
|
|
|
|
return $resource::getUrl('edit', ['record' => $composition]);
|
|
}
|
|
|
|
public function compositionTitle(Composition $composition): string
|
|
{
|
|
return filled($composition->display_title) ? $composition->display_title : $composition->designation;
|
|
}
|
|
|
|
public function outputLabel(string $outputClass): string
|
|
{
|
|
return match ($outputClass) {
|
|
'film' => 'Film',
|
|
'audio' => 'Hörstück',
|
|
'bild' => 'Bild',
|
|
'document', 'pdf' => 'Dokument',
|
|
default => 'Text',
|
|
};
|
|
}
|
|
}
|