fix controller loading and add UserMenu entry

This commit is contained in:
Julien Fastré 2021-12-25 20:47:54 +01:00
parent 6a0ce72836
commit e972beee11
3 changed files with 39 additions and 16 deletions

View File

@ -15,6 +15,7 @@ use Chill\MainBundle\Notification\NotificationRenderer;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\NotificationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
@ -23,27 +24,34 @@ use Symfony\Component\Security\Core\Security;
*/
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->notificationRepository = $notificationRepository;
$this->notificationRenderer = $notificationRenderer;
$this->paginatorFactory = $paginatorFactory;
}
/**
* @Route("/show", name="chill_main_notification_show")
*/
public function showAction(
NotificationRepository $notificationRepository,
NotificationRenderer $notificationRenderer,
PaginatorFactory $paginatorFactory
) {
public function showAction(): Response
{
$currentUser = $this->security->getUser();
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
$paginator = $paginatorFactory->create($notificationsNbr);
$notificationsNbr = $this->notificationRepository->countAllForAttendee(($currentUser));
$paginator = $this->paginatorFactory->create($notificationsNbr);
$notifications = $notificationRepository->findAllForAttendee(
$notifications = $this->notificationRepository->findAllForAttendee(
$currentUser,
$limit = $paginator->getItemsPerPage(),
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
@ -53,8 +61,8 @@ class NotificationController extends AbstractController
foreach ($notifications as $notification) {
$data = [
'template' => $notificationRenderer->getTemplate($notification),
'template_data' => $notificationRenderer->getTemplateData($notification),
'template' => $this->notificationRenderer->getTemplate($notification),
'template_data' => $this->notificationRenderer->getTemplateData($notification),
'notification' => $notification,
];
$templateData[] = $data;

View File

@ -48,7 +48,7 @@ class Notification
/**
* @ORM\Column(type="text")
*/
private string $message;
private string $message = '';
/**
* @ORM\Column(type="json")
@ -58,7 +58,7 @@ class Notification
/**
* @ORM\Column(type="string", length=255)
*/
private string $relatedEntityClass;
private string $relatedEntityClass = '';
/**
* @ORM\Column(type="integer")

View File

@ -14,14 +14,18 @@ namespace Chill\MainBundle\Routing\MenuBuilder;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserMenuBuilder implements LocalMenuBuilderInterface
{
private Security $security;
public function __construct(Security $security)
private TranslatorInterface $translator;
public function __construct(Security $security, TranslatorInterface $translator)
{
$this->security = $security;
$this->translator = $translator;
}
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
@ -44,6 +48,17 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
'order' => -9999999,
'icon' => 'map-marker',
]);
$menu
->addChild(
$this->translator->trans('My notifications'),
['route' => 'chill_main_notification_show']
)
->setExtras([
'order' => 600,
'icon' => 'envelope'
]);
$menu
->addChild(
'Change password',