All checks were successful
Deploy Preprod / Build and Deploy to Preprod (push) Successful in 31s
Le champ `users` est désormais sur le blueprint projet. Les blueprints pochet/client perdent leur champ `projects`. La logique PHP (user-projects, managers, controller, template, mark-all-read) lit project.users au lieu de user.projects. Script de migration inclus. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?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 {
|
|
$projects = $user->currentProjects()->toArray();
|
|
}
|
|
|
|
$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()
|
|
]);
|
|
}
|
|
}
|
|
];
|