Mache Auswahl, Aufbau und Entwurf im Redaktionseditor bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6955830579
commit
053a361801
14 files changed
+1040
-155
No files matched your search
@@ -8,13 +8,17 @@
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionMember;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditorialCatalog
|
||||
{
|
||||
@@ -72,6 +76,9 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'target' => 'element:'.$version->id,
|
||||
'title' => $title,
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
||||
'tone' => $this->tone((string) $element->output_class, $kind),
|
||||
'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path),
|
||||
'version_label' => 'Fassung '.$version->number,
|
||||
'identity' => 'medium:'.$element->id,
|
||||
'open_url' => route('content.preview', $version),
|
||||
@@ -100,6 +107,9 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'target' => 'composition:'.$version->id,
|
||||
'title' => $this->compositionTitle($composition),
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
'tone' => $this->tone('', $kind),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Fassung '.$version->number,
|
||||
'identity' => 'zusammenstellung:'.$composition->id,
|
||||
'open_url' => null,
|
||||
@@ -180,6 +190,149 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
return array_slice($rows, 0, 40);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: list<array<string, string|null>>, more: bool}
|
||||
*/
|
||||
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId): array
|
||||
{
|
||||
$query = trim($query);
|
||||
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
||||
$limit = 48;
|
||||
$rows = [];
|
||||
$dimensionId = ctype_digit($dimension) ? (int) $dimension : 0;
|
||||
|
||||
if ($kind !== 'modul') {
|
||||
$elements = ContentElementVersion::query()
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->with('element.editorialContentKind')
|
||||
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
||||
$this->constrainElement($builder, $query, $like, $kind, $dimensionId);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->limit($limit + 1)
|
||||
->get();
|
||||
|
||||
foreach ($elements as $version) {
|
||||
$row = $this->rowForTarget('element:'.$version->id, $exceptCompositionId);
|
||||
|
||||
if ($row !== null) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($kind, ['alle', 'modul'], true)) {
|
||||
$versions = CompositionVersion::query()
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->where('composition_id', '!=', $exceptCompositionId)
|
||||
->with('composition.editorialContentKind')
|
||||
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
||||
if ($kind === 'modul') {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
}
|
||||
|
||||
if ($dimensionId > 0) {
|
||||
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
|
||||
}
|
||||
|
||||
if ($query === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('designation', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
});
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->limit($limit + 1)
|
||||
->get();
|
||||
|
||||
foreach ($versions as $version) {
|
||||
$row = $this->rowForTarget('composition:'.$version->id, $exceptCompositionId);
|
||||
|
||||
if ($row !== null) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'items' => array_slice($rows, 0, $limit),
|
||||
'more' => count($rows) > $limit,
|
||||
];
|
||||
}
|
||||
|
||||
public function tone(string $outputClass, string $kindLabel): string
|
||||
{
|
||||
$value = mb_strtolower($outputClass.' '.$kindLabel);
|
||||
|
||||
return match (true) {
|
||||
str_contains($value, 'film') => 'film',
|
||||
str_contains($value, 'hör'), str_contains($value, 'audio') => 'audio',
|
||||
str_contains($value, 'dokument'), str_contains($value, 'pdf') => 'dokument',
|
||||
str_contains($value, 'modul'), str_contains($value, 'programm') => 'modul',
|
||||
default => 'text',
|
||||
};
|
||||
}
|
||||
|
||||
public function cardUrl(string $kind, int $id, ?string $path): ?string
|
||||
{
|
||||
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return route('editorial.card', ['kind' => $kind, 'subject' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<ContentElement> $builder
|
||||
*/
|
||||
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId): void
|
||||
{
|
||||
$outputs = match ($kind) {
|
||||
'film' => ['film'],
|
||||
'text' => ['text'],
|
||||
'dokument' => ['pdf', 'document'],
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($outputs !== null) {
|
||||
$builder->whereIn('output_class', $outputs);
|
||||
}
|
||||
|
||||
if ($dimensionId > 0) {
|
||||
$builder->whereIn('id', $this->dimensionSubjectIds(ContentElement::class, $dimensionId));
|
||||
}
|
||||
|
||||
if ($query === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('working_title', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('summary', 'like', $like)
|
||||
->orWhere('description', 'like', $like);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $class
|
||||
* @return list<int>
|
||||
*/
|
||||
private function dimensionSubjectIds(string $class, int $dimensionId): array
|
||||
{
|
||||
return IdentityDimensionValue::query()
|
||||
->where('subject_type', (new $class)->getMorphClass())
|
||||
->where('editorial_dimension_value_id', $dimensionId)
|
||||
->where('origin', 'direkt')
|
||||
->pluck('subject_id')
|
||||
->map(fn (mixed $id): int => (int) $id)
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{target: string, label: string}>
|
||||
*/
|
||||
@@ -284,15 +437,18 @@ public function stand(Composition $composition): array
|
||||
$release = app(CompositionDisplayRelease::class);
|
||||
$released = $ready->first(fn (CompositionVersion $version): bool => $release->isReleased($version));
|
||||
|
||||
$draft = is_array($composition->working_draft) && $composition->working_draft !== [];
|
||||
|
||||
if (! $latest instanceof CompositionVersion) {
|
||||
return [
|
||||
'text' => 'Noch ohne Fassung',
|
||||
'text' => $draft ? 'Entwurf gespeichert' : 'Noch ohne Fassung',
|
||||
'number' => null,
|
||||
'released_number' => $released instanceof CompositionVersion ? $released->number : null,
|
||||
];
|
||||
}
|
||||
|
||||
$text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht freigegeben');
|
||||
$text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht zur Anzeige freigegeben');
|
||||
$text = ($draft ? 'Entwurf gespeichert. ' : '').$text;
|
||||
|
||||
if ($released instanceof CompositionVersion && $released->number !== $latest->number) {
|
||||
$text .= '. Angezeigt wird Fassung '.$released->number;
|
||||
|
||||
Reference in new issue
Block a user