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

23 lines
738 B
PHP

<?php
return function($projectManagers, $notificationId) {
foreach ($projectManagers as $projectManager) {
try {
$notifications = $projectManager->notifications()->isNotEmpty()
? Yaml::decode($projectManager->notifications()->value())
: [];
foreach ($notifications as $key => $notification) {
if ($notification['id'] === $notificationId) {
unset($notifications[$key]);
}
}
$projectManager->update([
'notifications' => Yaml::encode(array_values($notifications))
]);
} catch (\Throwable $th) {
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
}
};