comments working

This commit is contained in:
isUnknown 2025-01-15 14:18:48 +01:00
parent 375bed1d01
commit 0b472988a2
14 changed files with 107 additions and 59 deletions

View file

@ -7,17 +7,20 @@ class FileDetails
{
public string $uuid;
public string $url;
public string $type;
public function __construct(Kirby\Cms\File $data)
{
$this->uuid = (string) $data->uuid();
$this->url = (string) $data->url();
$this->type = (string) $data->type();
}
public function toArray() {
return [
"uuid" => $this->uuid,
"url" => $this->url
"url" => $this->url,
"type" => $this->type
];
}
}

View file

@ -5,16 +5,16 @@ namespace adrienpayet\D2P\data\location;
class Location
{
protected PageDetails $page;
protected ?string $dialogUri = null;
protected ProjectDetails $project;
// protected ?string $dialogUri = null;
// protected ProjectDetails $project;
protected ?FileDetails $file = null;
protected ?array $parent = null;
public function __construct(array $data)
{
$this->page = new PageDetails($data["page"]);
$this->dialogUri = $data["dialogUri"];
$this->project = new ProjectDetails($data["project"]);
// $this->dialogUri = $data["dialogUri"];
// $this->project = new ProjectDetails($data["project"]);
if (isset($data['file'])) {
$this->file = new FileDetails($data["file"]);
@ -33,12 +33,12 @@ class Location
public function toArray() {
$array = [
"page" => $this->page->toArray(),
"project" => $this->project->toArray(),
// "project" => $this->project->toArray(),
];
if ($this->dialogUri) {
$array["dialogUri"] = $this->dialogUri;
}
// if ($this->dialogUri) {
// $array["dialogUri"] = $this->dialogUri;
// }
if ($this->file) {
$array["file"] = $this->file;

View file

@ -14,6 +14,8 @@ class PageDetails
public function toArray() {
return [
"uuid" => (string) $this->page->uuid(),
"template" => (string) $this->page->template(),
"uri" => (string) $this->page->uri(),
"title" => (string) $this->page->title(),
];

View file

@ -21,7 +21,6 @@ return [
"location" => [
"page" => $page,
"project" => $project,
"dialogUri" => $data->dialogUri,
"file" => $file
],
"position" => [

View file

@ -8,12 +8,11 @@ return [
$data = json_decode($json);
$page = page($data->location->page->uri);
$project = page($data->location->project->uri);
$file = $page->file($data->location->file->uuid);
$isReply = $data->location->parent->id ?? false;
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
$isReply = $data->location->parent->id ?? false;
foreach ($comments as $key => &$comment) {
if ($isReply) {
if ($comment['id'] === $data->location->parent->id) {
@ -39,6 +38,7 @@ return [
echo json_encode(getFileData($newFile));
$project = $page->parents()->findBy("template", "project");
$project->deleteNotification($data->id);
exit;

View file

@ -10,10 +10,8 @@ return [
$data = json_decode($json);
$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());
foreach ($comments as &$comment) {
@ -22,8 +20,6 @@ return [
$replyData = [
"location" => [
"page" => $page,
"project" => $project,
"dialogUri" => $data->dialogUri,
"file" => $file,
"parent" => $comment
],
@ -45,7 +41,8 @@ return [
'comments' => $comments
]);
$user->sendNotification($project, $replyData);
$project = $page->parents()->findBy("template", "project");
$project->createNotification($replyData);
return getFileData($newFile);
}

View file

@ -8,7 +8,7 @@ return [
$data = json_decode($json);
try {
$project = page($data->projectUuid);
$project = page($data->projectId);
$project->readNotification($data->notificationId);
return json_encode([
"status" => "success"