fix send notification to users and create custom user method

This commit is contained in:
isUnknown 2024-10-28 15:02:28 +01:00
parent 9dcb054973
commit f132049948
3 changed files with 133 additions and 12 deletions

View file

@ -0,0 +1,27 @@
<?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] = [];
}
$notifications[$group][$data['id']] = $data;
$otherUser->update([
'notifications' => $notifications
]);
} catch (\Throwable $th) {
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
}
}
]
]);