add / show comments working
This commit is contained in:
parent
a9992b0ff5
commit
6bffbc1707
10 changed files with 163 additions and 40 deletions
|
|
@ -6,4 +6,31 @@ Uuid: s0lNtRA0Z7ybTCWG
|
|||
|
||||
----
|
||||
|
||||
Template: document
|
||||
Template: document
|
||||
|
||||
----
|
||||
|
||||
Comments:
|
||||
|
||||
1:
|
||||
m2lmqu2u:
|
||||
text: test
|
||||
username: Adrien Payet
|
||||
date: 2024-10-23T10:46:08+02:00
|
||||
m2lo4obv:
|
||||
text: nouveau commentaire
|
||||
username: Adrien Payet
|
||||
date: 2024-10-23T11:24:53+02:00
|
||||
m2lo6ckw:
|
||||
text: Encore un autre commentaire
|
||||
username: Adrien Payet
|
||||
date: 2024-10-23T11:26:11+02:00
|
||||
2:
|
||||
m2loaj2f:
|
||||
text: Autre commentaire
|
||||
username: Adrien Payet
|
||||
date: 2024-10-23T11:29:26+02:00
|
||||
m2loam7s:
|
||||
text: Autre commentaire
|
||||
username: Adrien Payet
|
||||
date: 2024-10-23T11:29:30+02:00
|
||||
|
|
@ -26,6 +26,7 @@ return [
|
|||
require(__DIR__ . '/routes/save-file.php'),
|
||||
require(__DIR__ . '/routes/remove-file.php'),
|
||||
require(__DIR__ . '/routes/upload-pdf.php'),
|
||||
require(__DIR__ . '/routes/add-comment.php'),
|
||||
],
|
||||
'hooks' => [
|
||||
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
||||
|
|
|
|||
32
public/site/config/routes/add-comment.php
Normal file
32
public/site/config/routes/add-comment.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)add-comment.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
// return json_encode($data->pageUri);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Data::decode($file->comments()->toArray()['comments'], 'yaml');
|
||||
|
||||
$comments[$data->targetPage][$data->id] = [
|
||||
'text' => $data->text,
|
||||
'username' => (string) $user->name(),
|
||||
'date' => (string) $data->date,
|
||||
];
|
||||
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
];
|
||||
|
|
@ -5,7 +5,7 @@ function getFileData($file) {
|
|||
'url' => $file->url(),
|
||||
'uuid' => (string) $file->uuid(),
|
||||
'name' => $file->filename(),
|
||||
'type' => (string) $file->type()
|
||||
'type' => (string) $file->type(),
|
||||
];
|
||||
|
||||
if ($file->description()->exists()) {
|
||||
|
|
@ -13,5 +13,9 @@ function getFileData($file) {
|
|||
$data['tags'] = $file->tags()->split();
|
||||
};
|
||||
|
||||
if($file->comments()->exists()) {
|
||||
$data['comments'] = Data::decode($file->comments()->value(), 'yaml');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue