47 lines
No EOL
1.2 KiB
PHP
47 lines
No EOL
1.2 KiB
PHP
<?php
|
|
|
|
return [
|
|
'pattern' => '(:all)create-comment.json',
|
|
'method' => 'POST',
|
|
'action' => function () {
|
|
$json = file_get_contents('php://input');
|
|
$data = json_decode($json);
|
|
|
|
$page = page($data->pageUri);
|
|
$file = $page->file($data->fileName);
|
|
$user = kirby()->user($data->userUuid);
|
|
|
|
|
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
|
|
|
$newComment = [
|
|
'pageUri' => $data->pageUri,
|
|
'fileUuid' => (string) $file->uuid(),
|
|
'filePageIndex' => $data->filePageIndex,
|
|
'position' => [
|
|
'x' => null,
|
|
'y' => null
|
|
],
|
|
'replies' => [],
|
|
'text' => $data->text,
|
|
'user' => [
|
|
'name' => (string) $user->name(),
|
|
'email' => (string) $user->email(),
|
|
'uuid' => (string) $user->uuid(),
|
|
'role' => (string) $user->role()
|
|
],
|
|
'date' => (string) $data->date,
|
|
'id' => $data->id,
|
|
];
|
|
|
|
$comments[$data->id] = $newComment;
|
|
|
|
$newFile = $file->update([
|
|
'comments' => $comments
|
|
]);
|
|
|
|
// $user->sendNotification('comments', $newComment);
|
|
|
|
return getFileData($newFile);
|
|
}
|
|
]; |