designtopack/public/site/config/routes/validate-brief.php
2024-11-22 09:53:58 +01:00

52 lines
1.4 KiB
PHP

<?php
return [
'pattern' => 'validate-brief.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
$brief = page($data->briefUri);
$project = $brief->parent();
$href = $data->dialogUri ? $data->dialogUri : $brief->url();
try {
$newPage = $brief->update([
'isValidated' => 'true'
]);
$timezone = new DateTimeZone('Europe/Paris');
$dateTime = new DateTime('now', $timezone);
$notification = [
'location' => [
'href' => (string) $href,
'project' => [
'title' => (string) $project->title(),
'uri' => (string) $project->url()
]
],
'date' => $dateTime->format('Y-m-d\TH:i:sP'),
'author' => [
'name' => (string) kirby()->user()->name(),
'email' => (string) kirby()->user()->email(),
'uuid' => (string) kirby()->user()->uuid(),
'role' => (string) kirby()->user()->role(),
],
'type' => 'content'
];
kirby()->user()->sendNotification($project, $notification);
return [
"success" => "'" . $project->title()->value() . "' brief validated."
];
} catch (\Throwable $th) {
return [
"error" => "Can't validate '" . $brief->title()->value() . "' brief.",
'details' => $th->getMessage()
];
}
}
];