*/ public array $dimensionIds = []; public function mount(int|string $record): void { parent::mount($record); $this->fillLicenseEditorial(); } public function canEditEditorial(): bool { return LicenseArticleResource::keeper(); } public function saveLicenseEditorial(): void { $this->guardEditorial(); /** @var LicenseArticle $article */ $article = $this->getRecord(); $releaseId = $article->current_release_id; $releases = $article->releases()->count(); 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)); $article->refresh(); $this->fillLicenseEditorial(); $this->deskFeedback = $article->current_release_id === $releaseId && $article->releases()->count() === $releases ? 'Gespeichert. Stand, Preis und Rechte bleiben unverändert.' : 'Gespeichert. Prüfe den Artikelstand, er hat sich geändert.'; } /** * @return list}> */ public function licenseDimensionGroups(): array { $groups = []; foreach (EditorialDimension::forSubject($this->getRecord()) 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; } 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(); } protected function getHeaderActions(): array { return [ Action::make('release') ->label('Stand veröffentlichen') ->schema([ Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(), Textarea::make('classification')->label('Einordnung')->required() ->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'), TextInput::make('change_note')->label('Änderungshinweis'), ]) ->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, $data['classification'], $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(); }), 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 refreshRecord(): void { $this->getRecord()->unsetRelations(); $this->getRecord()->refresh(); } }