-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathNavbarController.php
More file actions
120 lines (103 loc) · 3.54 KB
/
NavbarController.php
File metadata and controls
120 lines (103 loc) · 3.54 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* NavbarController.php
* avanzu-admin
* Date: 23.02.14
*/
namespace Avanzu\AdminThemeBundle\Controller;
use Avanzu\AdminThemeBundle\Event\MessageListEvent;
use Avanzu\AdminThemeBundle\Event\NotificationListEvent;
use Avanzu\AdminThemeBundle\Event\ShowUserEvent;
use Avanzu\AdminThemeBundle\Event\TaskListEvent;
use Avanzu\AdminThemeBundle\Event\ThemeEvents;
use Avanzu\AdminThemeBundle\Controller\EmitterController;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Response;
class NavbarController extends EmitterController
{
const MAX_NOTIFICATIONS = 5;
const MAX_MESSAGES = 5;
const MAX_TASKS = 5;
/**
* @return EventDispatcher
*/
protected function getDispatcher()
{
return $this->get('event_dispatcher');
}
public function notificationsAction($max = self::MAX_NOTIFICATIONS)
{
if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_NOTIFICATIONS)) {
return new Response();
}
$listEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_NOTIFICATIONS, new NotificationListEvent());
return $this->render(
'@AvanzuAdminTheme/Navbar/notifications.html.twig',
[
'notifications' => $listEvent->getNotifications(),
'total' => $listEvent->getTotal(),
]
);
}
/**
* @param int $max
*
* @return Response
*/
public function messagesAction($max = self::MAX_MESSAGES)
{
if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_MESSAGES)) {
return new Response();
}
$listEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_MESSAGES, new MessageListEvent());
return $this->render(
'@AvanzuAdminTheme/Navbar/messages.html.twig',
[
'messages' => $listEvent->getMessages(),
'total' => $listEvent->getTotal(),
]
);
}
/**
* @param int $max
*
* @return Response
*/
public function tasksAction($max = self::MAX_TASKS)
{
if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_TASKS)) {
return new Response();
}
$listEvent = $this->triggerMethod(ThemeEvents::THEME_TASKS, new TaskListEvent($max));
return $this->render(
'@AvanzuAdminTheme/Navbar/tasks.html.twig',
[
'tasks' => $listEvent->getTasks(),
'total' => $listEvent->getTotal(),
]
);
}
/**
* @return Response
*/
public function userAction()
{
if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_NAVBAR_USER)) {
return new Response();
}
/** @var ShowUserEvent $userEvent */
$userEvent = $this->triggerMethod(ThemeEvents::THEME_NAVBAR_USER, new ShowUserEvent());
if ($userEvent instanceof ShowUserEvent) {
return $this->render(
'@AvanzuAdminTheme/Navbar/user.html.twig',
[
'user' => $userEvent->getUser(),
'links' => $userEvent->getLinks(),
'showProfileLink' => $userEvent->isShowProfileLink(),
'showLogoutLink' => $userEvent->isShowLogoutLink(),
]
);
}
return new Response();
}
}