diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-10-29 00:09:51 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-10-29 00:09:51 +0400 |
commit | 076c4eee4386e63200aab4522c014e416a7e31be (patch) | |
tree | 8b10a13d583e2fb3e7df0ee617fdcc72ee67577e /core/Notification | |
parent | f3046da3d3ba17f5a28576c4eb22bf0aea9c1144 (diff) |
refs #4179 as we do not get the notification id in the iterator, the cancel of all notification did not work
Diffstat (limited to 'core/Notification')
-rw-r--r-- | core/Notification/Manager.php | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/core/Notification/Manager.php b/core/Notification/Manager.php index 51681f0766..686f1f7c18 100644 --- a/core/Notification/Manager.php +++ b/core/Notification/Manager.php @@ -35,8 +35,8 @@ class Manager { self::checkId($id); - $session = static::getSession(); - $session->$id = $notification; + $session = static::getSession(); + $session->notifications[$id] = $notification; } /** @@ -45,10 +45,9 @@ class Manager */ public static function getAllNotificationsToDisplay() { - $session = static::getSession(); - $notifications = $session->getIterator(); + $notifications = static::getAllNotifications(); - $notifications->uasort(function ($n1, $n2) { + uasort($notifications, function ($n1, $n2) { if ($n1->priority == $n2->priority) { return 0; } @@ -65,15 +64,20 @@ class Manager */ public static function cancelAllNonPersistent() { - $session = static::getSession(); - - foreach ($session->getIterator() as $key => $notification) { + foreach (static::getAllNotifications() as $id => $notification) { if (Notification::TYPE_PERSISTENT != $notification->type) { - unset($session->$key); + static::cancel($id); } } } + private static function getAllNotifications() + { + $session = static::getSession(); + + return $session->notifications; + } + /** * Cancel a previously registered (or persistent) notification. * @param $id @@ -83,7 +87,9 @@ class Manager self::checkId($id); $session = static::getSession(); - unset($session->$id); + if (array_key_exists($id, $session->notifications)) { + unset($session->notifications[$id]); + } } /** @@ -95,6 +101,10 @@ class Manager static::$session = new SessionNamespace('notification'); } + if (empty(static::$session->notifications)) { + static::$session->notifications = array(); + } + return static::$session; } @@ -108,7 +118,7 @@ class Manager throw new \Exception('Notification ID is empty.'); } - if (!is_string($id) || !preg_match('/^(\w)*$/', $id)) { + if (!preg_match('/^(\w)*$/', $id)) { throw new \Exception('Invalid Notification ID given. Only word characters (AlNum + underscore) allowed.'); } } |