|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
+use App\Repository\CommentaireRepository;
|
|
|
+use App\Repository\FilmRepository;
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
@@ -11,8 +13,16 @@ use Symfony\UX\Chartjs\Model\Chart;
|
|
|
class DashboardController extends AbstractController
|
|
|
{
|
|
|
|
|
|
- public function index(ChartBuilderInterface $chartBuilderInterface): Response
|
|
|
+ public function index(
|
|
|
+ ChartBuilderInterface $chartBuilderInterface,
|
|
|
+ FilmRepository $filmRepository,
|
|
|
+ CommentaireRepository $commentaireRepository
|
|
|
+ ): Response
|
|
|
{
|
|
|
+ $filmsVus = $filmRepository->countFilmsVusBy($this->getUser());
|
|
|
+ $filmsFavoris = $filmRepository->countFilmsFavorisBy($this->getUser());
|
|
|
+ $commentairesParMois = $commentaireRepository->countCommentairesParMois();
|
|
|
+
|
|
|
$chart = $chartBuilderInterface->createChart(Chart::TYPE_DOUGHNUT);
|
|
|
$chart->setData([
|
|
|
'labels' => ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
|
@@ -35,8 +45,67 @@ class DashboardController extends AbstractController
|
|
|
],
|
|
|
]);
|
|
|
|
|
|
+ $chartDatesAjout = $chartBuilderInterface->createChart(Chart::TYPE_LINE);
|
|
|
+ $ajoutsParMois = $filmRepository->countAjoutsParMois();
|
|
|
+
|
|
|
+ $months = [];
|
|
|
+ $entryCounts = [];
|
|
|
+ foreach ($ajoutsParMois as $data) {
|
|
|
+ $months[] = $data['month'];
|
|
|
+ $entryCounts[] = $data['entryCount'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $chartDatesAjout->setData([
|
|
|
+ 'labels' => $months,
|
|
|
+ 'datasets' => [
|
|
|
+ [
|
|
|
+ 'label' => 'Nombre de films ajoutés par mois',
|
|
|
+ 'data' => $entryCounts
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $chart->setOptions([
|
|
|
+ 'scales' => [
|
|
|
+ 'y' => [
|
|
|
+ 'suggestedMin' => 0,
|
|
|
+ 'suggestedMax' => 100,
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $months = [];
|
|
|
+ $entryCounts = [];
|
|
|
+ foreach ($commentairesParMois as $data) {
|
|
|
+ $months[] = $data['month'];
|
|
|
+ $entryCounts[] = $data['entryCount'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $chartCommentairesAjout = $chartBuilderInterface->createChart(Chart::TYPE_LINE);
|
|
|
+ $chartCommentairesAjout->setData([
|
|
|
+ 'labels' => $months,
|
|
|
+ 'datasets' => [
|
|
|
+ [
|
|
|
+ 'label' => 'Nombre de films ajoutés par mois',
|
|
|
+ 'data' => $entryCounts
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $chart->setOptions([
|
|
|
+ 'scales' => [
|
|
|
+ 'y' => [
|
|
|
+ 'suggestedMin' => 0,
|
|
|
+ 'suggestedMax' => 100,
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+
|
|
|
return $this->render('dashboard/index.html.twig', [
|
|
|
'chart' => $chart,
|
|
|
+ 'chartAjoutsParMois' => $chartDatesAjout,
|
|
|
+ 'chartCommentairesAjouts' => $chartCommentairesAjout
|
|
|
]);
|
|
|
}
|
|
|
}
|