DTL : optimization appointment request working
This commit is contained in:
parent
11657a5589
commit
54af78e32c
8 changed files with 132 additions and 25 deletions
|
|
@ -3,6 +3,15 @@ label: Design to Light
|
|||
icon: leaf
|
||||
|
||||
fields:
|
||||
hasOptimizationRequest:
|
||||
type: hidden
|
||||
default: "false"
|
||||
optimizationRequestDetails:
|
||||
label: Demande de rendez-vous
|
||||
type: textarea
|
||||
disabled: true
|
||||
when:
|
||||
hasOptimizationRequest: "true"
|
||||
isDTLEnabled:
|
||||
label: Actif
|
||||
type: toggle
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ return [
|
|||
require(__DIR__ . '/routes/upload-pdf.php'),
|
||||
require(__DIR__ . '/routes/validate-brief.php'),
|
||||
require(__DIR__ . '/routes/request-project-creation.php'),
|
||||
require(__DIR__ . '/routes/request-optimization-appointment.php'),
|
||||
],
|
||||
'hooks' => [
|
||||
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => 'request-optimization-appointment.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$user = kirby()->user();
|
||||
$project = page($data->projectUri);
|
||||
|
||||
try {
|
||||
$newProject = $project->update([
|
||||
"hasOptimizationRequest" => "true",
|
||||
"optimizationRequestDetails" => esc("De la part de " . kirby()->user()->name() . " (" . kirby()->user()->email() . ") : \n\n" . "Objet : " . $data->subject . "\n" . $data->details)
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => "Can't update project " . $project->title()->value() . ". " . $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine()
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$date = new DateTime();
|
||||
$formattedDate = $date->format(DateTime::ISO8601);
|
||||
|
||||
$notificationData = [
|
||||
"location" => [
|
||||
"page" => $newProject
|
||||
],
|
||||
"date" => (string) $formattedDate,
|
||||
"text" => nl2br(esc($data->details)),
|
||||
"author" => $user,
|
||||
"id" => Str::uuid(),
|
||||
"type" => "appointment-request",
|
||||
];
|
||||
|
||||
$newProject->createNotification($notificationData);
|
||||
|
||||
return [
|
||||
"status" => "success",
|
||||
];
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => "Can't create notification. " . $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine()
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue