, 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> */ 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> */ 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))); } }