add('qm', fn (User $user) => [ * ['title' => '„Urlaubsregelung“ lesen und bestätigen', 'url' => '/qm/lesen/12', * 'meta' => 'Qualitätsmanagement', 'icon' => 'shield-check', 'due' => '2026-10-02'], * ]); * * Nur, was Handlung braucht (bestätigen, abstimmen, freigeben, annehmen) – keine Hinweise. * Gesperrte Plugins (Administration → Plugins → „Zugang“) liefern nichts; Fehler eines * Anbieters legen die Liste nicht lahm. */ class Tasks { /** @var array */ private array $providers = []; public function __construct() { // Redaktion: Freigaben und Anfragen, die in einem Bereich warten $this->add('editorial', function (User $user) { return collect(app(Editorial::class)->menu($user)) ->filter(fn (array $section) => $section['todo'] !== null) ->map(fn (array $section) => [ // Die Texte sind für „3 warten auf Freigabe“ gedacht 'title' => $section['todo']['count'].' '.$section['todo']['label'], 'meta' => 'Redaktion · '.$section['label'], 'url' => '/redaktion?bereich='.$section['key'], 'icon' => $section['icon'], ])->values()->all(); }, sort: 90); } /** * @param Closure(User): iterable $items */ public function add(string $key, Closure $items, int $sort = 50): void { $this->providers[$key] = ['sort' => $sort, 'items' => $items]; } public function remove(string $key): void { unset($this->providers[$key]); } /** * @return list */ public function forUser(User $user): array { $access = app(PluginAccess::class); $today = CarbonImmutable::today(); $tasks = []; foreach (collect($this->providers)->sortBy('sort') as $key => $provider) { if ($key !== 'editorial' && ! $access->allows($key, $user)) { continue; } try { foreach (($provider['items'])($user) as $item) { if (! is_array($item) || blank($item['title'] ?? null) || blank($item['url'] ?? null)) { continue; } $due = filled($item['due'] ?? null) ? CarbonImmutable::parse($item['due'])->startOfDay() : null; $tasks[] = [ 'key' => $key, 'title' => (string) $item['title'], 'url' => (string) $item['url'], 'meta' => (string) ($item['meta'] ?? ''), 'icon' => Icons::has($item['icon'] ?? null) ? $item['icon'] : (Navigation::DEFAULT_ICONS[explode('.', $key)[0]] ?? 'circle-check'), 'due' => $due?->toDateString(), 'overdue' => $due !== null && $due->lt($today), 'count' => isset($item['count']) ? (int) $item['count'] : null, ]; } } catch (Throwable $e) { Log::error("Aufgaben aus {$key}: ".$e->getMessage(), ['exception' => $e]); } } // Fällige zuerst (nach Datum), dann der Rest in der Reihenfolge der Anbieter return collect($tasks) ->sortBy(fn (array $task, int $index) => [$task['due'] === null ? 1 : 0, $task['due'] ?? '', $index]) ->values()->all(); } }