getRecord(); } public function editorialProfile(?string $audience = null): EditorialProfile { return app(EditorialProfileReader::class)->read($this->editorialSubject(), $audience); } /** * @return list */ public function editorialGaps(): array { $profile = $this->editorialProfile(); $gaps = []; foreach ([ 'display_title' => 'Anzeigename', 'teaser' => 'Teaser', 'summary' => 'Kurzbeschreibung', 'description' => 'Ausführliche Beschreibung', ] as $field => $label) { if ($profile->value($field) === null) { $gaps[] = $label; } } return $gaps; } /** * @return list> */ public function presentationRows(): array { return app(PresentationMedia::class)->rows($this->editorialSubject()); } /** * @return array */ public function presentationRoleOptions(): array { return PresentationRole::selectOptions(); } /** * @return array{items: list>, more: bool} */ public function presentationChoices(): array { return app(EditorialCatalog::class)->presentationBrowse($this->presentationQuery); } public function assignPickedPresentation(): void { $this->guardEditorial(); $row = app(EditorialCatalog::class)->rowForTarget($this->presentationPick, 0, allowDraft: true); if ($row === null || ! isset($row['element_id'])) { $this->deskFeedback = 'Bitte ein Medium aus dem Bestand wählen.'; return; } $this->rememberAssignment((int) $row['element_id'], isset($row['target']) ? (string) $row['target'] : null); $this->presentationPick = ''; } public function detachPresentation(int $assignmentId): void { $this->guardEditorial(); $this->deskFeedback = $this->reportPresentation( fn (): string => app(PresentationMedia::class)->detach($this->editorialSubject(), $assignmentId, $this->deskActor()), ); } public function movePresentation(int $assignmentId, int $direction): void { $this->guardEditorial(); $this->deskFeedback = $this->reportPresentation(function () use ($assignmentId, $direction): string { app(PresentationMedia::class)->move($this->editorialSubject(), $assignmentId, $direction, $this->deskActor()); return 'Die Reihenfolge ist gespeichert.'; }); } public function releaseAssigned(int $elementId): void { abort_unless(ContentElementResource::editor(), 403); $element = ContentElement::query()->find($elementId); if (! $element instanceof ContentElement) { $this->deskFeedback = 'Das Medium fehlt.'; return; } $this->deskFeedback = app(WebsiteRelease::class)->release($element, $this->deskActor()); } public function withdrawAssigned(int $elementId): void { abort_unless(ContentElementResource::editor(), 403); $element = ContentElement::query()->find($elementId); if (! $element instanceof ContentElement) { $this->deskFeedback = 'Das Medium fehlt.'; return; } $this->deskFeedback = app(WebsiteRelease::class)->withdraw($element, $this->deskActor()); } /** * @return list */ public function variantRows(): array { $subject = $this->editorialSubject(); return EditorialTextVariant::query() ->where('subject_type', $subject->getMorphClass()) ->where('subject_id', $subject->getKey()) ->orderBy('audience') ->orderBy('field') ->get() ->all(); } public function saveVariant(): void { $this->guardEditorial(); $this->deskFeedback = $this->reportPresentation( fn (): string => app(EditorialProfileReader::class)->putVariant( $this->editorialSubject(), $this->variantField, $this->variantAudience, $this->variantBody, $this->deskActor(), ), ); $this->variantBody = ''; } public function forgetVariant(int $variantId): void { $this->guardEditorial(); $variant = EditorialTextVariant::query()->find($variantId); if (! $variant instanceof EditorialTextVariant) { $this->deskFeedback = 'Diese Abweichung gibt es nicht mehr.'; return; } $this->reportPresentation(function () use ($variant): string { app(EditorialProfileReader::class)->forgetVariant($this->editorialSubject(), $variant, $this->deskActor()); return 'Die abweichende Formulierung ist entfernt.'; }); $this->deskFeedback = 'Die abweichende Formulierung ist entfernt. Es gilt wieder die zentrale Angabe.'; } public function variantFieldLabel(string $field): string { return match ($field) { 'display_title' => 'Anzeigename', 'teaser' => 'Teaser', 'summary' => 'Kurzbeschreibung', 'description' => 'Ausführliche Beschreibung', default => $field, }; } public function canReleasePresentation(): bool { return ContentElementResource::editor(); } public function canEditEditorial(): bool { return ContentElementResource::editor(); } protected function rememberAssignment(int $elementId, ?string $target): void { $sourceId = null; if ($this->bindToVersion && in_array($this->presentationRole, PresentationRole::BOUND_ROLES, true)) { $subject = $this->editorialSubject(); $sourceId = $subject instanceof ContentElement ? $subject->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->value('id') : $this->versionIdFromTarget($target); } $this->deskFeedback = $this->reportPresentation( fn (): string => app(PresentationMedia::class)->assign( $this->editorialSubject(), $this->presentationRole, $elementId, $sourceId !== null ? (int) $sourceId : null, $this->deskActor(), ), ); } protected function versionIdFromTarget(?string $target): ?int { if (is_string($target) && preg_match('/^element:(\d+)$/', $target, $match) === 1) { return (int) $match[1]; } return null; } protected function guardEditorial(): void { abort_unless($this->canEditEditorial(), 403); } protected function deskActor(): ?User { $user = auth()->user(); return $user instanceof User ? $user : null; } /** * @param callable(): string $action */ protected function reportPresentation(callable $action): string { try { return $action(); } catch (DomainRuleException $exception) { return $exception->getMessage(); } } }