Mache Auswahl, Aufbau und Entwurf im Redaktionseditor bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6955830579
commit
053a361801
14 files changed
+1040
-155
No files matched your search
@@ -19,6 +19,7 @@ class Composition extends Model
|
||||
'kind',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
'working_draft',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -26,6 +27,7 @@ protected function casts(): array
|
||||
return [
|
||||
'kind' => CompositionKind::class,
|
||||
'archived_at' => 'datetime',
|
||||
'working_draft' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
class EditorialWorkingDraft
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function read(Composition $composition): ?array
|
||||
{
|
||||
$draft = $composition->working_draft;
|
||||
|
||||
return is_array($draft) && $draft !== [] ? $draft : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function write(Composition $composition, array $payload): void
|
||||
{
|
||||
$composition->working_draft = $payload;
|
||||
$composition->save();
|
||||
}
|
||||
|
||||
public function clear(Composition $composition): void
|
||||
{
|
||||
if ($composition->working_draft === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$composition->working_draft = null;
|
||||
$composition->save();
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ public function entries(): array
|
||||
$rows[] = [
|
||||
'title' => $title,
|
||||
'kind' => $label,
|
||||
'tone' => $kind === CompositionKind::Kurs ? 'programm' : 'modul',
|
||||
'stand' => $catalog->stand($composition)['text'],
|
||||
'url' => EditorialCatalog::editUrl($composition),
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialDimensionValue;
|
||||
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -61,6 +62,20 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public string $panel = 'angaben';
|
||||
|
||||
public bool $pickerOpen = false;
|
||||
|
||||
public string $pickerQuery = '';
|
||||
|
||||
public string $pickerKind = 'alle';
|
||||
|
||||
public string $pickerDimension = '';
|
||||
|
||||
public string $pickerSelected = '';
|
||||
|
||||
public bool $textOpen = false;
|
||||
|
||||
public bool $releaseArmed = false;
|
||||
|
||||
public string $returnUrl = '';
|
||||
|
||||
public ?int $templateNumber = null;
|
||||
@@ -193,13 +208,20 @@ public function selfUrl(): string
|
||||
|
||||
public function previewUrl(): ?string
|
||||
{
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
|
||||
if (is_array($composition->working_draft) && $composition->working_draft !== []) {
|
||||
return route('editorial.draft-preview', ['composition' => $composition]);
|
||||
}
|
||||
|
||||
$version = $this->currentReadyVersion();
|
||||
|
||||
if ($version === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return route('editorial.preview', ['composition' => $this->getRecord(), 'version' => $version]);
|
||||
return route('editorial.preview', ['composition' => $composition, 'version' => $version]);
|
||||
}
|
||||
|
||||
public function previewUrlFor(int $versionId): ?string
|
||||
@@ -229,6 +251,188 @@ public function hits(): array
|
||||
);
|
||||
}
|
||||
|
||||
public function openPicker(): void
|
||||
{
|
||||
$this->pickerOpen = true;
|
||||
$this->textOpen = false;
|
||||
$this->pickerSelected = '';
|
||||
}
|
||||
|
||||
public function closePicker(): void
|
||||
{
|
||||
$this->pickerOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: list<array<string, string|null>>, more: bool}
|
||||
*/
|
||||
public function pickerResult(): array
|
||||
{
|
||||
if (! $this->pickerOpen) {
|
||||
return ['items' => [], 'more' => false];
|
||||
}
|
||||
|
||||
return app(EditorialCatalog::class)->browse(
|
||||
$this->pickerQuery,
|
||||
$this->pickerKind,
|
||||
$this->pickerDimension,
|
||||
(int) $this->getRecord()->getKey(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|null>|null
|
||||
*/
|
||||
public function pickerDetail(): ?array
|
||||
{
|
||||
if ($this->pickerSelected === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return app(EditorialCatalog::class)->rowForTarget(
|
||||
$this->pickerSelected,
|
||||
(int) $this->getRecord()->getKey(),
|
||||
);
|
||||
}
|
||||
|
||||
public function openText(): void
|
||||
{
|
||||
$this->pickerOpen = false;
|
||||
$this->textOpen = true;
|
||||
}
|
||||
|
||||
public function cancelText(): void
|
||||
{
|
||||
$this->textOpen = false;
|
||||
$this->newTextTitle = '';
|
||||
$this->newTextBody = '';
|
||||
}
|
||||
|
||||
public function saveDraft(): void
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
$minutes = $this->minutes($this->durationMinutes);
|
||||
|
||||
if ($minutes === false) {
|
||||
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Composition $record */
|
||||
$record = $this->getRecord();
|
||||
app(EditorialWorkingDraft::class)->write($record, $this->payload());
|
||||
$this->feedback = 'Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
|
||||
}
|
||||
|
||||
public function armRelease(): void
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
|
||||
if ($this->members === []) {
|
||||
$this->releaseArmed = false;
|
||||
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Entwurf kannst du schon speichern.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->needsRevision()) {
|
||||
$this->releaseArmed = false;
|
||||
$this->feedback = 'Die freigegebene Fassung ist unverändert. Es entsteht keine neue Fassung.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->releaseArmed = true;
|
||||
}
|
||||
|
||||
public function cancelRelease(): void
|
||||
{
|
||||
$this->releaseArmed = false;
|
||||
}
|
||||
|
||||
public function discardDraft(): void
|
||||
{
|
||||
/** @var Composition $record */
|
||||
$record = $this->getRecord();
|
||||
app(EditorialWorkingDraft::class)->clear($record);
|
||||
$this->releaseArmed = false;
|
||||
$this->loadEditor();
|
||||
$this->feedback = 'Der Entwurf ist verworfen. Eine freigegebene Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
public function editorStatus(): string
|
||||
{
|
||||
$current = $this->fingerprint($this->payload());
|
||||
$stored = $this->storedPayload();
|
||||
$ready = $this->fingerprint($this->readyPayload());
|
||||
$version = $this->currentReadyVersion();
|
||||
$display = $version === null
|
||||
? ''
|
||||
: (app(CompositionDisplayRelease::class)->isReleased($version)
|
||||
? ' Sie ist zur Anzeige freigegeben.'
|
||||
: ' Sie ist noch nicht zur Anzeige freigegeben.');
|
||||
$unsaved = $stored === null
|
||||
? $current !== $ready
|
||||
: $current !== $this->fingerprint($stored);
|
||||
|
||||
if ($unsaved) {
|
||||
return 'Es gibt ungespeicherte Änderungen. Speichern hält den Entwurf fest und legt keine Fassung an.';
|
||||
}
|
||||
|
||||
if ($stored !== null && $this->fingerprint($stored) !== $ready) {
|
||||
return $version === null
|
||||
? 'Der Entwurf ist gespeichert. Noch keine freigegebene Fassung.'
|
||||
: 'Der Entwurf ist gespeichert. Fassung '.$version->number.' bleibt unverändert.'.$display;
|
||||
}
|
||||
|
||||
if ($version === null) {
|
||||
return 'Noch keine freigegebene Fassung. Speichern hält einen Entwurf fest.';
|
||||
}
|
||||
|
||||
return 'Fassung '.$version->number.' ist der letzte freigegebene Stand.'.$display.' Kein offener Entwurf.';
|
||||
}
|
||||
|
||||
public function includeNeedsRelease(): bool
|
||||
{
|
||||
return $this->needsRevision();
|
||||
}
|
||||
|
||||
public function moveTo(int $from, int $to): void
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
$count = count($this->members);
|
||||
|
||||
if (! isset($this->members[$from]) || $to < 0 || $to >= $count) {
|
||||
$this->feedback = 'An dieser Stelle kann der Bestandteil nicht abgelegt werden. Die Reihenfolge gilt nur innerhalb dieses Aufbaus.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($from === $to) {
|
||||
$this->feedback = 'Der Bestandteil bleibt an seiner Stelle.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$selectedTarget = $this->selected !== null ? ($this->members[$this->selected]['target'] ?? null) : null;
|
||||
$item = $this->members[$from];
|
||||
array_splice($this->members, $from, 1);
|
||||
array_splice($this->members, $to, 0, [$item]);
|
||||
$this->members = array_values($this->members);
|
||||
$this->selected = null;
|
||||
|
||||
foreach ($this->members as $index => $member) {
|
||||
if ($selectedTarget !== null && ($member['target'] ?? null) === $selectedTarget) {
|
||||
$this->selected = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->syncRoleDraft();
|
||||
$this->feedback = $item['title'].' steht jetzt an Stelle '.($to + 1).'. Gespeichert ist das erst mit „Entwurf speichern“.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{id: int, number: int, text: string, current: bool}>
|
||||
*/
|
||||
@@ -241,13 +445,15 @@ public function versionChoices(): array
|
||||
$rows = [];
|
||||
|
||||
foreach ($composition->versions()->orderByDesc('number')->get() as $version) {
|
||||
$released = $version->status === ContentVersionStatus::Bereit && $release->isReleased($version);
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$released = $release->isReleased($version);
|
||||
$rows[] = [
|
||||
'id' => $version->id,
|
||||
'number' => $version->number,
|
||||
'text' => 'Fassung '.$version->number
|
||||
.($version->status === ContentVersionStatus::Bereit ? '' : ', nicht bereit')
|
||||
.($released ? ', zur Anzeige freigegeben' : ''),
|
||||
'text' => 'Fassung '.$version->number.($released ? ', zur Anzeige freigegeben' : ''),
|
||||
'current' => $latest !== null && $latest->id === $version->id,
|
||||
];
|
||||
}
|
||||
@@ -348,7 +554,7 @@ public function publishHint(): string
|
||||
return 'Lernziel, Zeit, Material und Aufbau sind unverändert. Es entsteht keine neue Fassung.';
|
||||
}
|
||||
|
||||
return 'Übernehmen legt eine neue Fassung an. Die bisherige Fassung bleibt und wird nicht überschrieben.';
|
||||
return 'Freigeben legt eine neue unveränderliche Fassung an. Speichern schreibt nur den Entwurf und lässt freigegebene Fassungen unverändert.';
|
||||
}
|
||||
|
||||
public function selectPart(int $index): void
|
||||
@@ -396,7 +602,9 @@ public function addPart(string $target): void
|
||||
$this->panel = 'bestandteil';
|
||||
$this->syncRoleDraft();
|
||||
$this->search = '';
|
||||
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die neue Fassung entsteht erst mit „Neue Fassung übernehmen“.';
|
||||
$this->pickerOpen = false;
|
||||
$this->pickerSelected = '';
|
||||
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Gespeichert ist das erst mit „Entwurf speichern“.';
|
||||
}
|
||||
|
||||
public function removePart(int $index): void
|
||||
@@ -489,7 +697,9 @@ public function addText(): void
|
||||
|
||||
$this->newTextTitle = '';
|
||||
$this->newTextBody = '';
|
||||
$this->textOpen = false;
|
||||
$this->addPart('element:'.$version->id);
|
||||
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Gespeichert ist das erst mit „Entwurf speichern“.';
|
||||
}
|
||||
|
||||
public function startModule(): void
|
||||
@@ -579,7 +789,11 @@ public function publishRevision(): bool
|
||||
}
|
||||
|
||||
if (! $this->needsRevision()) {
|
||||
$this->feedback = 'Die Fassung ist unverändert.';
|
||||
/** @var Composition $unchanged */
|
||||
$unchanged = $this->getRecord();
|
||||
app(EditorialWorkingDraft::class)->clear($unchanged);
|
||||
$this->releaseArmed = false;
|
||||
$this->feedback = 'Die freigegebene Fassung ist unverändert. Es entsteht keine neue Fassung.';
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -641,6 +855,8 @@ public function publishRevision(): bool
|
||||
|
||||
$this->revisionNote = '';
|
||||
$this->templateNumber = null;
|
||||
$this->releaseArmed = false;
|
||||
app(EditorialWorkingDraft::class)->clear($record);
|
||||
$this->loadEditor();
|
||||
$this->feedback = 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.';
|
||||
|
||||
@@ -709,6 +925,14 @@ protected function loadEditor(): void
|
||||
default => 'alles',
|
||||
};
|
||||
|
||||
$draft = app(EditorialWorkingDraft::class)->read($composition);
|
||||
|
||||
if ($draft !== null) {
|
||||
$this->applyDraft($draft);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($version === null) {
|
||||
$this->members = [];
|
||||
$this->learningGoal = '';
|
||||
@@ -721,6 +945,45 @@ protected function loadEditor(): void
|
||||
$this->applyVersion($version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $draft
|
||||
*/
|
||||
protected function applyDraft(array $draft): void
|
||||
{
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
$rows = [];
|
||||
$requested = 0;
|
||||
|
||||
foreach ($draft['members'] ?? [] as $member) {
|
||||
if (! is_array($member)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requested++;
|
||||
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true);
|
||||
|
||||
if ($row === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row['role'] = (string) ($member['role'] ?? $row['kind']);
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$this->members = $rows;
|
||||
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
|
||||
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
|
||||
$this->materialNote = (string) ($draft['material_note'] ?? '');
|
||||
$this->revisionNote = (string) ($draft['revision_note'] ?? '');
|
||||
$this->selected = null;
|
||||
$this->roleDraft = '';
|
||||
$this->panel = 'angaben';
|
||||
|
||||
if ($requested > count($rows) && $this->feedback === '') {
|
||||
$this->feedback = 'Ein Bestandteil des Entwurfs ist nicht mehr bereit und wurde nicht geladen.';
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyVersion(CompositionVersion $version): void
|
||||
{
|
||||
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
|
||||
@@ -899,17 +1162,122 @@ protected function storePreview(string $path): void
|
||||
}
|
||||
|
||||
protected function statusSentence(): string
|
||||
{
|
||||
return $this->editorStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{learning_goal: ?string, duration_minutes: int|string|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
|
||||
*/
|
||||
protected function payload(): array
|
||||
{
|
||||
$members = $this->members;
|
||||
|
||||
if ($this->selected !== null && isset($members[$this->selected]) && trim($this->roleDraft) !== '') {
|
||||
$members[$this->selected]['role'] = trim($this->roleDraft);
|
||||
}
|
||||
|
||||
$minutes = $this->minutes($this->durationMinutes);
|
||||
|
||||
return [
|
||||
'learning_goal' => $this->blank($this->learningGoal),
|
||||
'duration_minutes' => $minutes === false ? $this->durationMinutes : $minutes,
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
'revision_note' => $this->blank($this->revisionNote),
|
||||
'members' => array_values(array_map(
|
||||
fn (array $member): array => [
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'target' => (string) ($member['target'] ?? ''),
|
||||
],
|
||||
$members,
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{learning_goal: ?string, duration_minutes: int|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}|null
|
||||
*/
|
||||
protected function storedPayload(): ?array
|
||||
{
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
$draft = $composition->working_draft;
|
||||
|
||||
if (! is_array($draft) || $draft === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->normalizePayload($draft);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{learning_goal: ?string, duration_minutes: int|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
|
||||
*/
|
||||
protected function readyPayload(): array
|
||||
{
|
||||
$version = $this->currentReadyVersion();
|
||||
|
||||
if ($version === null) {
|
||||
return 'Noch keine Fassung.';
|
||||
return [
|
||||
'learning_goal' => null,
|
||||
'duration_minutes' => null,
|
||||
'material_note' => null,
|
||||
'revision_note' => null,
|
||||
'members' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$released = app(CompositionDisplayRelease::class)->isReleased($version);
|
||||
$rows = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
|
||||
|
||||
return 'Zuletzt übernommen: Fassung '.$version->number.'. '
|
||||
.($released ? 'Sie ist zur Anzeige freigegeben.' : 'Sie ist noch nicht zur Anzeige freigegeben.');
|
||||
return [
|
||||
'learning_goal' => $version->learning_goal,
|
||||
'duration_minutes' => $version->duration_minutes === null ? null : (int) $version->duration_minutes,
|
||||
'material_note' => $version->material_note,
|
||||
'revision_note' => null,
|
||||
'members' => array_values(array_map(
|
||||
fn (array $row): array => [
|
||||
'role' => trim((string) ($row['role'] ?? '')),
|
||||
'target' => (string) ($row['target'] ?? ''),
|
||||
],
|
||||
$rows,
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
* @return array{learning_goal: ?string, duration_minutes: int|string|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
|
||||
*/
|
||||
protected function normalizePayload(array $payload): array
|
||||
{
|
||||
$members = [];
|
||||
|
||||
foreach ($payload['members'] ?? [] as $member) {
|
||||
if (! is_array($member)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$members[] = [
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'target' => (string) ($member['target'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'learning_goal' => $payload['learning_goal'] ?? null,
|
||||
'duration_minutes' => $payload['duration_minutes'] ?? null,
|
||||
'material_note' => $payload['material_note'] ?? null,
|
||||
'revision_note' => $payload['revision_note'] ?? null,
|
||||
'members' => $members,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
protected function fingerprint(array $payload): string
|
||||
{
|
||||
return json_encode($this->normalizePayload($payload), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
protected function actor(): ?User
|
||||
|
||||
@@ -8,13 +8,17 @@
|
||||
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\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;
|
||||
|
||||
class EditorialCatalog
|
||||
{
|
||||
@@ -72,6 +76,9 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'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),
|
||||
@@ -100,6 +107,9 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'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,
|
||||
@@ -180,6 +190,149 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
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}>
|
||||
*/
|
||||
@@ -284,15 +437,18 @@ public function stand(Composition $composition): array
|
||||
$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' => 'Noch ohne Fassung',
|
||||
'text' => $draft ? 'Entwurf gespeichert' : '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');
|
||||
$text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht zur Anzeige freigegeben');
|
||||
$text = ($draft ? 'Entwurf gespeichert. ' : '').$text;
|
||||
|
||||
if ($released instanceof CompositionVersion && $released->number !== $latest->number) {
|
||||
$text .= '. Angezeigt wird Fassung '.$released->number;
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class EditorialPreviewController extends Controller
|
||||
{
|
||||
@@ -30,6 +33,101 @@ public function show(Composition $composition, ?CompositionVersion $version = nu
|
||||
abort_unless((int) $version->composition_id === (int) $composition->id, 404);
|
||||
abort_unless($version->status === ContentVersionStatus::Bereit, 404);
|
||||
|
||||
return $this->render(
|
||||
$composition,
|
||||
$version->learning_goal,
|
||||
$version->duration_minutes,
|
||||
$version->material_note,
|
||||
$version->number,
|
||||
false,
|
||||
array_map(
|
||||
fn (StructureNode $node): array => $this->present($node, app(EditorialCatalog::class)),
|
||||
app(CompositionStructureReader::class)->tree($version),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function draft(Composition $composition): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
$draft = $composition->working_draft;
|
||||
abort_unless(is_array($draft) && ($draft['members'] ?? null) !== null, 404);
|
||||
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
$nodes = [];
|
||||
|
||||
foreach ($draft['members'] as $member) {
|
||||
if (! is_array($member)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $composition->id, allowSelf: true);
|
||||
|
||||
if ($row === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$children = [];
|
||||
|
||||
if (preg_match('/^composition:(\d+)$/', (string) $row['target'], $match) === 1) {
|
||||
$nested = CompositionVersion::query()->find($match[1]);
|
||||
|
||||
if ($nested instanceof CompositionVersion) {
|
||||
$children = array_map(
|
||||
fn (StructureNode $node): array => $this->present($node, $catalog),
|
||||
app(CompositionStructureReader::class)->tree($nested),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$nodes[] = [
|
||||
'role' => (string) ($member['role'] ?? $row['kind']),
|
||||
'title' => $row['title'],
|
||||
'kind' => $row['kind'],
|
||||
'version' => $row['version_label'],
|
||||
'open_url' => $row['open_url'],
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
$composition,
|
||||
$draft['learning_goal'] ?? null,
|
||||
$draft['duration_minutes'] ?? null,
|
||||
$draft['material_note'] ?? null,
|
||||
null,
|
||||
true,
|
||||
$nodes,
|
||||
);
|
||||
}
|
||||
|
||||
public function card(string $kind, int $subject): StreamedResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
abort_unless(in_array($kind, ['element', 'komposition'], true), 404);
|
||||
$model = $kind === 'komposition'
|
||||
? Composition::query()->findOrFail($subject)
|
||||
: ContentElement::query()->findOrFail($subject);
|
||||
$path = $model->thumbnail_path;
|
||||
abort_unless(is_string($path) && str_starts_with($path, 'vorschau/') && ! str_contains($path, '..'), 404);
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($path), 404);
|
||||
|
||||
return $disk->response($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
*/
|
||||
private function render(
|
||||
Composition $composition,
|
||||
mixed $learningGoal,
|
||||
mixed $durationMinutes,
|
||||
mixed $materialNote,
|
||||
mixed $number,
|
||||
bool $draft,
|
||||
array $nodes,
|
||||
): View {
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
|
||||
return view('filament.editorial.preview', [
|
||||
@@ -37,15 +135,13 @@ public function show(Composition $composition, ?CompositionVersion $version = nu
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->deskLabel()),
|
||||
'learningGoal' => $version->learning_goal,
|
||||
'durationMinutes' => $version->duration_minutes,
|
||||
'materialNote' => $version->material_note,
|
||||
'number' => $version->number,
|
||||
'learningGoal' => $learningGoal,
|
||||
'durationMinutes' => $durationMinutes,
|
||||
'materialNote' => $materialNote,
|
||||
'number' => $number,
|
||||
'draft' => $draft,
|
||||
'backUrl' => $catalog->editUrl($composition),
|
||||
'nodes' => array_map(
|
||||
fn (StructureNode $node): array => $this->present($node, $catalog),
|
||||
app(CompositionStructureReader::class)->tree($version),
|
||||
),
|
||||
'nodes' => $nodes,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user