Remplace le système de notifications stockées par un système de providers qui dérivent les notifications des données existantes (commentaires, réponses, demandes de projet, demandes de rendez-vous, validations de brief). - Ajout du NotificationCollector et de l'interface NotificationProvider - Création de 5 providers : Comment, Reply, ProjectRequest, AppointmentRequest, Content - Métadonnées de notifications stockées directement sur les entités source - Nouvelles routes mark-as-read et mark-all-read - Mise à jour du frontend pour le nouveau système - Route de migration pour les données existantes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
if (!$kirby->user()) {
|
|
return json_encode([
|
|
'page' => $genericData,
|
|
'user' => []
|
|
]);
|
|
}
|
|
|
|
// Récupérer le collector de notifications
|
|
$notificationCollector = $kirby->option('adrienpayet.pdc-notifications.collector');
|
|
|
|
function getProjectData($project, $user, $collector)
|
|
{
|
|
// Utiliser le nouveau système de notifications dérivées
|
|
$notifications = [];
|
|
if ($collector) {
|
|
try {
|
|
$notifications = $collector->collect($project, $user);
|
|
} catch (\Throwable $e) {
|
|
error_log("Error collecting notifications for project {$project->uri()}: " . $e->getMessage());
|
|
$notifications = [];
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'title' => $project->title()->value(),
|
|
'url' => $project->url(),
|
|
'uri' => '/' . $project->uri(),
|
|
'modified' => $project->modified('Y-MM-d'),
|
|
'currentStep' => $project->currentStep()->value(),
|
|
'status' => $project->status(),
|
|
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
|
'steps' => $project->getSteps(),
|
|
'notifications' => $notifications,
|
|
'uuid' => (string) $project->uuid(),
|
|
'slug' => (string) $project->slug(),
|
|
'isDTLEnabled' => $project->isDTLEnabled()->isTrue(),
|
|
'hasOptimizationRequest' => $project->hasOptimizationRequest()->isTrue(),
|
|
];
|
|
|
|
if ($project->isDTLEnabled()) {
|
|
$data['designToLight'] = processDTLProposals($project);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
$currentUser = $kirby->user();
|
|
|
|
try {
|
|
$children = $currentUser->role() == 'admin'
|
|
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project, $currentUser, $notificationCollector))->values()
|
|
: $currentUser->projects()->toPages()->map(fn($project) => getProjectData($project, $currentUser, $notificationCollector))->values();
|
|
} catch (\Throwable $th) {
|
|
throw new Exception($th->getMessage() . ' line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
|
|
$children = [];
|
|
}
|
|
|
|
$specificData = [
|
|
'children' => $children,
|
|
];
|
|
|
|
$pageData = array_merge($genericData, $specificData);
|
|
|
|
echo json_encode([
|
|
'page' => $pageData,
|
|
'user' => $userData,
|
|
]);
|