*/ public array $dimensionIds = []; public function mount(int|string $record): void { parent::mount($record); $this->fillLicenseEditorial(); } public function canEditEditorial(): bool { return LicenseArticleResource::keeper(); } public function canViewEditorial(): bool { return LicenseArticleResource::keeper(); } public function getTitle(): string|Htmlable { return $this->redaktionTitel(); } public function saveLicenseEditorial(): void { $this->saveRedaktion(); } protected function saveRedaktionTexte(): bool { $this->guardEditorial(); /** @var LicenseArticle $article */ $article = $this->getRecord(); $this->releaseBeforeSave = $article->current_release_id; $this->releaseCountBeforeSave = $article->releases()->count(); $kindError = app(EditorialVocabulary::class)->kindError( 'lizenzartikel', filled($this->kindId) ? (int) $this->kindId : null, $article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null, ); if ($kindError !== null) { $this->deskFeedback = $kindError; $this->redaktionFehlerFeld = 'kindId'; return false; } app(IdentityProfile::class)->fill($article, [ 'working_title' => $this->workingTitle, 'display_title' => $this->displayTitle, 'teaser' => $this->teaser, 'summary' => $this->summary, 'description' => $this->descriptionText, 'search_terms' => $this->searchTerms, 'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null, ], auth()->user()); app(IdentityDimension::class)->replaceOffered($article, array_map(intval(...), $this->dimensionIds)); $this->persistPillarIds($article); $article->refresh(); $this->fillLicenseEditorial(); return true; } protected function redaktionSavedMessage(): string { /** @var LicenseArticle $article */ $article = $this->getRecord(); return $article->current_release_id === $this->releaseBeforeSave && $article->releases()->count() === $this->releaseCountBeforeSave ? 'Gespeichert. Stand, Preis und Rechte bleiben unverändert.' : 'Gespeichert. Prüfe den Artikelstand, er hat sich geändert.'; } protected function resetRedaktionTexte(): void { $this->fillLicenseEditorial(); } public function einordnungUnsaved(): bool { /** @var LicenseArticle $article */ $article = $this->getRecord()->fresh() ?? $this->getRecord(); $kind = filled($this->kindId) ? (int) $this->kindId : null; $storedKind = $article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null; if ($kind !== $storedKind) { return true; } $stored = IdentityDimensionValue::query() ->where('subject_type', $article->getMorphClass()) ->where('subject_id', $article->getKey()) ->where('origin', 'direkt') ->pluck('editorial_dimension_value_id') ->map(fn ($id): int => (int) $id) ->all(); $current = array_map(intval(...), $this->dimensionIds); sort($stored); sort($current); return $stored !== $current || $this->pillarsUnsaved($article); } /** * @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string} */ public function redaktionKopf(): array { return [ 'art' => 'Lizenzartikel', 'fuer' => 'den Lizenzartikel', 'liste' => 'Lizenzartikel', 'zurueck' => 'Zurück zum Lizenzartikel', 'typ' => null, 'umfang' => '„Redaktion speichern“ sichert die eigenen Texte, Präsentationsmedien und Einordnung dieses Lizenzartikels. Leere Angaben übernehmen weiter die fachliche Quelle. Stand, Preis und Rechte bleiben unverändert.', ]; } public function redaktionTitel(): string { foreach ([$this->displayTitle, $this->workingTitle] as $title) { if (trim($title) !== '') { return trim($title); } } $profile = $this->editorialProfile('artikel'); if ($profile->value('display_title') !== null) { return (string) $profile->value('display_title'); } $source = $profile->source; return $source !== null ? $this->sourceTitle($source) : (string) $this->getRecord()->code; } /** * @return list> */ public function redaktionFelder(): array { /** @var LicenseArticle $article */ $article = $this->getRecord(); $source = app(EditorialProfileReader::class)->sourceOf($article); $sourceTitle = $source !== null ? $this->sourceTitle($source) : null; $stored = fn (string $column): string => (string) ($article->getAttribute($column) ?? ''); $quelle = fn (string $column): ?array => $sourceTitle === null ? null : [ 'titel' => $sourceTitle, 'wert' => (string) ($source->getAttribute($column) ?? ''), ]; return [ ['id' => 'arbeitstitel', 'label' => 'Interner Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'hilfe' => 'Nur in der Verwaltung sichtbar.'], ['id' => 'anzeigename', 'label' => 'Name', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'quelle' => $quelle('display_title')], ['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser'), 'quelle' => $quelle('teaser')], ['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 4, 'stored' => $stored('summary'), 'quelle' => $quelle('summary')], ['id' => 'beschreibung', 'label' => 'Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 6, 'stored' => $stored('description'), 'quelle' => $quelle('description')], ['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'quelle' => $quelle('search_terms')], ]; } /** * @return array{titel: string, art: string, fuer: string, url: ?string}|null */ public function redaktionQuelle(): ?array { /** @var LicenseArticle $article */ $article = $this->getRecord(); $source = app(EditorialProfileReader::class)->sourceOf($article); if ($source === null) { return null; } $url = match (true) { $source instanceof Composition => EditorialCatalog::editUrl($source), $source instanceof ContentElement => ContentElementResource::getUrl('view', ['record' => $source]), default => null, }; return [ 'titel' => $this->sourceTitle($source), 'art' => $source instanceof ContentElement ? 'Medium' : ($source instanceof Composition && $source->kind === CompositionKind::Kurs ? 'Programm' : 'Modul'), 'fuer' => 'diesen Lizenzartikel', 'url' => $url, ]; } public function redaktionOhneQuelle(): string { return 'Keine eindeutige fachliche Quelle. Es wird nichts aus einem Modul, Programm oder Medium übernommen.'; } /** * @return array{model: string, options: array, hilfe: string} */ public function einordnungArt(): array { return [ 'model' => 'kindId', 'options' => app(EditorialVocabulary::class)->kindOptions('lizenzartikel', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null), 'hilfe' => 'Die Einordnung des Artikels ändert weder die Quelle noch den Preis.', ]; } /** * @return list}> */ public function einordnungGruppen(): array { $groups = array_map(fn (array $group): array => [ 'legend' => $group['label'], 'model' => 'dimensionIds', 'values' => $group['values'], ], $this->licenseDimensionGroups()); $pillars = $this->pillarGroup(); return $pillars === null ? $groups : [$pillars, ...$groups]; } private function sourceTitle(Model $source): string { $title = $source->getAttribute('display_title') ?: ($source->getAttribute('working_title') ?? $source->getAttribute('designation')); return (string) $title; } /** * @return list}> */ public function licenseDimensionGroups(): array { return app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query() ->where('subject_type', $this->getRecord()->getMorphClass()) ->where('subject_id', $this->getRecord()->getKey()) ->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all()); } private function fillLicenseEditorial(): void { /** @var LicenseArticle $article */ $article = $this->getRecord(); $this->workingTitle = (string) ($article->working_title ?? ''); $this->displayTitle = (string) ($article->display_title ?? ''); $this->teaser = (string) ($article->teaser ?? ''); $this->summary = (string) ($article->summary ?? ''); $this->descriptionText = (string) ($article->description ?? ''); $this->searchTerms = (string) ($article->search_terms ?? ''); $this->kindId = $article->editorial_content_kind_id; $this->dimensionIds = IdentityDimensionValue::query() ->where('subject_type', $article->getMorphClass()) ->where('subject_id', $article->id) ->where('origin', 'direkt') ->pluck('editorial_dimension_value_id') ->all(); $this->loadPillarIds($article); } protected function getHeaderActions(): array { return []; } public function releaseAction(): Action { return Action::make('release') ->label(fn (): string => $this->isFirstStand() ? 'Inhalt festlegen' : 'Neuen Stand veröffentlichen') ->modalHeading(fn (): string => $this->isFirstStand() ? 'Inhalt festlegen: ersten Stand veröffentlichen' : 'Neuen Stand veröffentlichen') ->modalDescription(fn (): string => $this->isFirstStand() ? 'Der Stand legt fest, welche Inhalte dieser Lizenzartikel lizenziert: der gewählte Inhalt samt allem, was er enthält. Er ist danach unveränderlich. Pakete und Angebote können den Artikel danach verwenden; verkauft wird er erst über ein Angebot.' : 'Ein neuer Stand ersetzt den aktuellen für künftige Ausgaben. Bestehende Käufer erhalten ihn im Rahmen ihrer Lizenz; frühere Stände bleiben gespeichert.') ->modalSubmitActionLabel('Stand veröffentlichen') ->fillForm(fn (): array => $this->isFirstStand() ? ['classification' => 'Erster Stand dieses Lizenzartikels.'] : []) ->schema([ Select::make('root')->label('Freigegebener Inhalt') ->options(fn (): array => CatalogOptions::assignmentTargets()) ->searchable() ->required() ->helperText(fn (): string => CatalogOptions::assignmentTargets() === [] ? 'Es gibt noch keinen freigegebenen Inhalt. Gib zuerst ein Medium, Modul oder Programm frei.' : 'Medien, Module und Programme mit freigegebener Fassung. Bei Modulen und Programmen gehört alles Enthaltene zum Stand.'), Textarea::make('classification')->label('Einordnung') ->required(fn (): bool => ! $this->isFirstStand()) ->helperText(fn (): string => $this->isFirstStand() ? 'Beim ersten Stand genügt der vorgegebene Text.' : 'Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'), TextInput::make('change_note')->label('Änderungshinweis') ->visible(fn (): bool => ! $this->isFirstStand()), ]) ->action(function (array $data): void { $this->report(function () use ($data): string { /** @var LicenseArticle $article */ $article = $this->getRecord(); [$type, $id] = explode(':', $data['root'], 2); $root = $type === 'composition' ? CompositionVersion::query()->findOrFail($id) : ContentElementVersion::query()->findOrFail($id); $release = app(ArticleService::class)->publishRelease( $article, $root, (string) ($data['classification'] ?? 'Erster Stand dieses Lizenzartikels.'), $data['change_note'] ?? null, ); $report = $release->impact_report ?? []; $offers = $report['offers'] ?? []; return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0) .', Inhaber: '.($report['holders'] ?? 0) .', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.'; }, 'Der Artikel-Stand ist veröffentlicht.'); $this->refreshRecord(); }); } public function withdrawAction(): Action { return Action::make('withdraw') ->label('Stand zurückziehen') ->schema([ Textarea::make('reason')->label('Begründung')->required(), ]) ->action(function (array $data): void { $this->report(function () use ($data): string { $result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']); $current = $result['fallback_number'] === null ? 'Es gibt keinen früheren Stand.' : 'Aktuell ist wieder Stand '.$result['fallback_number'].'.'; $holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']); return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.'; }, 'Der Stand ist zurückgezogen.'); $this->refreshRecord(); }); } private function isFirstStand(): bool { return ! $this->getRecord()->releases()->exists(); } private function refreshRecord(): void { $this->getRecord()->unsetRelations(); $this->getRecord()->refresh(); } }