src/Controller/HomeController.php line 23

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Customer;
  4. use App\Entity\Financier;
  5. use App\Entity\Formation;
  6. use App\Entity\Link;
  7. use App\Entity\Log;
  8. use App\Entity\Trainee;
  9. use App\Entity\TraineeFormation;
  10. use App\Entity\User;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use http\Client;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. class HomeController extends AbstractController
  17. {
  18.     #[Route('/'name'app_home')]
  19.     public function index(EntityManagerInterface $entityManager): Response
  20.     {
  21.         if (in_array('ROLE_TEACHER'$this->getUser()->getRoles(), true)) {
  22.             return $this->redirectToRoute('app_home_trainer');
  23.         }
  24.         //Formation créée mais convocation pas encore envoyée
  25.         $nbFormationsBrouillons 0;
  26.         //Convocation envoyée mais date < date de début de formation
  27.         $nbFormationsAmont 0;
  28.         //Convocation envoyée et date de début de formation < today < date de fin de formation
  29.         $nbFormationsEnCours 0;
  30.         //Convocation envoyée et date de fin de formation < today
  31.         $nbFormationsAval 0;
  32.         //Convocation envoyée et date de fin de formation + 6 mois < today
  33.         $nbFormationsArchivees 0;
  34.         $allFormations $entityManager->getRepository(Formation::class)->findBy([],['id' => 'DESC']);
  35.         foreach ($allFormations as $course) {
  36.             if ($course->getStatus() == 0) {
  37.                 $nbFormationsBrouillons++;
  38.             }
  39.             if ($course->getStatus() == 1) {
  40.                 $fill1 0;
  41.                 $fill2 0;
  42.                 $fill3 0;
  43.                 $fill4 0;
  44.                 $updatedDatEnd $course->getDateFinFormation()->modify('+3 month');
  45.                 $date = new \DateTime();
  46.                 $currentDate $date->format('Y-m-d');
  47.                if ($updatedDatEnd->format('Y-m-d')  <  $currentDate) {
  48.                    $fill4 1;
  49.                }
  50.                 if($course->getDateFinFormation()->format('Y-m-d') <  $currentDate) {
  51.                     $fill3 1;
  52.                 }
  53.                 if ($currentDate $course->getDateDebutFormation()->format('Y-m-d') and $currentDate $course->getDateFinFormation()->format('Y-m-d')) {
  54.                     $fill2 1;
  55.                 }
  56.                 if ($currentDate $course->getDateDebutFormation()->format('Y-m-d')) {
  57.                     $fill1 1;
  58.                 }
  59.                 if($fill4) {
  60.                     $nbFormationsArchivees++;
  61.                 }
  62.                 if($fill3) {
  63.                     $nbFormationsAval ++;
  64.                 }
  65.                 if($fill2) {
  66.                     $nbFormationsEnCours ++;
  67.                 }
  68.                 if($fill1) {
  69.                     $nbFormationsAmont ++;
  70.                 }
  71.             }
  72.          }
  73.         $log $entityManager->getRepository(Log::class)->findBy([],['id' => 'DESC'], 10);
  74.         $allTraineeConvo $entityManager->getRepository(TraineeFormation::class)->findAllTraineeByDate();
  75.         $datesTab= [];
  76.         $valTab = [];
  77.         foreach ($allTraineeConvo as $key => $trainee ) {
  78.             if ($trainee['dateConvocation'] != null) {
  79.                 array_push($datesTab$trainee['dateConvocation']->format('Y-m-d'));
  80.                 array_push($valTab$trainee['total']);
  81.             }
  82.         }
  83.         $nbTeachers count($entityManager->getRepository(User::class)->findUsers('ROLE_TEACHER'));
  84.         $nbLink count($entityManager->getRepository(Link::class)->findAll());
  85.         $nbContactClient count($entityManager->getRepository(Customer::class)->findAll());
  86.         $nbFinanceur count($entityManager->getRepository(Financier::class)->findAll());
  87.         return $this->render('views/dashboard.html.twig', [
  88.             'controller_name' => 'HomeController',
  89.             'nbFormationsBrouillons' => $nbFormationsBrouillons,
  90.             'nbFormationsAmont' => $nbFormationsAmont,
  91.             'nbFormationsEnCours' => $nbFormationsEnCours,
  92.             'nbFormationsAval' => $nbFormationsAval,
  93.             'nbFormationsArchivees' => $nbFormationsArchivees,
  94.             'nbTotale' => count($allFormations),
  95.             'log' => $log,
  96.             'datesTab' => $datesTab,
  97.             'valTab' => $valTab,
  98.             'nbLink' => $nbLink,
  99.             'nbContactClient' => $nbContactClient,
  100.             'nbFinanceur' => $nbFinanceur,
  101.             'nbTeachers' => $nbTeachers
  102.         ]);
  103.     }
  104.     #[Route('/dashboard'name'app_home_trainer')]
  105.     public function indexTrainer(EntityManagerInterface $entityManager): Response
  106.     {
  107.         //Formation créée mais convocation pas encore envoyée
  108.         $nbFormationsBrouillons 0;
  109.         //Convocation envoyée mais date < date de début de formation
  110.         $nbFormationsAmont 0;
  111.         //Convocation envoyée et date de début de formation < today < date de fin de formation
  112.         $nbFormationsEnCours 0;
  113.         //Convocation envoyée et date de fin de formation < today
  114.         $nbFormationsAval 0;
  115.         //Convocation envoyée et date de fin de formation + 6 mois < today
  116.         $nbFormationsArchivees 0;
  117.         $allFormations $entityManager->getRepository(Formation::class)->findBy([],['id' => 'DESC']);
  118.         foreach ($allFormations as $course) {
  119.             if ($course->getStatus() == 0) {
  120.                 $nbFormationsBrouillons++;
  121.             }
  122.             if ($course->getStatus() == 1) {
  123.                 $fill1 0;
  124.                 $fill2 0;
  125.                 $fill3 0;
  126.                 $fill4 0;
  127.                 $updatedDatEnd $course->getDateFinFormation()->modify('+3 month');
  128.                 $date = new \DateTime();
  129.                 $currentDate $date->format('Y-m-d');
  130.                 if ($updatedDatEnd->format('Y-m-d')  <  $currentDate) {
  131.                     $fill4 1;
  132.                 }
  133.                 if($course->getDateFinFormation()->format('Y-m-d') <  $currentDate) {
  134.                     $fill3 1;
  135.                 }
  136.                 if ($currentDate $course->getDateDebutFormation()->format('Y-m-d') and $currentDate $course->getDateFinFormation()->format('Y-m-d')) {
  137.                     $fill2 1;
  138.                 }
  139.                 if ($currentDate $course->getDateDebutFormation()->format('Y-m-d')) {
  140.                     $fill1 1;
  141.                 }
  142.                 if($fill4) {
  143.                     $nbFormationsArchivees++;
  144.                 }
  145.                 if($fill3) {
  146.                     $nbFormationsAval ++;
  147.                 }
  148.                 if($fill2) {
  149.                     $nbFormationsEnCours ++;
  150.                 }
  151.                 if($fill1) {
  152.                     $nbFormationsAmont ++;
  153.                 }
  154.             }
  155.         }
  156.         $log $entityManager->getRepository(Log::class)->findBy([],['id' => 'DESC'], 10);
  157.         $allTraineeConvo $entityManager->getRepository(TraineeFormation::class)->findAllTraineeByDate();
  158.         $datesTab= [];
  159.         $valTab = [];
  160.         foreach ($allTraineeConvo as $key => $trainee ) {
  161.             if ($trainee['dateConvocation'] != null) {
  162.                 array_push($datesTab$trainee['dateConvocation']->format('Y-m-d'));
  163.                 array_push($valTab$trainee['total']);
  164.             }
  165.         }
  166.         $nbTeachers count($entityManager->getRepository(User::class)->findUsers('ROLE_TEACHER'));
  167.         $nbLink count($entityManager->getRepository(Link::class)->findAll());
  168.         $nbContactClient count($entityManager->getRepository(Customer::class)->findAll());
  169.         $nbFinanceur count($entityManager->getRepository(Financier::class)->findAll());
  170.         return $this->render('views/dashboard-trainer.html.twig', [
  171.             'controller_name' => 'HomeController',
  172.             'nbFormationsBrouillons' => $nbFormationsBrouillons,
  173.             'nbFormationsAmont' => $nbFormationsAmont,
  174.             'nbFormationsEnCours' => $nbFormationsEnCours,
  175.             'nbFormationsAval' => $nbFormationsAval,
  176.             'nbFormationsArchivees' => $nbFormationsArchivees,
  177.             'nbTotale' => count($allFormations),
  178.             'log' => $log,
  179.             'datesTab' => $datesTab,
  180.             'valTab' => $valTab,
  181.             'nbLink' => $nbLink,
  182.             'nbContactClient' => $nbContactClient,
  183.             'nbFinanceur' => $nbFinanceur,
  184.             'nbTeachers' => $nbTeachers
  185.         ]);
  186.     }
  187. }