Files
LarsandClaude Sonnet 5.5 7c48a6480c
CI Feature / test (push) Successful in 1m34s
Deploy Test / test (push) Successful in 1m29s
Deploy Test / deploy (push) Successful in 29s
Vereinheitliche die fachlichen Säulen auf die zentrale Säulenverwaltung
Module, Programme und Lizenzartikel verwenden wie Medien und Seiten die Tabelle
pillars; die Kopie „Fachliche Säule“ in den redaktionellen Dimensionen wird nirgends
mehr angeboten, geändert oder gefiltert und bleibt nur als Verlauf erhalten.

- Migration (nur Ergänzungen): composition_pillar und license_article_pillar mit
  restrictOnDelete, pillar_id an den alten Dimensionswerten als dokumentierte
  Abbildung, einmalige wiederholbare Übernahme (LegacyPillarAdoption).
- Übernahme nur über die gespeicherte Kennung pfeiler-<Nummer> und nur direkte
  Zuordnungen; mehrdeutige, abgeleitete und verwaiste Fälle werden gemeldet, nicht
  geraten. Medien bleiben bei ihrer Zuordnung. Alte Zeilen bleiben unverändert.
  Befehl: php artisan luf:saeulen-uebernehmen [--dry-run].
- Editoren von Modul, Programm und Lizenzartikel wählen Säulen aus der Säulenverwaltung;
  PillarService::assign gilt für alle Objektarten, Löschschutz zählt alle Objektarten.
- Filter: Module und Programme, Aufbau-Picker und Mitgliederbibliothek nach der
  Säulenzuordnung; alte Adressen mit einem Säulenwert der Einordnung folgen der Säule.
- Abgeleitete Säulen (aus enthaltenen Medien) bleiben getrennt von direkten.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 10:11:42 +01:00

392 lines
15 KiB
PHP

<?php
namespace App\Filament\Resources\LicenseArticles\Pages;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\LicenseArticle;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Support\AssignsPillars;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\ManagesEditorialSurface;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
class ViewLicenseArticle extends ViewRecord
{
use AssignsPillars;
use ManagesEditorialSurface;
use ReportsDomainRules;
protected static string $resource = LicenseArticleResource::class;
public string $workingTitle = '';
public string $displayTitle = '';
public string $teaser = '';
public string $summary = '';
public string $descriptionText = '';
public string $searchTerms = '';
public int|string|null $kindId = null;
public ?int $releaseBeforeSave = null;
public int $releaseCountBeforeSave = 0;
/** @var list<int|string> */
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<array<string, mixed>>
*/
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<int|string, string>, 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<array{legend: string, model: string, values: list<array{id: int, label: string}>}>
*/
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<array{label: string, values: list<array{id: int, label: string}>}>
*/
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('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();
});
}
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 refreshRecord(): void
{
$this->getRecord()->unsetRelations();
$this->getRecord()->refresh();
}
}