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
|
|
@ -18,6 +18,111 @@ Comments:
|
||||||
username: Adrien Payet
|
username: Adrien Payet
|
||||||
date: 2024-10-23T16:22:47+02:00
|
date: 2024-10-23T16:22:47+02:00
|
||||||
id: m2lyrs06
|
id: m2lyrs06
|
||||||
|
m2t206b6:
|
||||||
|
text: Nouveau com
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:27:41+01:00
|
||||||
|
id: m2t206b6
|
||||||
|
m2t20ei0:
|
||||||
|
text: Et ebcore
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:27:51+01:00
|
||||||
|
id: m2t20ei0
|
||||||
|
m2t213jw:
|
||||||
|
text: test2
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:28:24+01:00
|
||||||
|
id: m2t213jw
|
||||||
|
m2t21e5f:
|
||||||
|
text: autre
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:28:38+01:00
|
||||||
|
id: m2t21e5f
|
||||||
|
m2t21h7k:
|
||||||
|
text: sfgd
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:28:42+01:00
|
||||||
|
id: m2t21h7k
|
||||||
|
m2t2sgrk:
|
||||||
|
text: test3
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:49:41+01:00
|
||||||
|
id: m2t2sgrk
|
||||||
|
m2t2sn60:
|
||||||
|
text: test4
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:49:49+01:00
|
||||||
|
id: m2t2sn60
|
||||||
|
m2t2ux6u:
|
||||||
|
text: test5
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:51:35+01:00
|
||||||
|
id: m2t2ux6u
|
||||||
|
m2t2v0ba:
|
||||||
|
text: test6
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:51:39+01:00
|
||||||
|
id: m2t2v0ba
|
||||||
|
m2t2wak4:
|
||||||
|
text: test8
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:52:39+01:00
|
||||||
|
id: m2t2wak4
|
||||||
|
m2t2z30f:
|
||||||
|
text: jfhj
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:54:49+01:00
|
||||||
|
id: m2t2z30f
|
||||||
|
m2t2ze81:
|
||||||
|
text: qsvfh
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:55:04+01:00
|
||||||
|
id: m2t2ze81
|
||||||
|
m2t30udw:
|
||||||
|
text: fdgjh
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:56:12+01:00
|
||||||
|
id: m2t30udw
|
||||||
|
m2t31bxv:
|
||||||
|
text: testl
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:56:34+01:00
|
||||||
|
id: m2t31bxv
|
||||||
|
m2t32i8i:
|
||||||
|
text: dlakeja
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:57:29+01:00
|
||||||
|
id: m2t32i8i
|
||||||
|
m2t33dra:
|
||||||
|
text: hfdts
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:58:10+01:00
|
||||||
|
id: m2t33dra
|
||||||
|
m2t34im4:
|
||||||
|
text: lkqs
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:59:03+01:00
|
||||||
|
id: m2t34im4
|
||||||
|
m2t359np:
|
||||||
|
text: lqsjd
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T14:59:38+01:00
|
||||||
|
id: m2t359np
|
||||||
|
m2t362kx:
|
||||||
|
text: ;sjn
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T15:00:16+01:00
|
||||||
|
id: m2t362kx
|
||||||
|
m2t36rex:
|
||||||
|
text: jfghy
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T15:00:48+01:00
|
||||||
|
id: m2t36rex
|
||||||
|
m2t37dx2:
|
||||||
|
text: dkdjsfn
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-28T15:01:17+01:00
|
||||||
|
id: m2t37dx2
|
||||||
2:
|
2:
|
||||||
m2lys1bs:
|
m2lys1bs:
|
||||||
text: test
|
text: test
|
||||||
|
|
|
||||||
|
|
@ -29,18 +29,7 @@ return [
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach (kirby()->users()->without($user) as $otherUser) {
|
$user->sendNotification('comments', $newComment);
|
||||||
try {
|
|
||||||
$notifications = $otherUser->notifications()->isNotEmpty() ? $otherUser->notifications()->toArray() : ["comments" => []];
|
|
||||||
$notifications['comments'][$data->id] = $newComment;
|
|
||||||
$otherUser->update([
|
|
||||||
"notifications" => $notifications
|
|
||||||
]);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
throw new Exception($th->getMessage(), 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return getFileData($newFile);
|
return getFileData($newFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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