Lasse Präsentationsmedien ohne Inhaltsfassung zu.
CI Feature / test (push) Successful in 53s
Deploy Test / test (push) Successful in 48s
Deploy Test / deploy (push) Successful in 22s

Bilder, Filme und Hörstücke lassen sich zuordnen und für die Website freigeben, ohne eine fachliche Fassung anzulegen. Unterrichtsfilme behalten die Teaserfassung an ihrer bereitgestellten Fassung.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-19 08:20:35 +01:00
1 parent 5590225f4f
commit 7b325f0d66
25 files changed
+734 -93

No files matched your search

+1
View File
@@ -28,6 +28,7 @@ class ContentElement extends Model
'thumbnail_alt',
'thumbnail_source',
'thumbnail_error',
'preview_path',
'editorial_content_kind_id',
'archived_at',
];
+29
View File
@@ -2,6 +2,7 @@
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -13,4 +14,32 @@ public function values(): HasMany
{
return $this->hasMany(EditorialDimensionValue::class);
}
/**
* Inhaltselemente pflegen Themen über die Säulen, nicht noch einmal über die Dimension.
* Module, Programme und Lizenzartikel haben keine Säulenauswahl und behalten die Dimension.
*
* @return Collection<int, self>
*/
public static function forSubject(Model $subject): Collection
{
$query = static::query()->with('values')->orderBy('label');
if ($subject instanceof ContentElement) {
$query->where('slug', '!=', 'saeule');
}
return $query->get();
}
/**
* @return list<int>
*/
public static function offeredValueIds(Model $subject): array
{
return static::forSubject($subject)
->flatMap(fn (self $dimension) => $dimension->values->pluck('id'))
->map(fn ($id): int => (int) $id)
->all();
}
}
+31
View File
@@ -52,4 +52,35 @@ public function matches(Model $subject, array $valueIds): bool
return true;
}
/**
* Ersetzt nur die Werte der Dimensionen, die dieses Fachobjekt anbietet.
* Nicht angebotene Zuordnungen, etwa gespiegelte Säulen am Inhaltselement, bleiben.
*
* @param list<int> $valueIds
*/
public function replaceOffered(Model $subject, array $valueIds): void
{
$offeredIds = EditorialDimension::offeredValueIds($subject);
$ids = array_values(array_intersect(
array_values(array_unique(array_map(intval(...), $valueIds))),
$offeredIds,
));
$query = IdentityDimensionValue::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('origin', 'direkt')
->whereIn('editorial_dimension_value_id', $offeredIds === [] ? [0] : $offeredIds);
if ($ids !== []) {
$query->whereNotIn('editorial_dimension_value_id', $ids);
}
$query->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
$this->assign($subject, $value, 'direkt');
}
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\DomainRuleException;
use Illuminate\Support\Facades\Storage;
/**
* Legt die technische Ableitung eines Präsentationsmediums an der Medienidentität ab.
* Es entsteht keine Inhaltsfassung, keine Freigabe und keine Berechtigung.
*/
class PresentationFile
{
public function store(ContentElement $element, string $incoming): void
{
if (! in_array($element->output_class, ['bild', 'film', 'audio'], true)) {
throw new DomainRuleException('Eine Präsentationsdatei ist ein Bild, ein Film oder ein Hörstück.');
}
if ($element->versions()->exists()) {
throw new DomainRuleException('Dieses Medium hat bereits eine Inhaltsfassung. Die Präsentationsdatei ersetzt sie nicht.');
}
if (! $this->readable($incoming)) {
throw new DomainRuleException('Die Datei liegt nicht im Eingang.');
}
$extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION));
$allowed = match ($element->output_class) {
'bild' => ['jpg', 'jpeg', 'png', 'webp', 'gif'],
'audio' => ['mp3', 'm4a', 'ogg'],
default => ['mp4', 'webm'],
};
if (! in_array($extension, $allowed, true)) {
throw new DomainRuleException('Diese Datei ist keine freigebbare Ableitung. Es wird keine Inhaltsfassung angelegt.');
}
$prefix = $element->output_class === 'bild' ? 'vorschau' : 'teaser';
$target = $prefix.'/'.$element->id.'/datei.'.$extension;
$stream = Storage::disk('cms_incoming')->readStream($incoming);
if (! is_resource($stream)) {
throw new DomainRuleException('Die Datei ließ sich nicht lesen.');
}
try {
Storage::disk('media_derived')->writeStream($target, $stream);
} finally {
fclose($stream);
}
if ($element->output_class === 'bild') {
$element->thumbnail_path = $target;
$element->thumbnail_source = 'eigen';
} else {
$element->preview_path = $target;
}
$element->save();
}
private function readable(string $path): bool
{
return (str_starts_with($path, 'inhalte/') || str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
&& ! str_contains($path, '..')
&& preg_match('#^(inhalte|cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
&& Storage::disk('cms_incoming')->exists($path);
}
}
+5 -1
View File
@@ -40,7 +40,11 @@ public function present(ContentElement|int $element): ?WebsitePresentation
title: $title,
alt: $alt !== '' ? $alt : $title,
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
kind: $element->output_class === 'film' ? 'film' : 'bild',
kind: match ($element->output_class) {
'film' => 'film',
'audio' => 'audio',
default => 'bild',
},
url: route('website.media', $element),
);
}
+19 -5
View File
@@ -44,7 +44,7 @@ public function refusal(ContentElement $element): ?string
}
if ($this->derivedPath($element) === null) {
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild, beim Film eine Teaserfassung unter teaser/. Die Originaldatei bleibt geschützt.';
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild. Film und Hörstück ohne Inhaltsfassung nutzen die Datei am Medium unter teaser/. Ein Film mit Inhaltsfassung nutzt die Teaserfassung seiner bereitgestellten Fassung. Die Originaldatei bleibt geschützt.';
}
return null;
@@ -57,7 +57,18 @@ public function derivedPath(ContentElement $element): ?string
}
if ($element->output_class === 'bild') {
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/');
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/', ['jpg', 'jpeg', 'png', 'webp', 'gif']);
}
if (in_array($element->output_class, ['film', 'audio'], true)) {
$extensions = $element->output_class === 'audio'
? ['mp3', 'm4a', 'ogg']
: ['mp4', 'webm'];
$own = $this->allowedDerivedPath($element->preview_path, 'teaser/', $extensions);
if ($own !== null) {
return $own;
}
}
if ($element->output_class !== 'film') {
@@ -79,7 +90,7 @@ public function derivedPath(ContentElement $element): ?string
->orderByDesc('id')
->value('path');
return $this->allowedDerivedPath($path, 'teaser/');
return $this->allowedDerivedPath($path, 'teaser/', ['mp4', 'webm']);
}
public function publicPath(ContentElement $element, string $derivedPath): string
@@ -100,7 +111,10 @@ private function isConfidential(ContentElement $element): bool
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
}
private function allowedDerivedPath(mixed $path, string $prefix): ?string
/**
* @param list<string> $extensions
*/
private function allowedDerivedPath(mixed $path, string $prefix, array $extensions): ?string
{
if (! is_string($path) || ! str_starts_with($path, $prefix) || str_contains($path, '..')) {
return null;
@@ -108,7 +122,7 @@ private function allowedDerivedPath(mixed $path, string $prefix): ?string
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'webm'], true)) {
if (! in_array($extension, $extensions, true)) {
return null;
}
@@ -14,7 +14,6 @@
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\EditorialWorkingDraft;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
@@ -348,6 +347,25 @@ public function assignFromPicker(string $target): void
{
$this->guardEditorial();
if (preg_match('/^medium:(\d+)$/', $target, $mediumMatch) === 1) {
$element = ContentElement::query()->find((int) $mediumMatch[1]);
if (! $element instanceof ContentElement
|| $element->archived_at !== null
|| ! in_array($element->output_class, ['bild', 'film', 'audio'], true)) {
$this->deskFeedback = 'Dieses Präsentationsmedium ist nicht verfügbar.';
return;
}
$this->rememberAssignment($element->id, null);
$this->pickerOpen = false;
$this->pickerPurpose = 'aufbau';
$this->pickerSelected = '';
return;
}
if (preg_match('/^element:(\d+)$/', $target, $match) !== 1) {
$this->deskFeedback = 'Präsentationsmedien sind Medien aus dem Bestand. Ein Modul bleibt Bestandteil des Aufbaus.';
@@ -382,6 +400,10 @@ public function pickerResult(): array
return ['items' => [], 'more' => false];
}
if ($this->pickerPurpose === 'praesentation') {
return app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery);
}
return app(EditorialCatalog::class)->browse(
$this->pickerQuery,
$this->pickerKind,
@@ -687,7 +709,7 @@ public function dimensionGroups(): array
{
$groups = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
$values = [];
foreach ($dimension->values as $value) {
@@ -1854,16 +1876,7 @@ protected function blank(string $value): ?string
*/
protected function syncDimensions(Composition $composition, array $ids): void
{
IdentityDimensionValue::query()
->where('subject_type', $composition->getMorphClass())
->where('subject_id', $composition->id)
->where('origin', 'direkt')
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
app(IdentityDimension::class)->assign($composition, $value, 'direkt');
}
app(IdentityDimension::class)->replaceOffered($composition, $ids);
}
protected function persistPresentation(): bool
@@ -9,7 +9,6 @@
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
@@ -93,7 +92,7 @@ public function form(Schema $schema): Schema
CheckboxList::make('dimension_ids')->label('Fachliche Einordnung')
->options(function (): array {
$options = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
foreach ($dimension->values as $value) {
$options[$value->id] = $dimension->label.': '.$value->label;
}
@@ -233,16 +232,7 @@ protected function handleRecordUpdate(Model $record, array $data): Model
DeriveThumbnail::dispatch('element', $record->id, $data['thumbnail_upload']);
}
if (array_key_exists('dimension_ids', $data)) {
$ids = array_map(intval(...), $data['dimension_ids'] ?? []);
IdentityDimensionValue::query()
->where('subject_type', $record->getMorphClass())
->where('subject_id', $record->id)
->where('origin', 'direkt')
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
app(IdentityDimension::class)->assign($record, $value, 'direkt');
}
app(IdentityDimension::class)->replaceOffered($record, array_map(intval(...), $data['dimension_ids'] ?? []));
}
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
} catch (DomainRuleException $exception) {
@@ -6,7 +6,6 @@
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityChange;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
@@ -476,17 +475,7 @@ public function saveEditorial(): void
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
], auth()->user());
app(PillarService::class)->assign($element, array_map(intval(...), $this->pillarIds));
$ids = array_map(intval(...), $this->dimensionIds);
IdentityDimensionValue::query()
->where('subject_type', $element->getMorphClass())
->where('subject_id', $element->id)
->where('origin', 'direkt')
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
app(IdentityDimension::class)->assign($element, $value, 'direkt');
}
app(IdentityDimension::class)->replaceOffered($element, array_map(intval(...), $this->dimensionIds));
$element->refresh();
$this->fillEditorial();
@@ -6,7 +6,6 @@
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
@@ -75,17 +74,7 @@ public function saveLicenseEditorial(): void
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
], auth()->user());
$ids = array_map(intval(...), $this->dimensionIds);
IdentityDimensionValue::query()
->where('subject_type', $article->getMorphClass())
->where('subject_id', $article->id)
->where('origin', 'direkt')
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
app(IdentityDimension::class)->assign($article, $value, 'direkt');
}
app(IdentityDimension::class)->replaceOffered($article, array_map(intval(...), $this->dimensionIds));
$article->refresh();
$this->fillLicenseEditorial();
@@ -101,7 +90,7 @@ public function licenseDimensionGroups(): array
{
$groups = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) {
$values = [];
foreach ($dimension->values as $value) {
+103
View File
@@ -65,6 +65,10 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
return $this->draftCompositionRow((int) $draftMatch[1], $exceptCompositionId, $allowSelf);
}
if (preg_match('/^medium:(\d+)$/', $target, $mediumMatch) === 1) {
return $this->rowForPresentationMedium((int) $mediumMatch[1]);
}
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
return null;
}
@@ -388,6 +392,105 @@ public function browse(string $query, string $kind, string $dimension, int $exce
];
}
/**
* Bestandssuche für Präsentationsmedien.
* Fassungen bleiben im didaktischen Aufbau. Bilder, Filme und Hörstücke ohne Inhaltsfassung kommen dazu.
*
* @return array{items: list<array<string, string|null>>, more: bool}
*/
public function presentationBrowse(string $query): array
{
$catalog = $this->browse($query, 'alle', '', 0, elementsOnly: true);
$seen = [];
foreach ($catalog['items'] as $item) {
if (isset($item['element_id'])) {
$seen[(int) $item['element_id']] = true;
}
}
$query = trim($query);
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
$elements = ContentElement::query()
->with('editorialContentKind')
->whereIn('output_class', ['bild', 'film', 'audio'])
->whereNull('archived_at')
->whereDoesntHave('versions')
->where(function ($builder): void {
$builder->whereNull('editorial_content_kind_id')
->orWhereDoesntHave('editorialContentKind', function ($kind): void {
$kind->where('slug', 'traineranleitung');
});
})
->when($query !== '', function ($builder) use ($like): void {
$builder->where(function ($inner) use ($like): void {
$inner->where('working_title', 'like', $like)
->orWhere('display_title', 'like', $like)
->orWhere('teaser', 'like', $like)
->orWhere('search_terms', 'like', $like)
->orWhere('summary', 'like', $like);
});
})
->orderBy('working_title')
->limit(48)
->get();
foreach ($elements as $element) {
if (isset($seen[$element->id])) {
continue;
}
$row = $this->rowForPresentationMedium($element->id);
if ($row !== null) {
$catalog['items'][] = $row;
}
}
return $catalog;
}
/**
* @return array<string, string|null>|null
*/
private function rowForPresentationMedium(int $id): ?array
{
$element = ContentElement::query()->with('editorialContentKind')->find($id);
if (! $element instanceof ContentElement
|| $element->archived_at !== null
|| ! in_array($element->output_class, ['bild', 'film', 'audio'], true)
|| $element->editorialContentKind?->slug === 'traineranleitung') {
return null;
}
$kind = $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class);
$title = filled($element->display_title) ? $element->display_title : $element->working_title;
return [
'target' => 'medium:'.$element->id,
'element_id' => (string) $element->id,
'title' => $title,
'kind' => $kind,
'output' => (string) $element->output_class,
'body' => '',
'summary' => (string) ($element->summary ?: $element->description ?: ''),
'medium_description' => (string) ($element->description ?? ''),
'usage_note' => (string) ($element->usage_note ?? ''),
'license_note' => (string) ($element->license_note ?? ''),
'tone' => $this->tone((string) $element->output_class, $kind),
'image' => $element->output_class === 'bild'
? $this->cardUrl('element', $element->id, $element->thumbnail_path)
: null,
'version_label' => 'Ohne Inhaltsfassung',
'committed' => false,
'identity' => 'medium:'.$element->id,
'open_url' => ContentElementResource::getUrl('view', ['record' => $element]),
'open_label' => 'Medium ansehen',
'edit_url' => ContentElementResource::getUrl('view', ['record' => $element]),
];
}
public function tone(string $outputClass, string $kindLabel): string
{
$value = mb_strtolower($outputClass.' '.$kindLabel);
@@ -27,7 +27,7 @@ trait ManagesEditorialSurface
public string $presentationPick = '';
public bool $bindToVersion = true;
public bool $bindToVersion = false;
public string $deskFeedback = '';
@@ -90,7 +90,7 @@ public function presentationRoleOptions(): array
*/
public function presentationChoices(): array
{
return app(EditorialCatalog::class)->browse($this->presentationQuery, 'alle', '', 0, elementsOnly: true);
return app(EditorialCatalog::class)->presentationBrowse($this->presentationQuery);
}
public function assignPickedPresentation(): void
+16 -6
View File
@@ -7,7 +7,9 @@
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Media\PresentationFile;
use App\Jobs\DeriveThumbnail;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
@@ -39,6 +41,10 @@ public static function fields(bool $creating, ?ContentElement $element = null):
$fields[] = self::fileField()
->visible(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text')
->required(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text');
$fields[] = Checkbox::make('without_version')
->label('Eigenständiges Präsentationsmedium')
->helperText('Bild, Film oder Hörstück ohne fachliche Inhaltsfassung. Die Datei bleibt eine technische Ableitung am Medium. Sie wird nicht lizenziert und nicht automatisch für die Website freigegeben.')
->visible(fn ($get): bool => in_array($get('shape'), ['film', 'audio', 'bild'], true));
} elseif ($element?->output_class === 'text') {
$fields[] = Textarea::make('body')->label('Text')->rows(8)->required();
}
@@ -120,13 +126,17 @@ public static function create(array $data, bool $hold): ContentElement
throw new DomainRuleException('Diese Datei passt nicht zur gewählten Art.');
}
$metadata = ['incoming' => $incoming];
if ($hold) {
$metadata['hold'] = true;
$service->draftElementVersion($element, null, $metadata);
if (! empty($data['without_version']) && in_array($output, ['bild', 'film', 'audio'], true)) {
app(PresentationFile::class)->store($element, $incoming);
} else {
$service->publishElementVersion($element, null, $metadata);
$metadata = ['incoming' => $incoming];
if ($hold) {
$metadata['hold'] = true;
$service->draftElementVersion($element, null, $metadata);
} else {
$service->publishElementVersion($element, null, $metadata);
}
}
}