Mache den Aufbau von Modulen und Programmen im Arbeitsplatz bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
30833f62a1
commit
a7feef2cd2
15 files changed
+2068
-328
No files matched your search
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EditorialPreviewController extends Controller
|
||||
{
|
||||
public function show(Composition $composition, ?CompositionVersion $version = null): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
if ($version === null) {
|
||||
$version = $composition->versions()
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
}
|
||||
|
||||
abort_unless($version instanceof CompositionVersion, 404);
|
||||
abort_unless((int) $version->composition_id === (int) $composition->id, 404);
|
||||
abort_unless($version->status === ContentVersionStatus::Bereit, 404);
|
||||
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
|
||||
return view('filament.editorial.preview', [
|
||||
'title' => $catalog->compositionTitle($composition),
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->deskLabel()),
|
||||
'learningGoal' => $version->learning_goal,
|
||||
'durationMinutes' => $version->duration_minutes,
|
||||
'materialNote' => $version->material_note,
|
||||
'number' => $version->number,
|
||||
'backUrl' => $catalog->editUrl($composition),
|
||||
'nodes' => array_map(
|
||||
fn (StructureNode $node): array => $this->present($node, $catalog),
|
||||
app(CompositionStructureReader::class)->tree($version),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(StructureNode $node, EditorialCatalog $catalog): array
|
||||
{
|
||||
$versionLabel = null;
|
||||
$openUrl = null;
|
||||
|
||||
if ($node->contentElementVersionId !== null) {
|
||||
$version = ContentElementVersion::query()->find($node->contentElementVersionId);
|
||||
$versionLabel = $version instanceof ContentElementVersion ? 'Fassung '.$version->number : null;
|
||||
$openUrl = $version instanceof ContentElementVersion ? route('content.preview', $version) : null;
|
||||
}
|
||||
|
||||
if ($node->compositionVersionId !== null) {
|
||||
$version = CompositionVersion::query()->find($node->compositionVersionId);
|
||||
$versionLabel = $version instanceof CompositionVersion ? 'Fassung '.$version->number : $versionLabel;
|
||||
}
|
||||
|
||||
return [
|
||||
'role' => $node->role,
|
||||
'title' => $node->title,
|
||||
'kind' => $node->editorialKindLabel ?: ($node->outputClass !== null ? $catalog->outputLabel($node->outputClass) : $node->technicalKindLabel),
|
||||
'version' => $versionLabel,
|
||||
'open_url' => $openUrl,
|
||||
'children' => array_map(
|
||||
fn (StructureNode $child): array => $this->present($child, $catalog),
|
||||
$node->children,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private function authorizeStaff(): void
|
||||
{
|
||||
$user = auth('staff')->user();
|
||||
abort_unless(
|
||||
$user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
|
||||
403,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user