2024-09-04 11:28:12 +02:00
|
|
|
<?php
|
2025-02-05 11:22:09 +01:00
|
|
|
|
2025-04-30 16:09:24 +02:00
|
|
|
if (!$kirby->user()) {
|
|
|
|
|
return json_encode([
|
|
|
|
|
'page' => $genericData,
|
|
|
|
|
'user' => []
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 11:42:20 +01:00
|
|
|
function getProjectData($project, $user)
|
2026-01-15 10:31:31 +01:00
|
|
|
{
|
2026-01-15 11:42:20 +01:00
|
|
|
// Utiliser getNotificationsLight() avec cache pour optimiser les performances
|
2026-01-15 11:18:59 +01:00
|
|
|
$notifications = [];
|
2026-01-15 11:42:20 +01:00
|
|
|
try {
|
|
|
|
|
$notifications = $project->getNotificationsLight($user);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
error_log("Error getting notifications for project {$project->uri()}: " . $e->getMessage());
|
|
|
|
|
$notifications = [];
|
2026-01-15 11:18:59 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-23 17:39:40 +01:00
|
|
|
$data = [
|
2026-01-15 10:31:31 +01:00
|
|
|
'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(),
|
2026-01-15 11:18:59 +01:00
|
|
|
'notifications' => $notifications,
|
2026-01-15 10:31:31 +01:00
|
|
|
'uuid' => (string) $project->uuid(),
|
|
|
|
|
'slug' => (string) $project->slug(),
|
|
|
|
|
'isDTLEnabled' => $project->isDTLEnabled()->isTrue(),
|
|
|
|
|
'hasOptimizationRequest' => $project->hasOptimizationRequest()->isTrue(),
|
|
|
|
|
];
|
2025-01-23 17:39:40 +01:00
|
|
|
|
2025-02-05 11:22:09 +01:00
|
|
|
if ($project->isDTLEnabled()) {
|
|
|
|
|
$data['designToLight'] = processDTLProposals($project);
|
|
|
|
|
}
|
2025-01-23 17:39:40 +01:00
|
|
|
|
2025-02-05 11:22:09 +01:00
|
|
|
return $data;
|
2024-11-21 16:51:35 +01:00
|
|
|
}
|
2024-09-04 11:28:12 +02:00
|
|
|
|
2026-01-15 11:18:59 +01:00
|
|
|
$currentUser = $kirby->user();
|
|
|
|
|
|
2024-11-21 16:51:35 +01:00
|
|
|
try {
|
2026-01-15 11:18:59 +01:00
|
|
|
$children = $currentUser->role() == 'admin'
|
2026-01-15 11:42:20 +01:00
|
|
|
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project, $currentUser))->values()
|
|
|
|
|
: $currentUser->projects()->toPages()->map(fn($project) => getProjectData($project, $currentUser))->values();
|
2024-11-21 16:51:35 +01:00
|
|
|
} catch (\Throwable $th) {
|
2025-03-26 17:02:23 +01:00
|
|
|
throw new Exception($th->getMessage() . ' line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
|
2025-02-05 11:22:09 +01:00
|
|
|
$children = [];
|
2024-11-21 16:51:35 +01:00
|
|
|
}
|
2024-11-11 17:12:26 +01:00
|
|
|
|
2024-09-04 11:28:12 +02:00
|
|
|
$specificData = [
|
2025-02-05 11:22:09 +01:00
|
|
|
'children' => $children,
|
2024-09-04 11:28:12 +02:00
|
|
|
];
|
|
|
|
|
|
2024-10-28 15:33:52 +01:00
|
|
|
$pageData = array_merge($genericData, $specificData);
|
2024-09-04 11:28:12 +02:00
|
|
|
|
2024-10-28 15:33:52 +01:00
|
|
|
echo json_encode([
|
2025-02-05 11:22:09 +01:00
|
|
|
'page' => $pageData,
|
|
|
|
|
'user' => $userData,
|
2024-10-28 15:33:52 +01:00
|
|
|
]);
|