-
Notifications
You must be signed in to change notification settings - Fork 4
/
AdminNotification.php
58 lines (47 loc) · 1.83 KB
/
AdminNotification.php
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
<?php
namespace Piwik\Plugins\AdminNotification;
use Piwik\Piwik;
use Piwik\Notification;
/**
*/
class AdminNotification extends \Piwik\Plugin
{
private static $hooks = array(
'Login.authenticate.successful' => 'setNotificationV3', //Version 3.X Post login handler
'SystemSettings.updated' => 'settingsChangedV3' //Version 3.X Setting updated handler
);
public function registerEvents()
{
return self::$hooks;
}
public function settingsChangedV3($settings)
{
if ($settings->getPluginName() === 'AdminNotification') {
$this->setNotificationV3();
}
}
public function setNotificationV3()
{
// Known issue. The alert notification is not updated until login/logout on v3.x.
// 2.X Compatibility. This method appears to be getting called in v2.X which I didn't
// believe would trigger the newer hooks.
if (!class_exists('\Piwik\Settings\Plugin\SystemSettings')) { //If class doesn't exist just get out.
return;
}
$settings = new SystemSettings();
//print_r($settings->enabled->getValue());
if ($settings->enabled->getValue()) {
$notification = new Notification($settings->message->getValue());
$notification->title = $settings->messageTitle->getValue();
$notification->context = $settings->context->getValue();
$notification->type = Notification::TYPE_PERSISTENT;
//$notification->priority = Notification::PRIORITY_MAX;
//echo "NOTIFY";
//print_r($notification);
Notification\Manager::notify('AdminNotification_notice', $notification);
} else {
//echo "NOTIFY CANCEL";
Notification\Manager::cancel('AdminNotification_notice');
}
}
}