44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
]
|
|
]);
|