2025-01-23 15:31:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'pattern' => 'request-project-creation.json',
|
|
|
|
|
'method' => 'POST',
|
|
|
|
|
'action' => function () {
|
|
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
|
$data = json_decode($json);
|
|
|
|
|
|
2025-01-23 16:16:51 +01:00
|
|
|
$user = kirby()->user();
|
|
|
|
|
|
2025-01-23 15:31:15 +01:00
|
|
|
$client = kirby()->user()->client()->toPage()->uuid();
|
|
|
|
|
|
2026-01-15 10:31:31 +01:00
|
|
|
$date = new DateTime();
|
|
|
|
|
$formattedDate = $date->format(DateTime::ISO8601);
|
|
|
|
|
|
2025-01-23 15:31:15 +01:00
|
|
|
$projectData = [
|
|
|
|
|
"slug" => esc(Str::slug($data->title)),
|
2026-01-15 10:31:31 +01:00
|
|
|
"template" => "project",
|
2025-01-23 15:31:15 +01:00
|
|
|
"content" => [
|
|
|
|
|
"title" => esc($data->title),
|
2026-01-15 10:31:31 +01:00
|
|
|
"requestDetails" => esc("Demande de " . $user->name() . " (" . $user->email() . ") : \n\n" . $data->details),
|
2025-01-23 15:31:15 +01:00
|
|
|
"client" => [$client],
|
|
|
|
|
"isClientRequest" => "true",
|
2026-01-15 10:31:31 +01:00
|
|
|
"isDTLEnabled" => esc($data->isDTLEnabled),
|
|
|
|
|
// Métadonnées pour le système de notifications dérivées
|
|
|
|
|
"requestAuthor" => (string) $user->uuid(),
|
|
|
|
|
"requestAuthorName" => (string) $user->name(),
|
|
|
|
|
"requestAuthorEmail" => (string) $user->email(),
|
|
|
|
|
"requestDate" => $formattedDate,
|
|
|
|
|
"requestReadby" => [],
|
2025-01-23 15:31:15 +01:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$projects = page("projects");
|
|
|
|
|
try {
|
2025-01-23 16:16:51 +01:00
|
|
|
$newProject = $projects->createChild($projectData);
|
|
|
|
|
|
2026-01-15 10:31:31 +01:00
|
|
|
// Note: Les notifications sont maintenant dérivées.
|
|
|
|
|
// Plus besoin d'appeler createNotification().
|
2025-01-23 16:16:51 +01:00
|
|
|
|
2025-01-23 15:31:15 +01:00
|
|
|
return [
|
|
|
|
|
"status" => "success",
|
|
|
|
|
];
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return [
|
|
|
|
|
"status" => "error",
|
|
|
|
|
"message" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine()
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|