#68 - create comment create working (notification to adapt)
This commit is contained in:
parent
3d4ddc12fc
commit
cf83edc1e6
11 changed files with 106 additions and 158 deletions
|
|
@ -3,7 +3,14 @@
|
|||
F::loadClasses([
|
||||
'adrienpayet\\comments\\BaseComment' => __DIR__ . '/src/BaseComment.php',
|
||||
'adrienpayet\\comments\\Comment' => __DIR__ . '/src/Comment.php',
|
||||
'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php'
|
||||
'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php',
|
||||
|
||||
'adrienpayet\\D2P\\data\\Position' => __DIR__ . '/../classes/Position.php',
|
||||
'adrienpayet\\D2P\data\Author' => __DIR__ . '/../classes/Author.php',
|
||||
'adrienpayet\\D2P\\data\\location\\Location' => __DIR__ . '/../classes/location/Location.php',
|
||||
'adrienpayet\\D2P\\data\\location\\PageDetails' => __DIR__ . '/../classes/location/PageDetails.php',
|
||||
'adrienpayet\\D2P\\data\\location\\ProjectDetails' => __DIR__ . '/../classes/location/ProjectDetails.php',
|
||||
'adrienpayet\\D2P\\data\\location\\FileDetails' => __DIR__ . '/../classes/location/FileDetails.php',
|
||||
]);
|
||||
|
||||
Kirby::plugin('adrienpayet/kirby4-comments', [
|
||||
|
|
|
|||
|
|
@ -9,49 +9,53 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$parsedUrl = parse_url($data->path);
|
||||
$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);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$data = [
|
||||
'href' => $data->path,
|
||||
'page' => $page,
|
||||
'file' => $file,
|
||||
'position' => [
|
||||
'pageIndex' => $data->position->pageIndex,
|
||||
'x' => $data->position->x,
|
||||
'y' => $data->position->y
|
||||
$commentData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"dialogUri" => $data->dialogUri,
|
||||
"file" => $file
|
||||
],
|
||||
'replies' => [],
|
||||
'text' => $data->text,
|
||||
'author' => $user,
|
||||
'date' => (string) $data->date,
|
||||
'id' => $data->id,
|
||||
'type' => 'comment'
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
"x" => $data->position->x,
|
||||
"y" => $data->position->y
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment",
|
||||
];
|
||||
|
||||
$newComment = new Comment($data);
|
||||
$user->sendNotification($project, $commentData);
|
||||
|
||||
$newComment = new Comment($commentData);
|
||||
|
||||
$comments[] = $newComment->toArray();
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
]);
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
try {
|
||||
$user->sendNotification($page->parent(), $newComment->toArray());
|
||||
$user->sendNotification($project, $commentData);
|
||||
} catch (\Throwable $th) {
|
||||
echo json_encode([
|
||||
"error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(),
|
||||
|
|
|
|||
|
|
@ -1,40 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\comments;
|
||||
use adrienpayet\D2P\data\location\Location;
|
||||
use adrienpayet\D2P\data\Author;
|
||||
|
||||
class BaseComment {
|
||||
protected $href;
|
||||
protected $location;
|
||||
protected $position;
|
||||
protected $replies;
|
||||
protected $text;
|
||||
protected $author;
|
||||
protected $date;
|
||||
protected $id;
|
||||
protected $type;
|
||||
protected $isRead;
|
||||
protected string $type;
|
||||
protected Location $location;
|
||||
protected string $text;
|
||||
protected Author $author;
|
||||
protected string $date;
|
||||
protected string $id;
|
||||
|
||||
public function __construct($data) {
|
||||
$this->type = $data["type"];
|
||||
$this->location = new Location($data["location"]);
|
||||
$this->text = $data["text"];
|
||||
$this->author = new Author($data["author"]);
|
||||
$this->date = $data["date"];
|
||||
$this->id = $data["id"];
|
||||
$this->isRead = "false";
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
'location' => $this->location,
|
||||
'position' => $this->position,
|
||||
'replies' => $this->replies,
|
||||
'text' => $this->text,
|
||||
'author' => $this->author,
|
||||
'date' => $this->date,
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'isRead' => $this->isRead
|
||||
"location" => $this->location->toArray(),
|
||||
"text" => $this->text,
|
||||
"author" => $this->author->toArray(),
|
||||
"date" => $this->date,
|
||||
"id" => $this->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\comments;
|
||||
use adrienpayet\D2P\data\Position;
|
||||
|
||||
class Comment extends BaseComment
|
||||
{
|
||||
protected $position;
|
||||
protected ?Position $position = null;
|
||||
protected string $type = "comment";
|
||||
protected array $replies = [];
|
||||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
$this->position = $data['position'] ?? null;
|
||||
}
|
||||
|
||||
public function position() {
|
||||
return $this->position;
|
||||
if (isset($data["position"])) {
|
||||
$this->position = new Position($data['position']);
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = parent::toArray();
|
||||
$array['position'] = $this->position;
|
||||
$array['type'] = $this->type;
|
||||
$array['replies'] = $this->replies;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue