send notification user method working

This commit is contained in:
isUnknown 2024-10-30 10:56:11 +01:00
parent 14f409abec
commit 9752fffae6
7 changed files with 67 additions and 18 deletions

View file

@ -6,4 +6,31 @@ Uuid: s0lNtRA0Z7ybTCWG
----
Template: document
Template: document
----
Comments:
m2vpa4tb:
page:
uri: >
projects/miss-dior-blooming-bouquet/client-brief
title: Brief client
file:
uuid: file://s0lNtRA0Z7ybTCWG
pageIndex: 1
replies: [ ]
text: test
user:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-10-30T10:54:49+01:00
id: m2vpa4tb
type: comment
isRead: false
position:
x: null
y: null

View file

@ -40,7 +40,7 @@ return [
'comments' => $comments
]);
$user->sendNotification('comments', $newComment->toArray());
$user->sendNotification('comments', $newComment);
return getFileData($newFile);
}

View file

@ -13,6 +13,7 @@ class BaseComment {
protected $date;
protected $id;
protected $type;
protected $isRead;
public function __construct($data) {
$page = $data['page'];
@ -44,6 +45,7 @@ class BaseComment {
$this->date = $date;
$this->id = $id;
$this->type = $type;
$this->isRead = false;
}
public function page() {
@ -78,6 +80,20 @@ class BaseComment {
return $this->type;
}
public function isRead() {
return $this->isRead;
}
public function read() {
$this->isRead = true;
return $this->isRead;
}
public function unread() {
$this->isRead = false;
return $this->isRead;
}
public function toArray() {
return [
'page' => $this->page,
@ -88,6 +104,7 @@ class BaseComment {
'date' => $this->date,
'id' => $this->id,
'type' => $this->type,
'isRead' => $this->isRead
];
}
}

View file

@ -3,5 +3,8 @@
Kirby::plugin('adrienpayet/pdc-notifications', [
'routes' => [
require(__DIR__ . '/routes/mark-as-read.php'),
],
'userMethods' => [
'sendNotification' => require(__DIR__ . '/user-methods/send.php')
]
]);

View file

@ -1,6 +1,6 @@
<?php
return function ($group, $data) {
return function ($group, $item) {
foreach (kirby()->users()->not($this) as $otherUser) {
try {
$notifications = $otherUser->notifications()->isNotEmpty()
@ -10,11 +10,8 @@ return function ($group, $data) {
if (!isset($notifications[$group])) {
$notifications[$group] = [];
}
$data['isRead'] = false;
$notifications[$group][$data['id']] = $data;
$notifications[$group][$item->id()] = $item->toArray();
$otherUser->update([
'notifications' => $notifications