src/Controller/Admin/DashboardController.php line 21

  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Repository\CoursRepository;
  4. use App\Repository\EleveRepository;
  5. use App\Repository\EnseignantRepository;
  6. use App\Repository\NotificationRepository;
  7. use App\Repository\PaymentRepository;
  8. use DateTime;
  9. use DateTimeImmutable;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class DashboardController extends AbstractController
  15. {
  16.     // notifications: 1 = cours publiĆ©, 2 = demande enseignant, 3 = 
  17.     #[Route('/admin/dashboard'name'app_admin_dashboard')]
  18.     public function index(CoursRepository $coursRepositoryEleveRepository $eleveRepositoryNotificationRepository $notificationRepositoryEnseignantRepository $enseignantRepository): Response
  19.     {
  20.         return $this->render('admin/dashboard/index.html.twig', [
  21.             'controller_name' => 'dashboardController',
  22.             'completedCourses' => $coursRepository->findBy(['isValidated' => true,]),
  23.             'courseInProgress' => $coursRepository->findBy(['isValidated' => false]),
  24.             'eleves' => $eleveRepository->findAll(),
  25.             'notifications' => $notificationRepository->findBy(['isRead' => false'destinataire' => $this->getUser()], ['createdAt' => 'DESC'], 5),
  26.             'enseignants' => $enseignantRepository->findBy(['isValidated' => true]),
  27.             'topInstructors' => $enseignantRepository->findBy(['isValidated' => true], ['review' => 'DESC'], 5),
  28.             'allNotifications' => $notificationRepository->findBy(['destinataire' => $this->getUser()], ['createdAt' => 'DESC']),
  29.         ]);
  30.     }
  31.     #[Route('/dashboardEarningsData'name'app_admin_earnings'methods: ['GET'])]
  32.     public function dashboardEarningsData(PaymentRepository $paymentRepository)
  33.     {
  34.         // On affiche le chiffre d'affaire des 12 derniers jours
  35.         $data = [];
  36.         $jours = [];
  37.         
  38.         for ($i=11$i >= 0$i--) { 
  39.             $currentDay = new DateTime(date_format(new DateTimeImmutable(), 'Y-m-d'));
  40.             $date $currentDay->modify("-" $i " day");
  41.             $jours[] = $date->format('d-m-Y');
  42.             $dayStart $date->format('Y-m-d 00:00:00');
  43.             $dayEnd $date->format('Y-m-d 23:59:59');
  44.             $payments $paymentRepository->findBetweenDates(new DateTime($dayStart), new DateTime($dayEnd));
  45.             $totalP 0;
  46.             foreach ($payments as $p) {
  47.                 $totalP += $p->getAmount();
  48.             }
  49.             $data[] = $totalP;
  50.         }
  51.         return new JsonResponse([
  52.             'data' => $data,
  53.             'jours' => $jours
  54.         ]);
  55.     }
  56.     #[Route('/traficSource'name'app_admin_trafic_sources'methods: ['GET'])]
  57.     public function traficSource(CoursRepository $coursRepository
  58.     {
  59.         $cours $coursRepository->findBy(['isValidated' => true], ['vues' => 'DESC'], 4);
  60.         $data = [25252525];
  61.         $totalVues 0;
  62.         foreach ($cours as $c) {
  63.             $totalVues += $c->getVues();
  64.         }
  65.         $totalVues $totalVues == ?? 1;
  66.         $labels = ['Course 1''Course 2''Course 3''Course 4'];
  67.         foreach ($cours as $key => $c) {
  68.             $data[$key] = number_format(($c->getVues()/$totalVues) * 1002);
  69.             $labels[$key] = $c->getIntitule();
  70.         }
  71.         return new JsonResponse(
  72.             [
  73.                 'data' => $data,
  74.                 'labels' => $labels
  75.             ]
  76.         );
  77.     }
  78. }