Mache den Aufbau von Modulen und Programmen im Arbeitsplatz bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
30833f62a1
commit
a7feef2cd2
15 files changed
+2068
-328
No files matched your search
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
class EditorialDesk extends Page
|
||||
{
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Arbeitsplatz';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
protected static ?string $slug = 'arbeitsplatz';
|
||||
|
||||
protected static ?string $title = 'Arbeitsplatz';
|
||||
|
||||
protected string $view = 'filament.editorial.desk-page';
|
||||
|
||||
#[Url]
|
||||
public string $query = '';
|
||||
|
||||
#[Url]
|
||||
public string $kindFilter = 'alle';
|
||||
|
||||
public string $programName = '';
|
||||
|
||||
public string $moduleName = '';
|
||||
|
||||
public string $feedback = '';
|
||||
|
||||
public function getHeading(): string|Htmlable|null
|
||||
{
|
||||
return 'Programme und Module';
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Vorhandene Einträge öffnen oder einen neuen anlegen. Technische Kennungen sind dafür nicht nötig.';
|
||||
}
|
||||
|
||||
public function getMaxContentWidth(): Width|string|null
|
||||
{
|
||||
return Width::Full;
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return ContentElementResource::editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{title: string, kind: string, stand: string, url: string, summary: string}>
|
||||
*/
|
||||
public function entries(): array
|
||||
{
|
||||
$query = trim($this->query);
|
||||
$needle = mb_strtolower($query);
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
$rows = [];
|
||||
|
||||
$compositions = Composition::query()
|
||||
->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung])
|
||||
->with(['editorialContentKind', 'versions'])
|
||||
->orderBy('designation')
|
||||
->get();
|
||||
|
||||
foreach ($compositions as $composition) {
|
||||
$kind = $composition->kind instanceof CompositionKind
|
||||
? $composition->kind
|
||||
: CompositionKind::from((string) $composition->kind);
|
||||
$label = $kind->deskLabel();
|
||||
|
||||
if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->kindFilter === 'modul' && $kind !== CompositionKind::Uebung) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $catalog->compositionTitle($composition);
|
||||
$haystack = mb_strtolower($title.' '.$composition->designation.' '.(string) $composition->summary);
|
||||
|
||||
if ($needle !== '' && ! str_contains($haystack, $needle)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'title' => $title,
|
||||
'kind' => $label,
|
||||
'stand' => $catalog->stand($composition)['text'],
|
||||
'url' => EditorialCatalog::editUrl($composition),
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function createProgram(): void
|
||||
{
|
||||
$this->create(CompositionKind::Kurs, $this->programName);
|
||||
}
|
||||
|
||||
public function createModule(): void
|
||||
{
|
||||
$this->create(CompositionKind::Uebung, $this->moduleName);
|
||||
}
|
||||
|
||||
private function create(CompositionKind $kind, string $name): void
|
||||
{
|
||||
$name = trim($name);
|
||||
|
||||
if ($name === '') {
|
||||
$this->feedback = 'Der Name fehlt.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$composition = app(EditorialCatalog::class)->create($name, $kind);
|
||||
$this->redirect(EditorialCatalog::editUrl($composition), navigate: false);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
@@ -41,13 +42,20 @@ public static function form(Schema $schema): Schema
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([
|
||||
TextColumn::make('designation')->label('Bezeichnung')->searchable(),
|
||||
TextColumn::make('designation')
|
||||
->label('Name')
|
||||
->formatStateUsing(fn (Composition $record): string => app(EditorialCatalog::class)->compositionTitle($record))
|
||||
->description(fn (Composition $record): ?string => filled($record->display_title) && $record->display_title !== $record->designation ? $record->designation : null)
|
||||
->searchable(['designation', 'display_title', 'summary']),
|
||||
TextColumn::make('stand')
|
||||
->label('Stand')
|
||||
->state(fn (Composition $record): string => app(EditorialCatalog::class)->stand($record)['text']),
|
||||
TextColumn::make('versions_count')->counts('versions')->label('Fassungen'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->where('kind', static::kind());
|
||||
return parent::getEloquentQuery()->where('kind', static::kind())->with('versions');
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -20,7 +20,11 @@ abstract protected function kind(): CompositionKind;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return $this->kind()->deskExplanation();
|
||||
$desk = in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true)
|
||||
? ' Programme und Module liegen gemeinsam auf dem Arbeitsplatz.'
|
||||
: '';
|
||||
|
||||
return $this->kind()->deskExplanation().$desk;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
<?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\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
|
||||
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,
|
||||
'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,
|
||||
'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 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));
|
||||
|
||||
if (! $latest instanceof CompositionVersion) {
|
||||
return [
|
||||
'text' => 'Noch ohne Fassung',
|
||||
'number' => null,
|
||||
'released_number' => $released instanceof CompositionVersion ? $released->number : null,
|
||||
];
|
||||
}
|
||||
|
||||
$text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht freigegeben');
|
||||
|
||||
if ($released instanceof CompositionVersion && $released->number !== $latest->number) {
|
||||
$text .= '. Angezeigt wird Fassung '.$released->number;
|
||||
}
|
||||
|
||||
return [
|
||||
'text' => $text,
|
||||
'number' => $latest->number,
|
||||
'released_number' => $released instanceof CompositionVersion ? $released->number : null,
|
||||
];
|
||||
}
|
||||
|
||||
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',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user