Meine Aufgaben (0.53.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 7m6s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 13s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 7m24s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 8m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m39s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m42s

Tasks-Registry mit Anbietern aus QM, Umfragen und Redaktion; Kachel auf der
Startseite und Seite /aufgaben.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-29 19:42:53 +00:00
parent 63f50f691a
commit c11cf4e0c4
146 changed files with 731 additions and 353 deletions

104
app/Tasks/Tasks.php Normal file
View file

@ -0,0 +1,104 @@
<?php
namespace App\Tasks;
use App\Editorial\Editorial;
use App\Models\User;
use App\Plugins\PluginAccess;
use App\Support\Icons;
use App\Support\Navigation;
use Carbon\CarbonImmutable;
use Closure;
use Illuminate\Support\Facades\Log;
use Throwable;
/**
* „Meine Aufgaben“: was jetzt auf eine Person wartet – an einer Stelle gesammelt.
* Kern und Plugins melden ihre offenen Punkte an:
*
* app(Tasks::class)->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<string, array{sort: int, items: Closure}> */
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<array{title: string, url: string, meta?: string, icon?: string, due?: string|null, count?: int}> $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<array{key: string, title: string, url: string, meta: string, icon: string, due: string|null, overdue: bool, count: int|null}>
*/
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();
}
}