mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
fix controller loading and add UserMenu entry
This commit is contained in:
parent
6a0ce72836
commit
e972beee11
@ -15,6 +15,7 @@ use Chill\MainBundle\Notification\NotificationRenderer;
|
|||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Repository\NotificationRepository;
|
use Chill\MainBundle\Repository\NotificationRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
@ -23,27 +24,34 @@ use Symfony\Component\Security\Core\Security;
|
|||||||
*/
|
*/
|
||||||
class NotificationController extends AbstractController
|
class NotificationController extends AbstractController
|
||||||
{
|
{
|
||||||
private $security;
|
private Security $security;
|
||||||
|
private NotificationRepository $notificationRepository;
|
||||||
|
private NotificationRenderer $notificationRenderer;
|
||||||
|
private PaginatorFactory $paginatorFactory;
|
||||||
|
|
||||||
public function __construct(Security $security)
|
public function __construct(
|
||||||
{
|
Security $security,
|
||||||
|
NotificationRepository $notificationRepository,
|
||||||
|
NotificationRenderer $notificationRenderer,
|
||||||
|
PaginatorFactory $paginatorFactory
|
||||||
|
) {
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
|
$this->notificationRepository = $notificationRepository;
|
||||||
|
$this->notificationRenderer = $notificationRenderer;
|
||||||
|
$this->paginatorFactory = $paginatorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/show", name="chill_main_notification_show")
|
* @Route("/show", name="chill_main_notification_show")
|
||||||
*/
|
*/
|
||||||
public function showAction(
|
public function showAction(): Response
|
||||||
NotificationRepository $notificationRepository,
|
{
|
||||||
NotificationRenderer $notificationRenderer,
|
|
||||||
PaginatorFactory $paginatorFactory
|
|
||||||
) {
|
|
||||||
$currentUser = $this->security->getUser();
|
$currentUser = $this->security->getUser();
|
||||||
|
|
||||||
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
|
$notificationsNbr = $this->notificationRepository->countAllForAttendee(($currentUser));
|
||||||
$paginator = $paginatorFactory->create($notificationsNbr);
|
$paginator = $this->paginatorFactory->create($notificationsNbr);
|
||||||
|
|
||||||
$notifications = $notificationRepository->findAllForAttendee(
|
$notifications = $this->notificationRepository->findAllForAttendee(
|
||||||
$currentUser,
|
$currentUser,
|
||||||
$limit = $paginator->getItemsPerPage(),
|
$limit = $paginator->getItemsPerPage(),
|
||||||
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
||||||
@ -53,8 +61,8 @@ class NotificationController extends AbstractController
|
|||||||
|
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
$data = [
|
$data = [
|
||||||
'template' => $notificationRenderer->getTemplate($notification),
|
'template' => $this->notificationRenderer->getTemplate($notification),
|
||||||
'template_data' => $notificationRenderer->getTemplateData($notification),
|
'template_data' => $this->notificationRenderer->getTemplateData($notification),
|
||||||
'notification' => $notification,
|
'notification' => $notification,
|
||||||
];
|
];
|
||||||
$templateData[] = $data;
|
$templateData[] = $data;
|
||||||
|
@ -48,7 +48,7 @@ class Notification
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text")
|
* @ORM\Column(type="text")
|
||||||
*/
|
*/
|
||||||
private string $message;
|
private string $message = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
@ -58,7 +58,7 @@ class Notification
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
*/
|
*/
|
||||||
private string $relatedEntityClass;
|
private string $relatedEntityClass = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
@ -14,14 +14,18 @@ namespace Chill\MainBundle\Routing\MenuBuilder;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class UserMenuBuilder implements LocalMenuBuilderInterface
|
class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||||
{
|
{
|
||||||
private Security $security;
|
private Security $security;
|
||||||
|
|
||||||
public function __construct(Security $security)
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
public function __construct(Security $security, TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
||||||
@ -44,6 +48,17 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
'order' => -9999999,
|
'order' => -9999999,
|
||||||
'icon' => 'map-marker',
|
'icon' => 'map-marker',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$menu
|
||||||
|
->addChild(
|
||||||
|
$this->translator->trans('My notifications'),
|
||||||
|
['route' => 'chill_main_notification_show']
|
||||||
|
)
|
||||||
|
->setExtras([
|
||||||
|
'order' => 600,
|
||||||
|
'icon' => 'envelope'
|
||||||
|
]);
|
||||||
|
|
||||||
$menu
|
$menu
|
||||||
->addChild(
|
->addChild(
|
||||||
'Change password',
|
'Change password',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user