designtopack/public/site/templates/projects.json.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2024-09-04 11:28:12 +02:00
<?php
if (!$kirby->user()) {
return json_encode([
'page' => $genericData,
'user' => []
]);
}
function getProjectData($project, $user)
{
// Utiliser getNotificationsLight() avec cache pour optimiser les performances
$notifications = [];
try {
$notifications = $project->getNotificationsLight($user);
} catch (\Throwable $e) {
error_log("Error getting notifications for project {$project->uri()}: " . $e->getMessage());
$notifications = [];
}
2025-01-23 17:39:40 +01:00
$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(),
];
2025-01-23 17:39:40 +01:00
if ($project->isDTLEnabled()) {
$data['designToLight'] = processDTLProposals($project);
}
2025-01-23 17:39:40 +01:00
return $data;
2024-11-21 16:51:35 +01:00
}
2024-09-04 11:28:12 +02:00
$currentUser = $kirby->user();
2024-11-21 16:51:35 +01:00
try {
$children = $currentUser->role() == 'admin'
? $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);
$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 = [
'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([
'page' => $pageData,
'user' => $userData,
2024-10-28 15:33:52 +01:00
]);