label('Rechteprofil anlegen') ->modalHeading('Neues Rechteprofil') ->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.') ->modalSubmitActionLabel('Rechteprofil anlegen') ->schema([ TextInput::make('name')->label('Name')->required(), Select::make('purpose')->label('Zweck')->options([ 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell', ])->required(), CheckboxList::make('capabilities')->label('Fähigkeiten')->options(CatalogLabels::FAEHIGKEITEN)->required(), ])->action(function (array $data): void { $this->report(function () use ($data): void { $capabilities = []; foreach ($data['capabilities'] as $entry) { [$class, $action] = explode(':', $entry, 2); $capabilities[$class][] = $action; } app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities); }, 'Das Rechteprofil ist angelegt.'); }), ]; } protected function catalogRows(): array { $rows = []; foreach (RightsProfile::query()->with('versions')->orderBy('name')->get() as $profile) { $version = $profile->versions->sortByDesc('number')->first(); $faehigkeiten = CatalogLabels::faehigkeiten($version?->capabilities); $purpose = CatalogLabels::zweck($version?->purpose); $chips = $version === null ? [['label' => 'Noch keine Fassung', 'ton' => 'offen']] : [['label' => 'Fassung '.$version->number, 'ton' => 'neutral'], ['label' => $purpose, 'ton' => 'leise']]; if ($version?->locked_at !== null) { $chips[] = ['label' => 'Festgeschrieben', 'ton' => 'leise']; } $url = RightsProfileResource::getUrl('view', ['record' => $profile]); $rows[] = [ 'schluessel' => 'r'.$profile->id, 'titel' => $profile->name, 'meta' => 'Rechteprofil', 'text' => $faehigkeiten === [] ? 'Keine Fähigkeiten' : implode(', ', $faehigkeiten), 'symbol' => 'schluessel', 'url' => $url, 'chips' => $chips, 'zustand' => [(string) $version?->purpose], 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], ]; } return $rows; } protected function zustandOptionen(): array { return ['alle' => 'Jeder Zweck', 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell']; } protected function einheit(): array { return ['Rechteprofil', 'Rechteprofile']; } protected function leer(): array { return ['titel' => 'Noch keine Rechteprofile', 'text' => 'Mit „Rechteprofil anlegen“ oben entsteht das erste Profil.']; } }