mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-02-09 16:17:54 +01:00
Fixed notifications that would not be remembered as hidden + various improvements
This commit is contained in:
@@ -1577,10 +1577,14 @@ class Admin
|
||||
{
|
||||
$last_checked = null;
|
||||
$filename = $this->grav['locator']->findResource('user://data/notifications/' . md5($this->grav['user']->username) . YAML_EXT, true, true);
|
||||
$userStatus = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
|
||||
|
||||
$notifications_file = CompiledYamlFile::instance($filename);
|
||||
$notifications_content = (array)$notifications_file->content();
|
||||
|
||||
$userStatus_file = CompiledYamlFile::instance($userStatus);
|
||||
$userStatus_content = (array)$userStatus_file->content();
|
||||
|
||||
$last_checked = $notifications_content['last_checked'] ?? null;
|
||||
$notifications = $notifications_content['data'] ?? array();
|
||||
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
|
||||
@@ -1643,6 +1647,27 @@ class Admin
|
||||
$notifications_file->save();
|
||||
}
|
||||
|
||||
foreach ($notifications as $location => $list) {
|
||||
$notifications[$location] = array_filter($list, function ($notification) use ($userStatus_content) {
|
||||
$element = $userStatus_content[$notification['id']] ?? null;
|
||||
if (isset($element)) {
|
||||
if (isset($notification['reappear_after'])) {
|
||||
$now = new \DateTime();
|
||||
$hidden_on = new \DateTime($element);
|
||||
$hidden_on->modify($notification['reappear_after']);
|
||||
|
||||
if ($now >= $hidden_on) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user