43 lines
No EOL
1.1 KiB
PHP
43 lines
No EOL
1.1 KiB
PHP
<?php
|
|
|
|
use adrienpayet\comments\Reply;
|
|
|
|
return [
|
|
'pattern' => '(:all)reply-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());
|
|
|
|
$data = [
|
|
'page' => $page,
|
|
'parentId' => $data->parentId,
|
|
'file' => $file,
|
|
'filePageIndex' => $data->filePageIndex,
|
|
'text' => $data->text,
|
|
'user' => $user,
|
|
'date' => (string) $data->date,
|
|
'id' => $data->id,
|
|
'type' => 'comment'
|
|
];
|
|
|
|
$newReply = new Reply($data);
|
|
|
|
$comments[$newReply->parentId()]['replies'][$newReply->id()] = $newReply->toArray();
|
|
|
|
$newFile = $file->update([
|
|
'comments' => $comments
|
|
]);
|
|
|
|
$user->sendNotification('comments', $newReply->toArray());
|
|
|
|
return getFileData($newFile);
|
|
}
|
|
]; |