Notification with paginitation

This commit is contained in:
Marc Ducobu
2021-06-30 12:02:18 +02:00
parent 0907ae1602
commit 50a4df3d0f
4 changed files with 64 additions and 17 deletions

View File

@@ -3,12 +3,16 @@
namespace Chill\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Notification\NotificationRenderer;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Routing\Annotation\Route;
use Chill\MainBundle\Pagination\PaginatorFactory;
/**
* @Route("/{_locale}/notification")
*/
class NotificationController extends AbstractController
{
private $security;
@@ -18,11 +22,23 @@ class NotificationController extends AbstractController
$this->security = $security;
}
public function showAction(NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer)
/**
* @Route("/show", name="chill_main_notification_show")
*/
public function showAction(
NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer,
PaginatorFactory $paginatorFactory)
{
$currentUser = $this->security->getUser();
$notifications = $notificationRepository->findAllForAttendee($currentUser);
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
$paginator = $paginatorFactory->create($notificationsNbr);
$notifications = $notificationRepository->findAllForAttendee(
$currentUser,
$limit=$paginator->getItemsPerPage(),
$offset= $paginator->getCurrentPage()->getFirstItemNumber());
$templateData = array();
foreach ($notifications as $notification) {
@@ -34,9 +50,10 @@ class NotificationController extends AbstractController
$templateData[] = $data;
}
return $this->render('ChillMainBundle:Notification:show.html.twig', [
return $this->render('@ChillMain/Notification/show.html.twig', [
'datas' => $templateData,
'notifications' => $notifications,
'notifications' => $notifications,
'paginator' => $paginator,
]);
}
}