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

26 lines
767 B
PHP
Raw Normal View History

2024-10-29 16:13:07 +01:00
<?php
2024-11-22 07:53:43 +01:00
return function($notificationId) {
2024-10-29 16:13:07 +01:00
try {
2024-11-18 09:36:15 +01:00
$notifications = $this->notifications()->isNotEmpty()
? Yaml::decode($this->notifications()->value())
: [];
$newNotification = null;
foreach ($notifications as $key => $notification) {
2024-12-17 14:21:33 +01:00
if (!isset($notification['id'])) continue;
2024-11-18 09:36:15 +01:00
if ($notification['id'] === $notificationId) {
2024-12-19 10:32:48 +01:00
$notifications[$key]['isread'] = "true";
2024-11-18 09:36:15 +01:00
$newNotification = $notifications[$key];
}
}
$this->update([
'notifications' => Yaml::encode(array_values($notifications))
]);
return $newNotification;
2024-10-29 16:13:07 +01:00
} catch (\Throwable $th) {
2024-11-18 09:36:15 +01:00
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
2024-10-29 16:13:07 +01:00
}
};