read all working
This commit is contained in:
parent
495e1c024e
commit
ef09a04b5e
7 changed files with 105 additions and 65 deletions
|
|
@ -5,62 +5,88 @@ use Kirby\Data\Yaml;
|
|||
use adrienpayet\notifications\Notification;
|
||||
|
||||
class NotificationsPage extends Page {
|
||||
public function createNotification($notificationData) {
|
||||
$newNotification = new Notification($notificationData);
|
||||
public function createNotification($notificationData) {
|
||||
$newNotification = new Notification($notificationData);
|
||||
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $newNotification->toArray();
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $newNotification->toArray();
|
||||
|
||||
$this->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
}
|
||||
$this->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteNotification($notificationId) {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
if ($notification['id'] === $notificationId) {
|
||||
unset($notifications[$key]);
|
||||
}
|
||||
}
|
||||
public function deleteNotification($notificationId) {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
if ($notification['id'] === $notificationId) {
|
||||
unset($notifications[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
}
|
||||
$this->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
}
|
||||
|
||||
public function readNotification($notificationId) {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => &$notification) {
|
||||
if ($notification['id'] !== $notificationId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($notification["readby"])) {
|
||||
$notification["readby"] = [];
|
||||
}
|
||||
|
||||
$userUuid = (string) kirby()->user()->uuid();
|
||||
if (in_array($userUuid, $notification["readby"])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification["readby"][] = $userUuid;
|
||||
break;
|
||||
}
|
||||
public function readNotification($notificationId) {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => &$notification) {
|
||||
if ($notification['id'] !== $notificationId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($notification["readby"])) {
|
||||
$notification["readby"] = [];
|
||||
}
|
||||
|
||||
$userUuid = (string) kirby()->user()->uuid();
|
||||
if (in_array($userUuid, $notification["readby"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notification["readby"][] = $userUuid;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'notifications' => Yaml::encode($notifications)
|
||||
]);
|
||||
}
|
||||
$this->update([
|
||||
'notifications' => Yaml::encode($notifications)
|
||||
]);
|
||||
}
|
||||
|
||||
public function readAllNotifications() {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => &$notification) {
|
||||
if (!isset($notification["readby"])) {
|
||||
$notification["readby"] = [];
|
||||
}
|
||||
|
||||
$userUuid = (string) kirby()->user()->uuid();
|
||||
if (in_array($userUuid, $notification["readby"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notification["readby"][] = $userUuid;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->update([
|
||||
'notifications' => Yaml::encode($notifications)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue