Merge branch 'notifications'
This commit is contained in:
commit
caf6f721fb
34 changed files with 671 additions and 417 deletions
|
|
@ -6,112 +6,58 @@ Comments:
|
|||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/proposal
|
||||
title: Offre commerciale
|
||||
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
file:
|
||||
uuid: file://3vTh1tMFeFM2JxaN
|
||||
url: file://3vTh1tMFeFM2JxaN
|
||||
url: >
|
||||
http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: "60.110185093015"
|
||||
y: "44.594594594595"
|
||||
replies: [ ]
|
||||
text: test
|
||||
x: "57.105131038425"
|
||||
y: "13.127413127413"
|
||||
text: un commentaire
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
uuid: user://WWjXgPWk
|
||||
role: admin
|
||||
date: 2024-11-28T16:30:56+01:00
|
||||
id: m41h238q
|
||||
date: 2024-12-19T10:26:05+01:00
|
||||
id: e16a5304-330b-4460-acbd-a6e471f4cda2
|
||||
type: comment
|
||||
isRead: false
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/proposal
|
||||
title: Offre commerciale
|
||||
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
file:
|
||||
uuid: file://3vTh1tMFeFM2JxaN
|
||||
url: file://3vTh1tMFeFM2JxaN
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: "26.098441098196"
|
||||
y: "64.864864864865"
|
||||
replies: [ ]
|
||||
text: Nouveau commentaire
|
||||
author:
|
||||
name: Utilisateur Dior
|
||||
email: utilisateur@dior.com
|
||||
uuid: user://HfuumN8s
|
||||
role: client
|
||||
date: 2024-12-04T15:00:15+01:00
|
||||
id: m49ygks2
|
||||
type: comment
|
||||
isRead: false
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/proposal
|
||||
title: Offre commerciale
|
||||
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
file:
|
||||
uuid: file://3vTh1tMFeFM2JxaN
|
||||
url: file://3vTh1tMFeFM2JxaN
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: "64.481172808783"
|
||||
y: "76.447876447876"
|
||||
replies: [ ]
|
||||
text: encore un commentaire
|
||||
author:
|
||||
name: Utilisateur Dior
|
||||
email: utilisateur@dior.com
|
||||
uuid: user://HfuumN8s
|
||||
role: client
|
||||
date: 2024-12-04T15:03:53+01:00
|
||||
id: m49yl8zc
|
||||
type: comment
|
||||
isRead: false
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/proposal
|
||||
title: Offre commerciale
|
||||
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
file:
|
||||
uuid: file://3vTh1tMFeFM2JxaN
|
||||
url: file://3vTh1tMFeFM2JxaN
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: '29.786457814876'
|
||||
y: '83.397683397683'
|
||||
replies: [ ]
|
||||
text: et encore un
|
||||
author:
|
||||
name: Utilisateur Dior
|
||||
email: utilisateur@dior.com
|
||||
uuid: user://HfuumN8s
|
||||
role: client
|
||||
date: 2024-12-04T15:05:10+01:00
|
||||
id: m49ymwuw
|
||||
type: comment
|
||||
isRead: false
|
||||
replies:
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/proposal
|
||||
title: Offre commerciale
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
|
||||
file:
|
||||
uuid: file://3vTh1tMFeFM2JxaN
|
||||
url: >
|
||||
http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
|
||||
parent:
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
id: e16a5304-330b-4460-acbd-a6e471f4cda2
|
||||
position:
|
||||
pageIndex: 1
|
||||
text: une réponse
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
uuid: user://WWjXgPWk
|
||||
role: admin
|
||||
date: 2024-12-19T10:26:09+01:00
|
||||
id: bc64e066-299d-4d80-a651-2c17482cda2f
|
||||
type: comment-reply
|
||||
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Comments:
|
|||
date: 2024-12-03T13:42:18+01:00
|
||||
id: m48g8hrb
|
||||
type: comment
|
||||
isRead: false
|
||||
isread: false
|
||||
-
|
||||
location:
|
||||
page:
|
||||
|
|
@ -53,7 +53,7 @@ Comments:
|
|||
date: 2024-12-03T13:43:08+01:00
|
||||
id: m48g9kau
|
||||
type: comment
|
||||
isRead: false
|
||||
isread: false
|
||||
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -4,4 +4,48 @@ home: /panel/pages/projects
|
|||
|
||||
fields:
|
||||
notifications:
|
||||
type: hidden
|
||||
label: Notifications
|
||||
type: structure
|
||||
fields:
|
||||
type:
|
||||
type: text
|
||||
disabled: true
|
||||
location:
|
||||
type: object
|
||||
fields:
|
||||
page:
|
||||
type: object
|
||||
fields:
|
||||
label: Page d'origine
|
||||
disabled: true
|
||||
title:
|
||||
type: text
|
||||
uri:
|
||||
disabled: true
|
||||
type: text
|
||||
project:
|
||||
label: Projet correspondant
|
||||
type: object
|
||||
fields:
|
||||
title:
|
||||
disabled: true
|
||||
type: text
|
||||
uri:
|
||||
disabled: true
|
||||
type: text
|
||||
author:
|
||||
label: Auteur
|
||||
type: object
|
||||
fields:
|
||||
name:
|
||||
label: Nom
|
||||
disabled: true
|
||||
type: text
|
||||
email:
|
||||
type: email
|
||||
disabled: true
|
||||
date:
|
||||
type: hidden
|
||||
isread:
|
||||
type: toggle
|
||||
disabled: true
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$brief = page($data->briefUri);
|
||||
$project = $brief->parent();
|
||||
$href = $data->dialogUri ? $data->dialogUri : $brief->url();
|
||||
$page = page($data->briefUri);
|
||||
$project = $page->parent();
|
||||
$dialogUri = $data->dialogUri ? $data->dialogUri : null;
|
||||
|
||||
try {
|
||||
$newPage = $brief->update([
|
||||
$newPage = $page->update([
|
||||
'isValidated' => 'true'
|
||||
]);
|
||||
|
||||
|
|
@ -21,20 +21,13 @@ return [
|
|||
|
||||
$notification = [
|
||||
'location' => [
|
||||
'href' => (string) $href,
|
||||
'project' => [
|
||||
'title' => (string) $project->title(),
|
||||
'uri' => (string) $project->url()
|
||||
]
|
||||
'page' => $page,
|
||||
'project' => $project,
|
||||
'dialogUri' => (string) $dialogUri,
|
||||
],
|
||||
'date' => $dateTime->format('Y-m-d\TH:i:sP'),
|
||||
'text' => "Brief (" . $project->title()->value() . ")",
|
||||
'author' => [
|
||||
'name' => (string) kirby()->user()->name(),
|
||||
'email' => (string) kirby()->user()->email(),
|
||||
'uuid' => (string) kirby()->user()->uuid(),
|
||||
'role' => (string) kirby()->user()->role(),
|
||||
],
|
||||
'text' => "Nouveau brief",
|
||||
'author' => kirby()->user(),
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'content'
|
||||
];
|
||||
|
|
@ -46,7 +39,7 @@ return [
|
|||
];
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
"error" => "Can't validate '" . $brief->title()->value() . "' brief.",
|
||||
"error" => "Can't validate '" . $page->title()->value() . "' brief.",
|
||||
'details' => $th->getMessage()
|
||||
];
|
||||
}
|
||||
|
|
|
|||
27
public/site/plugins/classes/Author.php
Normal file
27
public/site/plugins/classes/Author.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data;
|
||||
|
||||
class Author
|
||||
{
|
||||
protected string $name;
|
||||
protected string $email;
|
||||
protected string $uuid;
|
||||
protected string $role;
|
||||
|
||||
public function __construct($author) {
|
||||
$this->name = (string) $author->name();
|
||||
$this->email = (string) $author->email();
|
||||
$this->uuid = (string) $author->uuid();
|
||||
$this->role = (string) $author->role();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"name" => $this->name,
|
||||
"email" => $this->email,
|
||||
"uuid" => $this->uuid,
|
||||
"role" => $this->role,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
public/site/plugins/classes/Position.php
Normal file
32
public/site/plugins/classes/Position.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data;
|
||||
|
||||
class Position
|
||||
{
|
||||
public int $pageIndex;
|
||||
public ?float $x = null;
|
||||
public ?float $y = null;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->pageIndex = $data['pageIndex'];
|
||||
if (isset($data["x"])) {
|
||||
$this->x = (float) $data['x'];
|
||||
$this->y = (float) $data['y'];
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [
|
||||
"pageIndex" => $this->pageIndex,
|
||||
];
|
||||
|
||||
if ($this->x) {
|
||||
$array["x"] = $this->x;
|
||||
$array["y"] = $this->y;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
23
public/site/plugins/classes/location/FileDetails.php
Normal file
23
public/site/plugins/classes/location/FileDetails.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
use Kirby;
|
||||
|
||||
class FileDetails
|
||||
{
|
||||
public string $uuid;
|
||||
public string $url;
|
||||
|
||||
public function __construct(Kirby\Cms\File $data)
|
||||
{
|
||||
$this->uuid = (string) $data->uuid();
|
||||
$this->url = (string) $data->url();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"uuid" => $this->uuid,
|
||||
"url" => $this->url
|
||||
];
|
||||
}
|
||||
}
|
||||
53
public/site/plugins/classes/location/Location.php
Normal file
53
public/site/plugins/classes/location/Location.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
|
||||
class Location
|
||||
{
|
||||
protected PageDetails $page;
|
||||
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"]);
|
||||
|
||||
if (isset($data['file'])) {
|
||||
$this->file = new FileDetails($data["file"]);
|
||||
}
|
||||
if (isset($data["parent"])) {
|
||||
$this->parent = [
|
||||
"author" => [
|
||||
"name" => $data["parent"]["author"]["name"],
|
||||
"email" => $data["parent"]["author"]["email"],
|
||||
],
|
||||
"id" => $data["parent"]["id"]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [
|
||||
"page" => $this->page->toArray(),
|
||||
"project" => $this->project->toArray(),
|
||||
];
|
||||
|
||||
if ($this->dialogUri) {
|
||||
$array["dialogUri"] = $this->dialogUri;
|
||||
}
|
||||
|
||||
if ($this->file) {
|
||||
$array["file"] = $this->file;
|
||||
}
|
||||
|
||||
if ($this->parent) {
|
||||
$array["parent"] = $this->parent;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
21
public/site/plugins/classes/location/PageDetails.php
Normal file
21
public/site/plugins/classes/location/PageDetails.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
use Kirby\Cms\Page;
|
||||
|
||||
class PageDetails
|
||||
{
|
||||
protected Page $page;
|
||||
|
||||
public function __construct(Page $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"uri" => (string) $this->page->uri(),
|
||||
"title" => (string) $this->page->title(),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
public/site/plugins/classes/location/ProjectDetails.php
Normal file
23
public/site/plugins/classes/location/ProjectDetails.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
use Kirby;
|
||||
|
||||
class ProjectDetails
|
||||
{
|
||||
public string $title;
|
||||
public string $uri;
|
||||
|
||||
public function __construct(Kirby\Cms\Page $page)
|
||||
{
|
||||
$this->title = (string) $page->title();
|
||||
$this->uri = (string) $page->uri();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"title" => $this->title,
|
||||
"uri" => $this->uri
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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,51 @@ 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);
|
||||
$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(),
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ return [
|
|||
$page = page($data->location->page->uri);
|
||||
$project = page($data->location->project->uri);
|
||||
$file = $page->file($data->location->file->uuid);
|
||||
$isReply = $data->parentId ?? false;
|
||||
$isReply = $data->location->parentId ?? false;
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
foreach ($comments as $key => &$comment) {
|
||||
if ($isReply) {
|
||||
if ($comment['id'] === $data->parentId) {
|
||||
if ($comment['id'] === $data->location->parentId) {
|
||||
foreach ($comment['replies'] as $replyKey => $reply) {
|
||||
if ($reply['id'] === $data->id) {
|
||||
unset($comment['replies'][$replyKey]);
|
||||
|
|
|
|||
|
|
@ -9,39 +9,42 @@ 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,
|
||||
'parentId' => $data->parentId,
|
||||
'file' => $file,
|
||||
'position' => [
|
||||
'pageIndex' => $data->position->pageIndex,
|
||||
],
|
||||
'text' => $data->text,
|
||||
'author' => $user,
|
||||
'date' => (string) $data->date,
|
||||
'id' => $data->id,
|
||||
'type' => 'comment'
|
||||
];
|
||||
|
||||
$newReply = new Reply($data);
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
foreach ($comments as &$comment) {
|
||||
if ($comment['id'] === $newReply->parentId()) {
|
||||
$isParentComment = $comment['id'] === $data->parentId;
|
||||
if ($isParentComment) {
|
||||
$replyData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"dialogUri" => $data->dialogUri,
|
||||
"file" => $file,
|
||||
"parent" => $comment
|
||||
],
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment-reply",
|
||||
];
|
||||
$newReply = new Reply($replyData);
|
||||
$comment['replies'][] = $newReply->toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +53,7 @@ return [
|
|||
'comments' => $comments
|
||||
]);
|
||||
|
||||
$user->sendNotification($page->parent(), $newReply->toArray());
|
||||
$user->sendNotification($project, $replyData);
|
||||
|
||||
return getFileData($newFile);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,123 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\comments;
|
||||
use adrienpayet\D2P\data\location\Location;
|
||||
use adrienpayet\D2P\data\Author;
|
||||
use adrienpayet\D2P\data\Position;
|
||||
|
||||
class BaseComment {
|
||||
protected $href;
|
||||
protected $location;
|
||||
protected $position;
|
||||
protected $replies;
|
||||
protected $text;
|
||||
protected $author;
|
||||
protected $date;
|
||||
protected $id;
|
||||
protected $type;
|
||||
protected $isRead;
|
||||
protected Location $location;
|
||||
protected Author $author;
|
||||
protected string $text;
|
||||
protected string $date;
|
||||
protected string $id;
|
||||
protected Position $position;
|
||||
|
||||
public function __construct($data) {
|
||||
$page = $data['page'];
|
||||
$project = $page->template() == 'project' ? $page : $page->parent();
|
||||
$file = $data['file'];
|
||||
$position = $data['position'];
|
||||
$replies = $data['replies'] ?? [];
|
||||
$text = $data['text'];
|
||||
$author = $data['author'];
|
||||
$date = $data['date'];
|
||||
$id = $data['id'];
|
||||
$type = $data['type'] ?? 'comment';
|
||||
|
||||
$this->location = [
|
||||
'page' => [
|
||||
'uri' => (string) $page->uri(),
|
||||
'title' => (string) $page->title(),
|
||||
],
|
||||
'href' => (string) $data['href'],
|
||||
'project' => [
|
||||
'title' => (string) $project->title(),
|
||||
'uri' => (string) $project->uri(),
|
||||
],
|
||||
'file' => $file ? [
|
||||
'uuid' => (string) $file->uuid(),
|
||||
'url' => (string) $file->uuid()
|
||||
] : false,
|
||||
];
|
||||
|
||||
$this->replies = $replies ?? [];
|
||||
$this->text = $text;
|
||||
$this->author = [
|
||||
'name' => (string) $author->name(),
|
||||
'email' => (string) $author->email(),
|
||||
'uuid' => (string) $author->uuid(),
|
||||
'role' => (string) $author->role(),
|
||||
];
|
||||
$this->date = $date;
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->isRead = false;
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function location() {
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function file() {
|
||||
return $this->location['file'];
|
||||
}
|
||||
|
||||
public function replies() {
|
||||
return $this->replies;
|
||||
}
|
||||
|
||||
public function text() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function author() {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function date() {
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function isRead() {
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function read() {
|
||||
$this->isRead = true;
|
||||
return $this->isRead;
|
||||
$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->position = new Position($data['position']);
|
||||
}
|
||||
|
||||
public function unread() {
|
||||
$this->isRead = false;
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function pageIndex() {
|
||||
$this->position['pageIndex'];
|
||||
}
|
||||
|
||||
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(),
|
||||
"position" => $this->position->toArray(),
|
||||
"text" => $this->text,
|
||||
"author" => $this->author->toArray(),
|
||||
"date" => $this->date,
|
||||
"id" => $this->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,20 +4,17 @@ namespace adrienpayet\comments;
|
|||
|
||||
class Comment extends BaseComment
|
||||
{
|
||||
protected $position;
|
||||
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;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = parent::toArray();
|
||||
$array['position'] = $this->position;
|
||||
$array['type'] = $this->type;
|
||||
$array['replies'] = $this->replies;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,21 +3,15 @@ namespace adrienpayet\comments;
|
|||
|
||||
class Reply extends BaseComment {
|
||||
|
||||
protected $parentId;
|
||||
protected string $type = "comment-reply";
|
||||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
$this->parentId = $data['parentId'];
|
||||
}
|
||||
|
||||
|
||||
public function parentId() {
|
||||
return $this->parentId;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = parent::toArray();
|
||||
$array['parentId'] = $this->parentId;
|
||||
$array['type'] = $this->type;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ load([
|
|||
'ProjectPage' => 'models/ProjectPage.php',
|
||||
], __DIR__);
|
||||
|
||||
F::loadClasses([
|
||||
'adrienpayet\\notifications\\Notification' => __DIR__ . '/src/Notification.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/pdc-notifications', [
|
||||
'routes' => [
|
||||
require(__DIR__ . '/routes/readAll.php'),
|
||||
|
|
|
|||
42
public/site/plugins/notifications/src/Notification.php
Normal file
42
public/site/plugins/notifications/src/Notification.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications;
|
||||
use adrienpayet\D2P\data\location\Location;
|
||||
use adrienpayet\D2P\data\Author;
|
||||
|
||||
class Notification
|
||||
{
|
||||
protected string $type;
|
||||
protected Location $location;
|
||||
protected string $text;
|
||||
protected Author $author;
|
||||
protected string $date;
|
||||
protected string $id;
|
||||
protected string $isread = "false";
|
||||
|
||||
protected ?Position $position = null;
|
||||
|
||||
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"];
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [
|
||||
"type" => $this->type,
|
||||
"location" => $this->location->toArray(),
|
||||
"text" => $this->text,
|
||||
"author" => $this->author->toArray(),
|
||||
"date" => $this->date,
|
||||
"id" => $this->id,
|
||||
"isread" => $this->isread,
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ return function($notificationId) {
|
|||
foreach ($notifications as $key => $notification) {
|
||||
if (!isset($notification['id'])) continue;
|
||||
if ($notification['id'] === $notificationId) {
|
||||
$notifications[$key]['isRead'] = true;
|
||||
$notifications[$key]['isread'] = "true";
|
||||
$newNotification = $notifications[$key];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ return function() {
|
|||
|
||||
$newNotification = null;
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$notifications[$key]['isRead'] = true;
|
||||
$notifications[$key]['isread'] = true;
|
||||
}
|
||||
|
||||
$updatedUser = $this->update([
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use adrienpayet\notifications\Notification;
|
||||
|
||||
/**
|
||||
* Send a notification to all users who manage a specific project, excluding the user sending the notification.
|
||||
*
|
||||
|
|
@ -14,26 +16,26 @@
|
|||
*/
|
||||
|
||||
return function ($project, $notificationData) {
|
||||
$recipients = $project->managers()->without($this);
|
||||
$recipients = $project->managers()->without($this);
|
||||
|
||||
if ($recipients->isEmpty()) return;
|
||||
if ($recipients->isEmpty()) return;
|
||||
|
||||
$notificationData['isRead'] = false;
|
||||
$newNotification = new Notification($notificationData);
|
||||
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $notificationData;
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $newNotification->toArray();
|
||||
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
}
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue