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