mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
78 lines
2.5 KiB
PHP
78 lines
2.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\MainBundle\Controller;
|
|
|
|
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;
|
|
|
|
/**
|
|
* @Route("/{_locale}/notification")
|
|
*/
|
|
class NotificationController extends AbstractController
|
|
{
|
|
private Security $security;
|
|
private NotificationRepository $notificationRepository;
|
|
private NotificationRenderer $notificationRenderer;
|
|
private PaginatorFactory $paginatorFactory;
|
|
|
|
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(): Response
|
|
{
|
|
$currentUser = $this->security->getUser();
|
|
|
|
$notificationsNbr = $this->notificationRepository->countAllForAttendee(($currentUser));
|
|
$paginator = $this->paginatorFactory->create($notificationsNbr);
|
|
|
|
$notifications = $this->notificationRepository->findAllForAttendee(
|
|
$currentUser,
|
|
$limit = $paginator->getItemsPerPage(),
|
|
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
|
);
|
|
|
|
$templateData = [];
|
|
|
|
foreach ($notifications as $notification) {
|
|
$data = [
|
|
'template' => $this->notificationRenderer->getTemplate($notification),
|
|
'template_data' => $this->notificationRenderer->getTemplateData($notification),
|
|
'notification' => $notification,
|
|
];
|
|
$templateData[] = $data;
|
|
}
|
|
|
|
return $this->render('@ChillMain/Notification/show.html.twig', [
|
|
'datas' => $templateData,
|
|
'notifications' => $notifications,
|
|
'paginator' => $paginator,
|
|
]);
|
|
}
|
|
}
|