|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vivait\AuthBundle\EventListener; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Security\Core\SecurityContext; |
|
6
|
|
|
use Vivait\BootstrapBundle\Event\ConfigureMenuEvent; |
|
7
|
|
|
|
|
8
|
|
|
class ConfigureMenuListener { |
|
9
|
|
|
/** |
|
10
|
|
|
* @var SecurityContext |
|
11
|
|
|
*/ |
|
12
|
|
|
private $security_context; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var int |
|
16
|
|
|
*/ |
|
17
|
|
|
private $license_warning; |
|
18
|
|
|
|
|
19
|
|
|
function __construct(SecurityContext $security_context, $license_warning = 7) { |
|
|
|
|
|
|
20
|
|
|
$this->security_context = $security_context; |
|
21
|
|
|
$this->license_warning = intval($license_warning); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param ConfigureMenuEvent $event |
|
26
|
|
|
*/ |
|
27
|
|
|
public function onMenuConfigure(ConfigureMenuEvent $event) { |
|
28
|
|
|
$menu = $event->getMenu(); |
|
29
|
|
|
$token = $this->security_context->getToken(); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$root = $menu->addChild('Auth Menu', [ |
|
32
|
|
|
'navbar' => true, |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
if ($token === null) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/* @var $user \Vivait\AuthBundle\Entity\User */ |
|
40
|
|
|
$user = $token->getUser(); |
|
41
|
|
|
|
|
42
|
|
|
if ($user) { |
|
43
|
|
|
if ($user->getLicensedUntil() > new \DateTime('+' . $this->license_warning . ' days')) { |
|
44
|
|
|
$licensing = $root->addChild('Licensing Warning', [ |
|
45
|
|
|
'dropdown' => true, |
|
46
|
|
|
'icon' => 'warning-sign', |
|
47
|
|
|
'label' => '', |
|
48
|
|
|
'pull-right' => true |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
$licensing->setAttribute('class', $licensing->getAttribute('class') .' menu-danger'); |
|
52
|
|
|
|
|
53
|
|
|
$licensing->addChild('This product will expire soon', [ |
|
54
|
|
|
'dropdown-header' => true |
|
55
|
|
|
]); |
|
56
|
|
|
$licensing->addChild('Licensed until '. $user->getLicensedUntil()->format('d M Y H:i'), [ |
|
57
|
|
|
'dropdown-header' => true |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// $menu->addChild('Tenants', array('route' => 'vivait_auth_tenant')); |
|
|
|
|
|
|
62
|
|
|
// $menu->addChild('Groups', array('route' => 'vivait_auth_group')); |
|
63
|
|
|
// $menu->addChild('Users', array('route' => 'vivait_auth_user')); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.