label('Artikel anlegen') ->modalHeading('Neuer Lizenzartikel') ->modalDescription('Kennung und Produktlinie genügen. Titel, Texte und Stand pflegst du danach am Artikel.') ->modalSubmitActionLabel('Artikel anlegen') ->schema([ TextInput::make('code')->label('Kennung')->required(), TextInput::make('product_line')->label('Produktlinie'), ]) ->action(function (array $data): void { $article = null; $this->report(function () use ($data, &$article): void { $article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null); }, 'Der Lizenzartikel ist angelegt.'); if ($article instanceof LicenseArticle) { $this->redirect(LicenseArticleResource::getUrl('view', ['record' => $article])); } }), ]; } protected function catalogRows(): array { $offered = DB::table('resolved_scopes') ->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id') ->where('offer_versions.status', 'aktiv') ->distinct() ->pluck('resolved_scopes.license_article_id') ->map(fn (mixed $id): int => (int) $id) ->all(); $presentation = app(PresentationMedia::class); $rows = []; foreach (LicenseArticle::query()->with(['currentRelease', 'releases'])->orderBy('code')->get() as $article) { $current = $article->currentRelease; $currentStatus = $current !== null ? StatusValue::of($current->status) : null; $draft = $article->releases->first(fn ($release): bool => StatusValue::of($release->status) === ReleaseStatus::Entwurf->value); $chips = []; $zustand = []; if ($current === null) { $chips[] = ['label' => 'Noch kein Stand', 'ton' => 'offen']; $zustand[] = 'ohne'; } elseif ($currentStatus === ReleaseStatus::Gesperrt->value) { $chips[] = ['label' => 'Stand '.$current->number.' gesperrt', 'ton' => 'achtung']; $zustand[] = 'gesperrt'; } else { $chips[] = ['label' => 'Stand '.$current->number.' veröffentlicht', 'ton' => 'gut']; $zustand[] = 'stand'; } if ($draft !== null) { $chips[] = ['label' => 'Stand '.$draft->number.' in Arbeit', 'ton' => 'offen']; $zustand[] = 'entwurf'; } $inOffer = in_array($article->id, $offered, true); $chips[] = $inOffer ? ['label' => 'In einem aktiven Angebot', 'ton' => 'gut'] : ['label' => 'In keinem aktiven Angebot', 'ton' => 'leise']; $zustand[] = $inOffer ? 'angebot' : 'ohne-angebot'; if ($article->archived_at !== null) { $chips[] = ['label' => 'Archiviert', 'ton' => 'leise']; $zustand[] = 'archiviert'; } $coverId = $presentation->coverElementId($article); $cover = $coverId !== null ? ContentElement::query()->find($coverId) : null; $title = trim((string) ($article->display_title ?: $article->working_title)) ?: $article->code; $url = LicenseArticleResource::getUrl('view', ['record' => $article]); $rows[] = [ 'schluessel' => 'a'.$article->id, 'titel' => $title, 'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''), 'text' => trim((string) ($article->teaser ?: $article->summary)), 'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null, 'symbol' => 'dokument', 'url' => $url, 'chips' => $chips, 'zustand' => $zustand, 'suchtext' => implode(' ', array_filter([$article->code, $article->working_title, $article->display_title, $article->summary, $article->product_line, $article->search_terms])), 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], ]; } return $rows; } protected function zustandOptionen(): array { return [ 'alle' => 'Jeder Zustand', 'stand' => 'Mit veröffentlichtem Stand', 'ohne' => 'Noch ohne Stand', 'entwurf' => 'Stand in Arbeit', 'gesperrt' => 'Gesperrter Stand', 'angebot' => 'In einem aktiven Angebot', 'ohne-angebot' => 'In keinem aktiven Angebot', 'archiviert' => 'Archiviert', ]; } protected function einheit(): array { return ['Lizenzartikel', 'Lizenzartikel']; } protected function leer(): array { return ['titel' => 'Noch keine Lizenzartikel', 'text' => 'Mit „Artikel anlegen“ oben entsteht der erste Artikel.']; } protected function suchPlatzhalter(): string { return 'Kennung, Titel oder Produktlinie'; } }