comment 360 working

This commit is contained in:
isUnknown 2024-12-19 17:11:46 +01:00
parent bc0ae8861f
commit 4daaa3dc88
8 changed files with 134 additions and 91 deletions

View file

@ -9,17 +9,11 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
$parsedUrl = parse_url($data->dialogUri);
$query = $parsedUrl['query'] ?? null;
parse_str($query, $queryParams);
$stepSlug = $queryParams['dialog'] ?? null;
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
$project = page($parsedUrl['path']);
$page = page($targetPageUri);
$page = page($data->fileParentUri);
$project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent();
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
@ -41,13 +35,13 @@ return [
"type" => "comment",
];
if ($data->position->pageIndex) {
if (isset($data->position->pageIndex)) {
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
}
$newComment = new Comment($commentData);
$comments[] = $newComment->toArray();
$comments[] = $newComment->toArray();
$newFile = $file->update([
'comments' => $comments

View file

@ -19,7 +19,7 @@ function getFileData($file) {
$data['tags'] = $file->tags()->split();
};
if($file->extension() == "pdf") {
if($file->comments()->exists()) {
$data['comments'] = $file->comments()->exists() && $file->comments() ? Data::decode($file->comments()->value(), 'yaml') : [];
$data['cover'] = $file->cover()->exists() && $file->cover()->isNotEmpty() ? $file->cover()->toFile()->resize(576)->url() : false;
}