2026-01-15 10:31:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Route pour marquer toutes les notifications comme lues.
|
|
|
|
|
* Parcourt tous les projets accessibles à l'utilisateur.
|
|
|
|
|
*/
|
|
|
|
|
return [
|
|
|
|
|
'pattern' => '(:all)mark-all-notifications-read.json',
|
|
|
|
|
'method' => 'POST',
|
|
|
|
|
'action' => function () {
|
|
|
|
|
try {
|
|
|
|
|
$user = kirby()->user();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
throw new Exception('User not authenticated');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$collector = kirby()->option('adrienpayet.pdc-notifications.collector');
|
|
|
|
|
if (!$collector) {
|
|
|
|
|
throw new Exception('NotificationCollector not initialized');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Récupérer les projets selon le rôle
|
|
|
|
|
if ($user->role()->name() === 'admin') {
|
|
|
|
|
$projects = page('projects')->children()->toArray();
|
|
|
|
|
} else {
|
2026-03-03 14:01:27 +01:00
|
|
|
$projects = $user->currentProjects()->toArray();
|
2026-01-15 10:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$count = $collector->markAllAsRead($projects, $user);
|
|
|
|
|
|
|
|
|
|
return json_encode([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => "$count notifications marked as read"
|
|
|
|
|
]);
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return json_encode([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => $th->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|