133 lines
3.7 KiB
PHP
133 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Support\EditorialCatalog;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Livewire\Attributes\Url;
|
|
|
|
class EditorialDesk extends Page
|
|
{
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
|
|
|
protected static ?string $navigationLabel = 'Arbeitsplatz';
|
|
|
|
protected static ?int $navigationSort = 0;
|
|
|
|
protected static ?string $slug = 'arbeitsplatz';
|
|
|
|
protected static ?string $title = 'Arbeitsplatz';
|
|
|
|
protected string $view = 'filament.editorial.desk-page';
|
|
|
|
#[Url]
|
|
public string $query = '';
|
|
|
|
#[Url]
|
|
public string $kindFilter = 'alle';
|
|
|
|
public string $programName = '';
|
|
|
|
public string $moduleName = '';
|
|
|
|
public string $feedback = '';
|
|
|
|
public function getHeading(): string|Htmlable|null
|
|
{
|
|
return 'Programme und Module';
|
|
}
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return 'Vorhandene Einträge öffnen oder einen neuen anlegen. Technische Kennungen sind dafür nicht nötig.';
|
|
}
|
|
|
|
public function getMaxContentWidth(): Width|string|null
|
|
{
|
|
return Width::Full;
|
|
}
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
return ContentElementResource::editor();
|
|
}
|
|
|
|
/**
|
|
* @return list<array{title: string, kind: string, stand: string, url: string, summary: string}>
|
|
*/
|
|
public function entries(): array
|
|
{
|
|
$query = trim($this->query);
|
|
$needle = mb_strtolower($query);
|
|
$catalog = app(EditorialCatalog::class);
|
|
$rows = [];
|
|
|
|
$compositions = Composition::query()
|
|
->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung])
|
|
->with(['editorialContentKind', 'versions'])
|
|
->orderBy('designation')
|
|
->get();
|
|
|
|
foreach ($compositions as $composition) {
|
|
$kind = $composition->kind instanceof CompositionKind
|
|
? $composition->kind
|
|
: CompositionKind::from((string) $composition->kind);
|
|
$label = $kind->deskLabel();
|
|
|
|
if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) {
|
|
continue;
|
|
}
|
|
|
|
if ($this->kindFilter === 'modul' && $kind !== CompositionKind::Uebung) {
|
|
continue;
|
|
}
|
|
|
|
$title = $catalog->compositionTitle($composition);
|
|
$haystack = mb_strtolower($title.' '.$composition->designation.' '.(string) $composition->summary);
|
|
|
|
if ($needle !== '' && ! str_contains($haystack, $needle)) {
|
|
continue;
|
|
}
|
|
|
|
$rows[] = [
|
|
'title' => $title,
|
|
'kind' => $label,
|
|
'stand' => $catalog->stand($composition)['text'],
|
|
'url' => EditorialCatalog::editUrl($composition),
|
|
'summary' => (string) ($composition->summary ?? ''),
|
|
];
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
public function createProgram(): void
|
|
{
|
|
$this->create(CompositionKind::Kurs, $this->programName);
|
|
}
|
|
|
|
public function createModule(): void
|
|
{
|
|
$this->create(CompositionKind::Uebung, $this->moduleName);
|
|
}
|
|
|
|
private function create(CompositionKind $kind, string $name): void
|
|
{
|
|
$name = trim($name);
|
|
|
|
if ($name === '') {
|
|
$this->feedback = 'Der Name fehlt.';
|
|
|
|
return;
|
|
}
|
|
|
|
$composition = app(EditorialCatalog::class)->create($name, $kind);
|
|
$this->redirect(EditorialCatalog::editUrl($composition), navigate: false);
|
|
}
|
|
}
|