Sfoglia il codice sorgente

Dashboard films vus et à voir

François Drouhard 2 anni fa
parent
commit
fcb1af50a1

+ 25 - 0
src/Controller/DashboardController.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Controller;
+
+use App\Repository\FilmRepository;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Bundle\SecurityBundle\Security;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\Annotation\Route;
+
+class DashboardController extends AbstractController
+{
+    #[Route('/dashboard', name: 'app_dashboard')]
+    public function index(FilmRepository $filmRepository, Security $security): Response
+    {
+        /** @var \App\Entity\User $user */
+        $user = $security->getUser();
+        $nbSeen = $filmRepository->nbFilmSeenBy ($user->getId());
+        $nbToSee = $filmRepository->nbFilmToSeeBy($user->getId());
+        return $this->render('dashboard/index.html.twig', [
+            'nbSeen'    => $nbSeen,
+            'nbToSee'   => $nbToSee
+        ]);
+    }
+}

+ 26 - 0
src/Repository/FilmRepository.php

@@ -158,4 +158,30 @@ class FilmRepository extends ServiceEntityRepository
             ->getResult()
         ;
     }
+
+    public function nbFilmSeenBy(int $userId)
+    {
+        $qb = $this->createQueryBuilder('f');
+        return $qb
+            ->leftJoin('f.usersWantToView', 'wan')
+            ->where($qb->expr()->in('wan', ':user'))
+            ->setParameter('user', $userId)
+            ->select('COUNT(f.id)')
+            ->getQuery()
+            ->getSingleScalarResult()
+        ;
+    }
+
+    public function nbFilmToSeeBy(int $userId)
+    {
+        $qb = $this->createQueryBuilder('f');
+        return $qb
+            ->leftJoin('f.usersWhoSeen', 'wan')
+            ->where($qb->expr()->in('wan', ':user'))
+            ->setParameter('user', $userId)
+            ->select('COUNT(f.id)')
+            ->getQuery()
+            ->getSingleScalarResult()
+        ;
+    }
 }

+ 24 - 0
templates/dashboard/index.html.twig

@@ -0,0 +1,24 @@
+{% extends "base.html.twig" %}
+
+{% block title %}{{ parent() }} - {{"dashboard" | trans }}{% endblock %}
+{% block titre %}{{ "dashboard" | trans }}{% endblock %}
+{% block body %}
+    <div class="d-flex">
+        <div class="card m-3">
+            <div class="card-header">
+                <h4>Films vus</h4>
+            </div>
+            <div class="card-body text-center">
+                {{ nbSeen }}
+            </div>
+        </div>
+        <div class="card m-3">
+            <div class="card-header">
+                <h4>A voir</h4>
+            </div>
+            <div class="card-body text-center">
+                {{ nbToSee }}
+            </div>
+        </div>
+    </div>
+{% endblock %}

+ 1 - 0
translations/messages.fr.yaml

@@ -22,6 +22,7 @@ Content: Contenu de la page
 edit_page: Editer la page
 Previous: Précédente
 Next: Suivante
+dashboard: Tableau de bord
 
 Username: Nom d'utilisateur
 Prenom: Prénom