fix send notification to users and create custom user method
This commit is contained in:
parent
9dcb054973
commit
f132049948
3 changed files with 133 additions and 12 deletions
27
public/site/plugins/user-methods/index.php
Normal file
27
public/site/plugins/user-methods/index.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue