refactor deleteNotification method
This commit is contained in:
parent
82f4aaf904
commit
fe56312f20
6 changed files with 70 additions and 33 deletions
|
|
@ -27,9 +27,30 @@ Comments:
|
||||||
role: admin
|
role: admin
|
||||||
position:
|
position:
|
||||||
pageIndex: 1
|
pageIndex: 1
|
||||||
x: "19.132179426191"
|
x: "34.157449699143"
|
||||||
y: "21.235521235521"
|
y: "50.965250965251"
|
||||||
date: 2024-11-16T12:15:12+01:00
|
date: 2024-11-17T11:51:35+01:00
|
||||||
id: m3k2mztq
|
id: m3lh8h5h
|
||||||
|
type: comment
|
||||||
|
isRead: false
|
||||||
|
-
|
||||||
|
page:
|
||||||
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
|
title: Miss Dior Blooming Bouquet
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
replies: [ ]
|
||||||
|
text: deuxième commentaire
|
||||||
|
author:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
position:
|
||||||
|
pageIndex: 1
|
||||||
|
x: '84.696990994209'
|
||||||
|
y: '56.949806949807'
|
||||||
|
date: 2024-11-17T11:59:37+01:00
|
||||||
|
id: m3lhisy6
|
||||||
type: comment
|
type: comment
|
||||||
isRead: false
|
isRead: false
|
||||||
|
|
@ -40,11 +40,14 @@ return [
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
echo json_encode(getFileData($newFile));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user->sendNotification($page->parent()->uri(), $newComment->toArray());
|
$user->sendNotification($page->parent()->uri(), $newComment->toArray());
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
throw new Exception($th->getMessage(), 1);
|
throw new Exception($th->getMessage(), 1);
|
||||||
}
|
}
|
||||||
return getFileData($newFile);
|
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -30,32 +30,16 @@ return [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$comments = array_values($comments); // Réindexe les commentaires
|
$comments = array_values($comments);
|
||||||
|
|
||||||
foreach (kirby()->users() as $user) {
|
|
||||||
try {
|
|
||||||
$notifications = $user->notifications()->isNotEmpty()
|
|
||||||
? Yaml::decode($user->notifications()->value())
|
|
||||||
: [];
|
|
||||||
|
|
||||||
foreach ($notifications as $key => $notification) {
|
|
||||||
if ($notification['id'] === $data->id) {
|
|
||||||
unset($notifications[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->update([
|
|
||||||
'notifications' => $notifications
|
|
||||||
]);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return getFileData($newFile);
|
echo json_encode(getFileData($newFile));
|
||||||
|
|
||||||
|
kirby()->user()->deleteNotification($page, $data->id);
|
||||||
|
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
Kirby::plugin('adrienpayet/pdc-notifications', [
|
Kirby::plugin('adrienpayet/pdc-notifications', [
|
||||||
'routes' => [
|
// 'routes' => [
|
||||||
require(__DIR__ . '/routes/mark-as-read.php'),
|
// require(__DIR__ . '/routes/mark-as-read.php'),
|
||||||
],
|
// ],
|
||||||
'userMethods' => [
|
'userMethods' => [
|
||||||
'sendNotification' => require(__DIR__ . '/user-methods/send.php')
|
'sendNotification' => require(__DIR__ . '/user-methods/send.php'),
|
||||||
|
'deleteNotification' => require(__DIR__ . '/user-methods/delete.php')
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
26
public/site/plugins/notifications/user-methods/delete.php
Normal file
26
public/site/plugins/notifications/user-methods/delete.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return function($project, $notificationId) {
|
||||||
|
$projectManagers = $project->managers()->toUsers();
|
||||||
|
|
||||||
|
foreach ($projectManagers as $user) {
|
||||||
|
try {
|
||||||
|
$notifications = $user->notifications()->isNotEmpty()
|
||||||
|
? Yaml::decode($user->notifications()->value())
|
||||||
|
: [];
|
||||||
|
|
||||||
|
foreach ($notifications as $key => $notification) {
|
||||||
|
if ($notification['id'] === $notificationId) {
|
||||||
|
unset($notifications[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Réindexation et ré-encodage en YAML avant la mise à jour
|
||||||
|
$user->update([
|
||||||
|
'notifications' => Yaml::encode(array_values($notifications))
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<aside id="comments-container" aria-labelledby="comments-label">
|
<aside id="comments-container" aria-labelledby="comments-label">
|
||||||
<h2 id="comments-label" class="sr-only">Commentaires</h2>
|
<h2 id="comments-label" class="sr-only">Commentaires</h2>
|
||||||
<div class="comments | flow" :class="{ empty: comments.length === 0 }">
|
<div
|
||||||
|
class="comments | flow"
|
||||||
|
:class="{ empty: !comments || comments.length === 0 }"
|
||||||
|
>
|
||||||
<template v-if="comments">
|
<template v-if="comments">
|
||||||
<template v-if="!openedComment">
|
<template v-if="!openedComment">
|
||||||
<Comment
|
<Comment
|
||||||
|
|
@ -43,7 +46,6 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<template v-else> état aucun commentaire </template>
|
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
v-if="!openedComment && !isAddOpen"
|
v-if="!openedComment && !isAddOpen"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue