create comment classes
This commit is contained in:
parent
cd1f065962
commit
f5ffe312e2
8 changed files with 246 additions and 63 deletions
|
|
@ -22,7 +22,23 @@ m2unqxu0:
|
||||||
position:
|
position:
|
||||||
x: null
|
x: null
|
||||||
y: null
|
y: null
|
||||||
replies: [ ]
|
replies:
|
||||||
|
m2vmx97a:
|
||||||
|
page:
|
||||||
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
|
title: Miss Dior Blooming Bouquet
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
text: Test de réponse
|
||||||
|
user:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
date: 2024-10-30T09:48:49+01:00
|
||||||
|
id: m2vmx97a
|
||||||
|
type: comment
|
||||||
text: >
|
text: >
|
||||||
Un commentaire écrit par Adrien pour
|
Un commentaire écrit par Adrien pour
|
||||||
tester.
|
tester.
|
||||||
|
|
@ -69,4 +85,50 @@ m2unytm0:
|
||||||
role: client
|
role: client
|
||||||
date: 2024-10-29T17:30:15+01:00
|
date: 2024-10-29T17:30:15+01:00
|
||||||
id: m2unytm0
|
id: m2unytm0
|
||||||
type: comment
|
type: comment
|
||||||
|
m2vmw7ct:
|
||||||
|
page:
|
||||||
|
uri: >
|
||||||
|
projects/miss-dior-blooming-bouquet/client-brief
|
||||||
|
title: Brief client
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: >
|
||||||
|
encore un test après créaton classes
|
||||||
|
php comment
|
||||||
|
user:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
date: 2024-10-30T09:48:00+01:00
|
||||||
|
id: m2vmw7ct
|
||||||
|
type: comment
|
||||||
|
position:
|
||||||
|
x: null
|
||||||
|
y: null
|
||||||
|
m2vmwvmt:
|
||||||
|
page:
|
||||||
|
uri: >
|
||||||
|
projects/miss-dior-blooming-bouquet/client-brief
|
||||||
|
title: Brief client
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: >
|
||||||
|
encore un test après créaton classes
|
||||||
|
php comment
|
||||||
|
user:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
date: 2024-10-30T09:48:31+01:00
|
||||||
|
id: m2vmwvmt
|
||||||
|
type: comment
|
||||||
|
position:
|
||||||
|
x: null
|
||||||
|
y: null
|
||||||
24
public/site/plugins/comments/composer.json
Normal file
24
public/site/plugins/comments/composer.json
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"name": "adrienpayet/kirby4-comments",
|
||||||
|
"description": "Enable comment.",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "kirby-plugin",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Adrien Payet",
|
||||||
|
"email": "contact@adrien-payet.fr"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"getkirby/composer-installer": "^1.1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Adrienpayet\\Comments\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"optimize-autoloader": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
Kirby::plugin('adrienpayet/pdc-comments', [
|
F::loadClasses([
|
||||||
|
'adrienpayet\\comments\\BaseComment' => __DIR__ . '/src/BaseComment.php',
|
||||||
|
'adrienpayet\\comments\\Comment' => __DIR__ . '/src/Comment.php',
|
||||||
|
'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php'
|
||||||
|
]);
|
||||||
|
|
||||||
|
Kirby::plugin('adrienpayet/kirby4-comments', [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require(__DIR__ . '/routes/create.php'),
|
require(__DIR__ . '/routes/create.php'),
|
||||||
require(__DIR__ . '/routes/update.php'),
|
require(__DIR__ . '/routes/update.php'),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use adrienpayet\comments\Comment;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pattern' => '(:all)create-comment.json',
|
'pattern' => '(:all)create-comment.json',
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
|
@ -14,33 +16,25 @@ return [
|
||||||
|
|
||||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||||
|
|
||||||
$newComment = [
|
$data = [
|
||||||
'page' => [
|
'page' => $page,
|
||||||
'uri' => (string) $page->parent()->uri(),
|
'file' => $file,
|
||||||
'title' => (string) $page->parent()->title(),
|
'filePageIndex' => $data->filePageIndex,
|
||||||
],
|
|
||||||
'file' => [
|
|
||||||
'uuid' => (string) $file->uuid(),
|
|
||||||
'pageIndex' => $data->filePageIndex,
|
|
||||||
],
|
|
||||||
'position' => [
|
'position' => [
|
||||||
'x' => null,
|
'x' => null,
|
||||||
'y' => null
|
'y' => null
|
||||||
],
|
],
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'text' => $data->text,
|
'text' => $data->text,
|
||||||
'user' => [
|
'user' => $user,
|
||||||
'name' => (string) $user->name(),
|
|
||||||
'email' => (string) $user->email(),
|
|
||||||
'uuid' => (string) $user->uuid(),
|
|
||||||
'role' => (string) $user->role()
|
|
||||||
],
|
|
||||||
'date' => (string) $data->date,
|
'date' => (string) $data->date,
|
||||||
'id' => $data->id,
|
'id' => $data->id,
|
||||||
'type' => 'comment'
|
'type' => 'comment'
|
||||||
];
|
];
|
||||||
|
|
||||||
$comments[$data->id] = $newComment;
|
$newComment = new Comment($data);
|
||||||
|
|
||||||
|
$comments[$newComment->id()] = $newComment->toArray();
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
|
|
|
||||||
93
public/site/plugins/comments/src/BaseComment.php
Normal file
93
public/site/plugins/comments/src/BaseComment.php
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace adrienpayet\comments;
|
||||||
|
|
||||||
|
class BaseComment {
|
||||||
|
protected $page;
|
||||||
|
protected $file;
|
||||||
|
protected $filePageIndex;
|
||||||
|
protected $position;
|
||||||
|
protected $replies;
|
||||||
|
protected $text;
|
||||||
|
protected $user;
|
||||||
|
protected $date;
|
||||||
|
protected $id;
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
public function __construct($data) {
|
||||||
|
$page = $data['page'];
|
||||||
|
$file = $data['file'];
|
||||||
|
$filePageIndex = $data['filePageIndex'];
|
||||||
|
$replies = $data['replies'] ?? [];
|
||||||
|
$text = $data['text'];
|
||||||
|
$user = $data['user'];
|
||||||
|
$date = $data['date'];
|
||||||
|
$id = $data['id'];
|
||||||
|
$type = $data['type'] ?? 'comment';
|
||||||
|
|
||||||
|
$this->page = [
|
||||||
|
'uri' => (string) $page->uri(),
|
||||||
|
'title' => (string) $page->title(),
|
||||||
|
];
|
||||||
|
$this->file = [
|
||||||
|
'uuid' => (string) $file->uuid(),
|
||||||
|
'pageIndex' => $filePageIndex,
|
||||||
|
];
|
||||||
|
$this->replies = $replies ?? [];
|
||||||
|
$this->text = $text;
|
||||||
|
$this->user = [
|
||||||
|
'name' => (string) $user->name(),
|
||||||
|
'email' => (string) $user->email(),
|
||||||
|
'uuid' => (string) $user->uuid(),
|
||||||
|
'role' => (string) $user->role(),
|
||||||
|
];
|
||||||
|
$this->date = $date;
|
||||||
|
$this->id = $id;
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function page() {
|
||||||
|
return $this->page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function file() {
|
||||||
|
return $this->file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function replies() {
|
||||||
|
return $this->replies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function text() {
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user() {
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function date() {
|
||||||
|
return $this->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function id() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function type() {
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray() {
|
||||||
|
return [
|
||||||
|
'page' => $this->page,
|
||||||
|
'file' => $this->file,
|
||||||
|
'replies' => $this->replies,
|
||||||
|
'text' => $this->text,
|
||||||
|
'user' => $this->user,
|
||||||
|
'date' => $this->date,
|
||||||
|
'id' => $this->id,
|
||||||
|
'type' => $this->type,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
public/site/plugins/comments/src/Comment.php
Normal file
24
public/site/plugins/comments/src/Comment.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace adrienpayet\comments;
|
||||||
|
|
||||||
|
class Comment extends BaseComment
|
||||||
|
{
|
||||||
|
protected $position;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
public/site/plugins/comments/src/Reply.php
Normal file
24
public/site/plugins/comments/src/Reply.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
namespace adrienpayet\comments;
|
||||||
|
|
||||||
|
class Reply extends BaseComment {
|
||||||
|
|
||||||
|
protected $parentId;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
Kirby::plugin('adrienpayet/pdc-user-methods', [
|
|
||||||
'userMethods' => [
|
|
||||||
'sendNotification' => function ($group, $data) {
|
|
||||||
foreach (kirby()->users()->not($this) as $otherUser) {
|
|
||||||
try {
|
|
||||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
|
||||||
? Yaml::decode($otherUser->notifications()->value())
|
|
||||||
: [];
|
|
||||||
|
|
||||||
if (!isset($notifications[$group])) {
|
|
||||||
$notifications[$group] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$data['isRead'] = false;
|
|
||||||
|
|
||||||
$notifications[$group][$data['id']] = $data;
|
|
||||||
|
|
||||||
$otherUser->update([
|
|
||||||
'notifications' => $notifications
|
|
||||||
]);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'readNotification' => function ($group, $notificationId) {
|
|
||||||
$notifications = Yaml::decode($this->notifications()->value());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$notifications[$group][$notificationId]['isRead'] = true;
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
//throw $th;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->update([
|
|
||||||
"notifications" => $notifications
|
|
||||||
]);
|
|
||||||
return $notifications;
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue