vendor/kevinpapst/adminlte-bundle/Controller/NavbarController.php line 132

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the AdminLTE bundle.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. namespace KevinPapst\AdminLTEBundle\Controller;
  9. use KevinPapst\AdminLTEBundle\Event\MessageListEvent;
  10. use KevinPapst\AdminLTEBundle\Event\NavbarUserEvent;
  11. use KevinPapst\AdminLTEBundle\Event\NotificationListEvent;
  12. use KevinPapst\AdminLTEBundle\Event\ShowUserEvent;
  13. use KevinPapst\AdminLTEBundle\Event\TaskListEvent;
  14. use KevinPapst\AdminLTEBundle\Helper\ContextHelper;
  15. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16. use Symfony\Component\HttpFoundation\Response;
  17. class NavbarController extends EmitterController
  18. {
  19. /**
  20. * @var int|null
  21. */
  22. private $maxNotifications;
  23. /**
  24. * @var int|null
  25. */
  26. private $maxMessages;
  27. /**
  28. * @var int|null
  29. */
  30. private $maxTasks;
  31. public function __construct(EventDispatcherInterface $dispatcher, ContextHelper $helper)
  32. {
  33. parent::__construct($dispatcher);
  34. $this->maxNotifications = $helper->getOption('max_navbar_notifications');
  35. $this->maxMessages = $helper->getOption('max_navbar_messages');
  36. $this->maxTasks = $helper->getOption('max_navbar_tasks');
  37. }
  38. /**
  39. * @param int|null $max
  40. * @return Response
  41. */
  42. public function notificationsAction($max = null): Response
  43. {
  44. if (!$this->hasListener(NotificationListEvent::class)) {
  45. return new Response();
  46. }
  47. if (null === $max) {
  48. $max = (int) $this->maxNotifications;
  49. }
  50. /** @var NotificationListEvent $listEvent */
  51. $listEvent = $this->dispatch(new NotificationListEvent($max));
  52. return $this->render(
  53. '@AdminLTE/Navbar/notifications.html.twig',
  54. [
  55. 'notifications' => $listEvent->getNotifications(),
  56. 'total' => $listEvent->getTotal(),
  57. ]
  58. );
  59. }
  60. /**
  61. * @param int|null $max
  62. * @return Response
  63. */
  64. public function messagesAction($max = null): Response
  65. {
  66. if (!$this->hasListener(MessageListEvent::class)) {
  67. return new Response();
  68. }
  69. if (null === $max) {
  70. $max = (int) $this->maxMessages;
  71. }
  72. /** @var MessageListEvent $listEvent */
  73. $listEvent = $this->dispatch(new MessageListEvent($max));
  74. return $this->render(
  75. '@AdminLTE/Navbar/messages.html.twig',
  76. [
  77. 'messages' => $listEvent->getMessages(),
  78. 'total' => $listEvent->getTotal(),
  79. ]
  80. );
  81. }
  82. /**
  83. * @param int|null $max
  84. * @return Response
  85. */
  86. public function tasksAction($max = null): Response
  87. {
  88. if (!$this->hasListener(TaskListEvent::class)) {
  89. return new Response();
  90. }
  91. if (null === $max) {
  92. $max = (int) $this->maxTasks;
  93. }
  94. /** @var TaskListEvent $listEvent */
  95. $listEvent = $this->dispatch(new TaskListEvent($max));
  96. return $this->render(
  97. '@AdminLTE/Navbar/tasks.html.twig',
  98. [
  99. 'tasks' => $listEvent->getTasks(),
  100. 'total' => $listEvent->getTotal(),
  101. ]
  102. );
  103. }
  104. /**
  105. * @return Response
  106. */
  107. public function userAction(): Response
  108. {
  109. if (!$this->hasListener(NavbarUserEvent::class)) {
  110. return new Response();
  111. }
  112. /** @var ShowUserEvent $userEvent */
  113. $userEvent = $this->dispatch(new NavbarUserEvent());
  114. if ($userEvent instanceof ShowUserEvent && null !== $userEvent->getUser()) {
  115. return $this->render(
  116. '@AdminLTE/Navbar/user.html.twig',
  117. [
  118. 'user' => $userEvent->getUser(),
  119. 'links' => $userEvent->getLinks(),
  120. 'showProfileLink' => $userEvent->isShowProfileLink(),
  121. 'showLogoutLink' => $userEvent->isShowLogoutLink(),
  122. ]
  123. );
  124. }
  125. return new Response();
  126. }
  127. }