Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 9m9s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 9m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 10m30s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 11m5s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m15s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m54s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m57s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m20s
Übersichtsseiten /wissen und /service (Hubs, im Admin pflegbar), Baustein „Mitglieder mit Rolle“, Menü-Vorschlag für die Mitarbeiter-App. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
96 lines
5 KiB
PHP
96 lines
5 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
use App\Feed\Feed;
|
||
use App\Models\User;
|
||
use App\Plugins\PluginAccess;
|
||
use Illuminate\Support\Facades\Route;
|
||
|
||
/**
|
||
* Übersichtsseiten „Wissen“ (/wissen) und „Service“ (/service): Kacheln zu den Bereichen
|
||
* bzw. Anlaufstellen des Hauses – jeweils mit Ansprechperson. Die Administration pflegt sie
|
||
* unter Startseite & Menü → Wissen & Service; ohne eigene Pflege gilt ein Vorschlag aus den
|
||
* vorhandenen Bereichen.
|
||
*
|
||
* Je Kachel: Titel, Text, Symbol, Adresse, Knopf, Ansprechperson, „Sichtbar für“ und – bei
|
||
* Vorschlägen – das Plugin, zu dem sie gehört (gesperrt → Kachel entfällt).
|
||
*/
|
||
class Hubs
|
||
{
|
||
public const HUBS = ['wissen', 'service'];
|
||
|
||
public function __construct(private readonly Settings $settings) {}
|
||
|
||
/**
|
||
* Gespeicherte Kacheln – oder der Vorschlag.
|
||
*
|
||
* @return list<array{title: string, text: string, icon: string, url: string, action: string, person: int|null, roles: list<int>, plugin: string|null}>
|
||
*/
|
||
public function entries(string $hub): array
|
||
{
|
||
$stored = $this->settings->get("hubs.{$hub}");
|
||
|
||
return array_values(array_map(fn (array $entry) => [
|
||
'title' => (string) ($entry['title'] ?? ''),
|
||
'text' => (string) ($entry['text'] ?? ''),
|
||
'icon' => Icons::has($entry['icon'] ?? null) ? $entry['icon'] : 'link',
|
||
'url' => preg_match('#^(https?://|/)#i', (string) ($entry['url'] ?? '')) ? (string) $entry['url'] : '#',
|
||
'action' => (string) ($entry['action'] ?? ''),
|
||
'person' => filled($entry['person'] ?? null) ? (int) $entry['person'] : null,
|
||
'roles' => array_values(array_map('intval', array_filter((array) ($entry['roles'] ?? []), 'is_numeric'))),
|
||
'plugin' => filled($entry['plugin'] ?? null) ? (string) $entry['plugin'] : null,
|
||
], array_filter(is_array($stored) ? $stored : $this->suggestion($hub), fn ($entry) => is_array($entry) && filled($entry['title'] ?? null))));
|
||
}
|
||
|
||
/**
|
||
* Für eine Person: gefiltert nach Rolle und gesperrten Bereichen, Ansprechperson aufgelöst.
|
||
*
|
||
* @return list<array<string, mixed>>
|
||
*/
|
||
public function forUser(string $hub, User $user): array
|
||
{
|
||
$roleIds = $user->roles()->pluck('roles.id')->map(fn ($id) => (int) $id)->all();
|
||
$access = app(PluginAccess::class);
|
||
$entries = array_filter($this->entries($hub), fn (array $entry) => ($entry['roles'] === [] || array_intersect($entry['roles'], $roleIds) !== [])
|
||
&& ($entry['plugin'] === null || $access->allows($entry['plugin'], $user)));
|
||
$people = User::query()->active()->whereIn('id', array_filter(array_column($entries, 'person')))->get()->keyBy('id');
|
||
|
||
return array_values(array_map(fn (array $entry) => [
|
||
'title' => $entry['title'],
|
||
'text' => $entry['text'],
|
||
'icon' => $entry['icon'],
|
||
'url' => $entry['url'],
|
||
'action' => $entry['action'],
|
||
'person' => $entry['person'] ? Feed::person($people->get($entry['person'])) : null,
|
||
], $entries));
|
||
}
|
||
|
||
/**
|
||
* Vorschlag aus den vorhandenen Bereichen.
|
||
*
|
||
* @return list<array<string, mixed>>
|
||
*/
|
||
public function suggestion(string $hub): array
|
||
{
|
||
$candidates = $hub === 'wissen' ? [
|
||
['pages.index', 'pages', 'Handbuch', 'Wie wir arbeiten: Organisation, Abläufe, Regeln für den Alltag.', 'book-open'],
|
||
['downloads.index', 'downloads', 'Downloads', 'Vorlagen, Anträge und Infomaterial – immer in der aktuellen Fassung.', 'folder-down'],
|
||
['qm.index', 'qm', 'Qualität', 'Qualitätshandbuch, Verfahrensanweisungen und Formblätter.', 'shield-check'],
|
||
['people.index', null, 'Telefonbuch', 'Wer macht was, wer sitzt wo, wer vertritt wen.', 'contact'],
|
||
['glossary.index', 'glossar', 'Glossar', 'Abkürzungen und Fachbegriffe aus dem Haus.', 'book-a'],
|
||
['forms.index', 'forms', 'Formulare', 'Anträge und Meldungen online ausfüllen.', 'clipboard-list'],
|
||
] : [
|
||
['forms.index', 'forms', 'Anträge und Formulare', 'Urlaub, Fortbildung, Bescheinigungen und mehr – online beantragen.', 'clipboard-list'],
|
||
['verleih.index', 'verleih', 'Bilderverleih', 'Bilder vom Künstlerteam für Flure und Büros.', 'images'],
|
||
['speiseplan.index', 'speiseplan', 'Kantine', 'Speiseplan der Woche.', 'utensils'],
|
||
['ideas.index', 'ideen', 'Ideenbox', 'Verbesserungsvorschläge – jede Idee wird beantwortet.', 'lightbulb'],
|
||
['kleinanzeigen.index', 'kleinanzeigen', 'Kleinanzeigen', 'Suchen, verschenken, verkaufen – unter Kolleginnen und Kollegen.', 'shopping-bag'],
|
||
];
|
||
|
||
return array_values(array_filter(array_map(fn (array $c) => Route::has($c[0]) ? [
|
||
'title' => $c[2], 'text' => $c[3], 'icon' => $c[4], 'url' => route($c[0], absolute: false),
|
||
'action' => '', 'person' => null, 'roles' => [], 'plugin' => $c[1],
|
||
] : null, $candidates)));
|
||
}
|
||
}
|