160 lines
5.1 KiB
PHP
160 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use App\Domain\Catalog\Bundle;
|
|
use App\Domain\Catalog\BundleStatus;
|
|
use App\Domain\Catalog\BundleVersion;
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\CompositionVersion;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\ContentVersionStatus;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Domain\Catalog\Offer;
|
|
use App\Domain\Catalog\RightsProfileVersion;
|
|
|
|
class CatalogOptions
|
|
{
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function elements(): array
|
|
{
|
|
return ContentElement::query()->orderBy('working_title')->pluck('working_title', 'id')->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function assignmentTargets(?int $exceptCompositionId = null): array
|
|
{
|
|
$media = [];
|
|
$structures = [];
|
|
|
|
foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element.editorialContentKind')->orderBy('id')->get() as $version) {
|
|
$media['element:'.$version->id] = self::elementLabel($version);
|
|
}
|
|
|
|
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
|
if ($exceptCompositionId !== null && (int) $version->composition_id === $exceptCompositionId) {
|
|
continue;
|
|
}
|
|
|
|
$structures['composition:'.$version->id] = self::compositionLabel($version);
|
|
}
|
|
|
|
return array_filter([
|
|
'Medien und Dokumente' => $media,
|
|
'Module und Programme' => $structures,
|
|
]);
|
|
}
|
|
|
|
public static function elementLabel(ContentElementVersion $version): string
|
|
{
|
|
$kind = $version->element->editorialContentKind?->label;
|
|
$kind = $kind ?: self::outputLabel((string) $version->element->output_class);
|
|
|
|
return $version->element->working_title.', '.$kind.', Fassung '.$version->number;
|
|
}
|
|
|
|
public static function compositionLabel(CompositionVersion $version): string
|
|
{
|
|
$editorial = $version->composition->editorialContentKind?->label;
|
|
$technical = $version->composition->kind;
|
|
$kind = $editorial ?: ($technical instanceof CompositionKind ? $technical->label() : 'Zusammenstellung');
|
|
$title = filled($version->composition->display_title)
|
|
? $version->composition->display_title
|
|
: $version->composition->designation;
|
|
|
|
return $title.', '.$kind.', Fassung '.$version->number;
|
|
}
|
|
|
|
private static function outputLabel(string $outputClass): string
|
|
{
|
|
return match ($outputClass) {
|
|
'film' => 'Film',
|
|
'audio' => 'Hörstück',
|
|
'bild' => 'Bild',
|
|
'document', 'pdf' => 'Dokument',
|
|
'text' => 'Text',
|
|
default => 'Medium',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function readyTargets(): array
|
|
{
|
|
$options = [];
|
|
|
|
foreach (ContentElementVersion::query()->where('status', ContentVersionStatus::Bereit)->with('element.editorialContentKind')->orderBy('id')->get() as $version) {
|
|
$options['element:'.$version->id] = self::elementLabel($version);
|
|
}
|
|
|
|
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
|
$options['composition:'.$version->id] = self::compositionLabel($version);
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function compositions(): array
|
|
{
|
|
return Composition::query()->orderBy('designation')->pluck('designation', 'id')->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function articles(): array
|
|
{
|
|
return LicenseArticle::query()->orderBy('code')->pluck('code', 'id')->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function bundles(): array
|
|
{
|
|
return Bundle::query()->orderBy('name')->pluck('name', 'id')->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function bundleVersions(): array
|
|
{
|
|
return BundleVersion::query()
|
|
->where('status', BundleStatus::Veroeffentlicht)
|
|
->with('bundle')
|
|
->orderBy('id')
|
|
->get()
|
|
->mapWithKeys(fn (BundleVersion $version): array => [$version->id => $version->bundle->name.' · Fassung '.$version->number])
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function rights(): array
|
|
{
|
|
return RightsProfileVersion::query()->with('profile')->orderBy('id')->get()
|
|
->mapWithKeys(fn (RightsProfileVersion $version): array => [$version->id => $version->profile->name.' · '.$version->purpose])
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function offers(): array
|
|
{
|
|
return Offer::query()->orderBy('name')->pluck('name', 'id')->all();
|
|
}
|
|
}
|