diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index 4efe262..81aeac1 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -22,7 +22,23 @@ m2unqxu0: position: x: 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: > Un commentaire écrit par Adrien pour tester. @@ -69,4 +85,50 @@ m2unytm0: role: client date: 2024-10-29T17:30:15+01:00 id: m2unytm0 - type: comment \ No newline at end of file + 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 \ No newline at end of file diff --git a/public/site/plugins/comments/composer.json b/public/site/plugins/comments/composer.json new file mode 100644 index 0000000..66550d3 --- /dev/null +++ b/public/site/plugins/comments/composer.json @@ -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 + } +} diff --git a/public/site/plugins/comments/index.php b/public/site/plugins/comments/index.php index f4d8e7f..0fcc8bb 100644 --- a/public/site/plugins/comments/index.php +++ b/public/site/plugins/comments/index.php @@ -1,6 +1,12 @@ __DIR__ . '/src/BaseComment.php', + 'adrienpayet\\comments\\Comment' => __DIR__ . '/src/Comment.php', + 'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php' +]); + +Kirby::plugin('adrienpayet/kirby4-comments', [ 'routes' => [ require(__DIR__ . '/routes/create.php'), require(__DIR__ . '/routes/update.php'), diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 3949381..4449822 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -1,5 +1,7 @@ '(:all)create-comment.json', 'method' => 'POST', @@ -14,33 +16,25 @@ return [ $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); - $newComment = [ - 'page' => [ - 'uri' => (string) $page->parent()->uri(), - 'title' => (string) $page->parent()->title(), - ], - 'file' => [ - 'uuid' => (string) $file->uuid(), - 'pageIndex' => $data->filePageIndex, - ], + $data = [ + 'page' => $page, + 'file' => $file, + 'filePageIndex' => $data->filePageIndex, 'position' => [ 'x' => null, 'y' => null ], 'replies' => [], 'text' => $data->text, - 'user' => [ - 'name' => (string) $user->name(), - 'email' => (string) $user->email(), - 'uuid' => (string) $user->uuid(), - 'role' => (string) $user->role() - ], + 'user' => $user, 'date' => (string) $data->date, 'id' => $data->id, 'type' => 'comment' ]; - $comments[$data->id] = $newComment; + $newComment = new Comment($data); + + $comments[$newComment->id()] = $newComment->toArray(); $newFile = $file->update([ 'comments' => $comments diff --git a/public/site/plugins/comments/src/BaseComment.php b/public/site/plugins/comments/src/BaseComment.php new file mode 100644 index 0000000..6b5d6d7 --- /dev/null +++ b/public/site/plugins/comments/src/BaseComment.php @@ -0,0 +1,93 @@ +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, + ]; + } +} diff --git a/public/site/plugins/comments/src/Comment.php b/public/site/plugins/comments/src/Comment.php new file mode 100644 index 0000000..64cfb61 --- /dev/null +++ b/public/site/plugins/comments/src/Comment.php @@ -0,0 +1,24 @@ +position = $data['position'] ?? null; + } + + public function position() { + return $this->position; + } + + public function toArray() { + $array = parent::toArray(); + $array['position'] = $this->position; + + return $array; + } +} \ No newline at end of file diff --git a/public/site/plugins/comments/src/Reply.php b/public/site/plugins/comments/src/Reply.php new file mode 100644 index 0000000..4ff9382 --- /dev/null +++ b/public/site/plugins/comments/src/Reply.php @@ -0,0 +1,24 @@ +parentId = $data['parentId']; + } + + + public function parentId() { + return $this->parentId; + } + + public function toArray() { + $array = parent::toArray(); + $array['parentId'] = $this->parentId; + + return $array; + } +} diff --git a/public/site/plugins/user-methods/index.php b/public/site/plugins/user-methods/index.php deleted file mode 100644 index 2507b6d..0000000 --- a/public/site/plugins/user-methods/index.php +++ /dev/null @@ -1,44 +0,0 @@ - [ - '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; - } - ] -]);