blob: 62b245a3896c2660c4f0da5d80e73b9b83143c6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Notification;
use Piwik\Notification;
use Piwik\Session\SessionNamespace;
/**
* @package Piwik
* @subpackage Notification
* @api
*/
class Manager
{
private static $session = null;
/**
* Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.
*
* @param string $id A unique identifier for this notification
* @param Notification $notification
*/
public static function notify($id, Notification $notification)
{
$session = static::getSession();
$session->$id = $notification;
$session->setExpirationHops(1, $id);
}
public static function getAllNotificationsToDisplay()
{
$session = static::getSession();
$notifications = $session->getIterator();
$notifications->uasort(function ($n1, $n2) {
if ($n1->priority == $n2->priority) {
return 0;
}
return $n1->priority > $n2->priority;
});
return $notifications;
}
/**
* Cancel a previously registered notification.
* @param $id
*/
public static function cancel($id)
{
$session = static::getSession();
unset($session->$id);
}
/**
* @return SessionNamespace
*/
private static function getSession()
{
if (!isset(static::$session)) {
static::$session = new SessionNamespace('notification');
}
return static::$session;
}
}
|