designtopack/public/site/templates/projects.json.php
isUnknown 19752f516e
All checks were successful
Deploy Production / Build and Deploy to Production (push) Successful in 28s
fix: guard instanceof ProjectPage avant getNotificationsLight
Les projets avec un template non-project déclenchaient le __call magique
de Kirby qui retournait un Field object au lieu de lancer une exception,
cassant l'affichage des notifications côté frontend.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:53:37 +01:00

68 lines
2.3 KiB
PHP

<?php
if (!$kirby->user()) {
return json_encode([
'page' => $genericData,
'user' => []
]);
}
function getProjectData($project, $user)
{
// Utiliser getNotificationsLight() avec cache pour optimiser les performances
$notifications = [];
if ($project instanceof ProjectPage) {
try {
$notifications = $project->getNotificationsLight($user);
} catch (\Throwable $e) {
error_log("Error getting notifications for project {$project->uri()}: " . $e->getMessage());
}
}
$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 {
if ($currentUser->role() == 'admin' && $currentUser->hasNoAssignedProjects()) {
$projectCollection = $page->childrenAndDrafts();
} else {
$projectCollection = $currentUser->currentProjects()->merge($currentUser->archivedProjects());
}
$children = $projectCollection->map(fn($project) => getProjectData($project, $currentUser))->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,
]);