Zeige Katalogkarten, Titelbilder und klare Freigabestatus im Arbeitsplatz.
Deploy Test / test (push) Successful in 23s
Deploy Test / deploy (push) Successful in 22s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 17:54:12 +01:00
1 parent 053a361801
commit 9195cdcd15
15 files changed
+795 -59

No files matched your search

+2
View File
@@ -12,8 +12,10 @@ class Composition extends Model
'designation',
'display_title',
'summary',
'description',
'thumbnail_path',
'thumbnail_alt',
'thumbnail_source',
'thumbnail_error',
'public_slug',
'kind',
+32 -1
View File
@@ -41,6 +41,21 @@ public function forCompositionUpload(Composition $composition, string $incoming)
}
$this->still($composition, Storage::disk('cms_incoming'), $incoming, 'komposition-'.$composition->id);
$this->rememberChoice($composition, 'eigen');
}
public function forCompositionFromElement(Composition $composition, ContentElement $element): void
{
$path = $element->thumbnail_path;
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
$this->failComposition($composition, 'Für dieses Medium liegt noch kein Vorschaubild vor.');
return;
}
$this->still($composition, Storage::disk('media_derived'), $path, 'komposition-'.$composition->id);
$this->rememberChoice($composition, 'element:'.$element->id);
}
private function frame(ContentElement $element, string $file): void
@@ -119,11 +134,27 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
$path = 'vorschau/'.$name.'.jpg';
Storage::disk('media_derived')->put($path, $bytes);
$subject->thumbnail_path = $path;
$subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title;
if (! ($subject instanceof Composition && filled($subject->thumbnail_alt))) {
$subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title;
}
$subject->thumbnail_error = null;
$subject->save();
}
private function rememberChoice(Composition $composition, string $source): void
{
$composition->refresh();
if ($composition->thumbnail_error !== null || ! filled($composition->thumbnail_path)) {
return;
}
$composition->thumbnail_source = $source;
$composition->save();
}
private function fail(ContentElement $element, string $reason): void
{
$this->failSubject($element, $reason);
+124 -7
View File
@@ -4,6 +4,9 @@
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\EditorialCatalog;
use Filament\Pages\Page;
@@ -31,6 +34,12 @@ class EditorialDesk extends Page
#[Url]
public string $kindFilter = 'alle';
#[Url]
public string $pillar = '';
#[Url]
public string $visibility = 'alle';
public string $programName = '';
public string $moduleName = '';
@@ -58,18 +67,55 @@ public static function canAccess(): bool
}
/**
* @return list<array{title: string, kind: string, stand: string, url: string, summary: string}>
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
*/
public function dimensionFilters(): array
{
$groups = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
$values = [];
foreach ($dimension->values as $value) {
$values[] = ['id' => $value->id, 'label' => $value->label];
}
if ($values !== []) {
$groups[] = ['label' => $dimension->label, 'values' => $values];
}
}
return $groups;
}
public function resetFilters(): void
{
$this->query = '';
$this->kindFilter = 'alle';
$this->pillar = '';
$this->visibility = 'alle';
}
public function hasActiveFilters(): bool
{
return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->visibility !== 'alle';
}
/**
* @return list<array<string, mixed>>
*/
public function entries(): array
{
$query = trim($this->query);
$needle = mb_strtolower($query);
$catalog = app(EditorialCatalog::class);
$offered = $catalog->offeredCompositionIds();
$pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar);
$rows = [];
$compositions = Composition::query()
->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung])
->with(['editorialContentKind', 'versions'])
->with(['editorialContentKind', 'versions.members.contentElementVersion.element'])
->orderBy('designation')
->get();
@@ -77,7 +123,6 @@ public function entries(): array
$kind = $composition->kind instanceof CompositionKind
? $composition->kind
: CompositionKind::from((string) $composition->kind);
$label = $kind->deskLabel();
if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) {
continue;
@@ -87,26 +132,98 @@ public function entries(): array
continue;
}
if ($pillarIds !== null && ! in_array($composition->id, $pillarIds, true)) {
continue;
}
$stand = $catalog->stand($composition);
if (! $this->matchesVisibility($stand)) {
continue;
}
$title = $catalog->compositionTitle($composition);
$haystack = mb_strtolower($title.' '.$composition->designation.' '.(string) $composition->summary);
$summary = (string) ($composition->summary ?? '');
$haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.(string) $composition->description);
if ($needle !== '' && ! str_contains($haystack, $needle)) {
continue;
}
$cover = $catalog->cover($composition, $this->coverMembers($composition));
$rows[] = [
'title' => $title,
'kind' => $label,
'kind' => $kind->deskLabel(),
'tone' => $kind === CompositionKind::Kurs ? 'programm' : 'modul',
'stand' => $catalog->stand($composition)['text'],
'summary' => $summary,
'url' => EditorialCatalog::editUrl($composition),
'summary' => (string) ($composition->summary ?? ''),
'image' => $cover['url'],
'image_note' => $cover['note'],
'chips' => $catalog->statusChips($composition, in_array($composition->id, $offered, true)),
];
}
return $rows;
}
/**
* @return list<array{target: string}>
*/
private function coverMembers(Composition $composition): array
{
$draft = $composition->working_draft;
if (is_array($draft) && is_array($draft['members'] ?? null) && $draft['members'] !== []) {
return $draft['members'];
}
$version = $composition->versions
->filter(fn ($item): bool => $item->status === ContentVersionStatus::Bereit)
->sortByDesc('number')
->first();
if ($version === null) {
return [];
}
$members = [];
foreach ($version->members as $member) {
$target = $member->content_element_version_id
? 'element:'.$member->content_element_version_id
: 'composition:'.$member->nested_composition_version_id;
$members[] = ['target' => $target];
}
return $members;
}
/**
* @return list<int>
*/
private function pillarSubjects(int $valueId): array
{
return IdentityDimensionValue::query()
->where('subject_type', (new Composition)->getMorphClass())
->where('editorial_dimension_value_id', $valueId)
->pluck('subject_id')
->map(fn (mixed $id): int => (int) $id)
->all();
}
/**
* @param array{text: string, number: int|null, released_number: int|null} $stand
*/
private function matchesVisibility(array $stand): bool
{
return match ($this->visibility) {
'bibliothek' => $stand['released_number'] !== null,
'verborgen' => $stand['number'] !== null && $stand['released_number'] === null,
'entwurf' => $stand['number'] === null,
default => true,
};
}
public function createProgram(): void
{
$this->create(CompositionKind::Kurs, $this->programName);
@@ -7,6 +7,7 @@
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionStructureReader;
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;
@@ -42,6 +43,8 @@ abstract class EditComposition extends EditRecord
public string $summary = '';
public string $description = '';
public string $learningGoal = '';
public string $durationMinutes = '';
@@ -92,8 +95,12 @@ abstract class EditComposition extends EditRecord
public ?string $thumbnailPath = null;
public string $thumbnailAlt = '';
public ?string $thumbnailError = null;
public string $imageQuery = '';
/** @var list<array<string, string|null>> */
public array $members = [];
@@ -150,10 +157,10 @@ protected function getHeaderActions(): array
->openUrlInNewTab()
->visible(fn (): bool => $this->previewUrl() !== null),
Action::make('displayRelease')
->label('Zur Anzeige freigeben')
->label('In Mitgliederbibliothek anzeigen')
->requiresConfirmation()
->modalHeading('Diese Fassung zur Anzeige freigeben')
->modalDescription('Freigegeben wird die zuletzt übernommene Fassung. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.')
->modalHeading('In der Mitgliederbibliothek anzeigen')
->modalDescription('Sichtbar wird die zuletzt übernommene Fassung. Das ist keine Website-Veröffentlichung und kein aktives Angebot. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.')
->visible(function (): bool {
$version = $this->currentReadyVersion();
@@ -163,10 +170,10 @@ protected function getHeaderActions(): array
$this->releaseDisplay();
}),
Action::make('displayRevoke')
->label('Anzeige zurücknehmen')
->label('Aus Mitgliederbibliothek ausblenden')
->color('danger')
->requiresConfirmation()
->modalDescription('Nur die Anzeige dieser Fassung wird zurückgenommen. Der Inhalt der Fassung bleibt gespeichert.')
->modalDescription('Die Fassung verschwindet aus der Mitgliederbibliothek. Der fachliche Inhalt bleibt gespeichert. Website und Angebot sind davon unabhängig.')
->visible(function (): bool {
$version = $this->currentReadyVersion();
@@ -177,7 +184,7 @@ protected function getHeaderActions(): array
$actor = $this->actor();
abort_unless($version !== null && $actor instanceof User, 403);
app(CompositionDisplayRelease::class)->revoke($version, $actor);
$this->feedback = 'Die Anzeige dieser Fassung ist zurückgenommen. Der Inhalt bleibt gespeichert.';
$this->feedback = 'Die Fassung ist aus der Mitgliederbibliothek ausgeblendet. Der Inhalt bleibt gespeichert.';
}),
];
}
@@ -370,8 +377,8 @@ public function editorStatus(): string
$display = $version === null
? ''
: (app(CompositionDisplayRelease::class)->isReleased($version)
? ' Sie ist zur Anzeige freigegeben.'
: ' Sie ist noch nicht zur Anzeige freigegeben.');
? ' Sie ist in der Mitgliederbibliothek sichtbar.'
: ' Sie ist nicht in der Mitgliederbibliothek.');
$unsaved = $stored === null
? $current !== $ready
: $current !== $this->fingerprint($stored);
@@ -453,7 +460,7 @@ public function versionChoices(): array
$rows[] = [
'id' => $version->id,
'number' => $version->number,
'text' => 'Fassung '.$version->number.($released ? ', zur Anzeige freigegeben' : ''),
'text' => 'Fassung '.$version->number.($released ? ', in der Mitgliederbibliothek' : ', nicht in der Mitgliederbibliothek'),
'current' => $latest !== null && $latest->id === $version->id,
];
}
@@ -734,6 +741,8 @@ public function saveDisplay(): void
app(IdentityProfile::class)->fill($record, [
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'thumbnail_alt' => $this->thumbnailAlt,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$record->refresh();
@@ -778,6 +787,82 @@ public function savePreviewImage(string $storedPath): void
$this->storePreview($storedPath);
}
public function adoptPicture(int $elementId): void
{
$element = ContentElement::query()->find($elementId);
$path = $element?->thumbnail_path;
if (! $element instanceof ContentElement || ! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
$this->feedback = 'Für dieses Medium liegt noch kein Vorschaubild vor.';
return;
}
/** @var Composition $record */
$record = $this->getRecord();
$before = $record->versions()->count();
DeriveThumbnail::dispatch('komposition', $record->id, null, $element->id);
$record->refresh();
$this->thumbnailPath = $record->thumbnail_path;
$this->thumbnailError = $record->thumbnail_error;
$this->feedback = $this->previewFeedback($record, $before);
}
/**
* @return array{url: ?string, note: ?string, own: bool}
*/
public function coverPicture(): array
{
/** @var Composition $composition */
$composition = $this->getRecord();
return app(EditorialCatalog::class)->cover($composition, $this->members);
}
/**
* @return list<array{id: int, title: string, image: string}>
*/
public function filmChoices(): array
{
$films = app(EditorialCatalog::class)->filmPictures($this->members);
return count($films) > 1 ? $films : [];
}
/**
* @return array{id: int, title: string, image: string}|null
*/
public function suggestedFilm(): ?array
{
if (filled($this->thumbnailPath)) {
return null;
}
$films = app(EditorialCatalog::class)->filmPictures($this->members);
return count($films) === 1 ? $films[0] : null;
}
/**
* @return list<array{id: int, title: string, image: string, kind: string}>
*/
public function mediaChoices(): array
{
return app(EditorialCatalog::class)->mediaPictures($this->imageQuery);
}
/**
* @return list<array{label: string, tone: string}>
*/
public function presentationChips(): array
{
/** @var Composition $composition */
$composition = $this->getRecord();
$offered = in_array($composition->id, app(EditorialCatalog::class)->offeredCompositionIds(), true);
return app(EditorialCatalog::class)->statusChips($composition, $offered);
}
public function publishRevision(): bool
{
$this->commitRoleDraft();
@@ -910,7 +995,9 @@ protected function loadEditor(): void
$this->designation = $composition->designation;
$this->displayTitle = (string) ($composition->display_title ?? '');
$this->summary = (string) ($composition->summary ?? '');
$this->description = (string) ($composition->description ?? '');
$this->thumbnailPath = $composition->thumbnail_path;
$this->thumbnailAlt = (string) ($composition->thumbnail_alt ?? '');
$this->thumbnailError = $composition->thumbnail_error;
$this->dimensionIds = IdentityDimensionValue::query()
->where('subject_type', $composition->getMorphClass())
@@ -1034,7 +1121,7 @@ protected function releaseCurrent(): void
}
app(CompositionDisplayRelease::class)->release($version, $actor);
$this->feedback = 'Fassung '.$version->number.' ist zur Anzeige freigegeben. Frühere Fassungen bleiben erhalten.';
$this->feedback = 'Fassung '.$version->number.' ist in der Mitgliederbibliothek sichtbar. Frühere Fassungen bleiben erhalten.';
}
protected function currentReadyVersion(): ?CompositionVersion
@@ -1156,9 +1243,24 @@ protected function storePreview(string $path): void
$record->refresh();
$this->thumbnailPath = $record->thumbnail_path;
$this->thumbnailError = $record->thumbnail_error;
$this->feedback = $record->versions()->count() === $before && filled($record->thumbnail_path)
? 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.'
: ($record->thumbnail_error ?: 'Das Vorschaubild wurde nicht übernommen.');
$this->feedback = $this->previewFeedback($record, $before);
}
protected function previewFeedback(Composition $record, int $versionsBefore): string
{
if ($record->versions()->count() !== $versionsBefore) {
return 'Das Vorschaubild wurde nicht übernommen.';
}
if (filled($record->thumbnail_path) && $record->thumbnail_error === null) {
return 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
}
if (config('queue.default') !== 'sync') {
return 'Das Titelbild wird vorbereitet. Die Fassung bleibt unverändert.';
}
return $record->thumbnail_error ?: 'Das Vorschaubild wurde nicht übernommen.';
}
protected function statusSentence(): string
+188 -3
View File
@@ -14,11 +14,14 @@
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
{
@@ -447,20 +450,202 @@ public function stand(Composition $composition): array
];
}
$text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht zur Anzeige freigegeben');
$visible = $released instanceof CompositionVersion;
$text = 'Fassung '.$latest->number.($visible ? ', in der Mitgliederbibliothek' : ', nicht in der Mitgliederbibliothek');
$text = ($draft ? 'Entwurf gespeichert. ' : '').$text;
if ($released instanceof CompositionVersion && $released->number !== $latest->number) {
if ($visible && $released->number !== $latest->number) {
$text .= '. Angezeigt wird Fassung '.$released->number;
}
return [
'text' => $text,
'number' => $latest->number,
'released_number' => $released instanceof CompositionVersion ? $released->number : null,
'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);
@@ -133,6 +133,7 @@ private function render(
return view('filament.editorial.preview', [
'title' => $catalog->compositionTitle($composition),
'summary' => $composition->summary,
'description' => $composition->description,
'kind' => $composition->editorialContentKind?->label
?? ($composition->kind?->deskLabel()),
'learningGoal' => $learningGoal,
+16 -1
View File
@@ -16,6 +16,7 @@ public function __construct(
public readonly string $subject,
public readonly int $subjectId,
public readonly ?string $incoming = null,
public readonly ?int $fromElement = null,
) {}
public function handle(ThumbnailDeriver $deriver): void
@@ -23,7 +24,21 @@ public function handle(ThumbnailDeriver $deriver): void
if ($this->subject === 'komposition') {
$composition = Composition::query()->find($this->subjectId);
if ($composition !== null && is_string($this->incoming)) {
if ($composition === null) {
return;
}
if ($this->fromElement !== null) {
$element = ContentElement::query()->find($this->fromElement);
if ($element !== null) {
$deriver->forCompositionFromElement($composition, $element);
}
return;
}
if (is_string($this->incoming)) {
$deriver->forCompositionUpload($composition, $this->incoming);
}