designtopack/public/site/plugins/notifications/user-methods/send.php

23 lines
657 B
PHP
Raw Normal View History

2024-10-29 16:13:07 +01:00
<?php
2024-10-30 10:56:11 +01:00
return function ($group, $item) {
2024-10-29 16:13:07 +01:00
foreach (kirby()->users()->not($this) as $otherUser) {
try {
$notifications = $otherUser->notifications()->isNotEmpty()
? Yaml::decode($otherUser->notifications()->value())
: [];
if (!isset($notifications[$group])) {
$notifications[$group] = [];
}
2024-10-30 10:56:11 +01:00
$notifications[$group][$item->id()] = $item->toArray();
2024-10-29 16:13:07 +01:00
$otherUser->update([
'notifications' => $notifications
]);
} catch (\Throwable $th) {
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
}
};