src/Controller/ClassRoomController.php line 1226

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  10. use Knp\Snappy\Pdf;
  11. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use App\Repository\AttributionRepository;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use App\Repository\ClassRoomRepository;
  16. use App\Repository\SchoolYearRepository;
  17. use App\Repository\QuaterRepository;
  18. use App\Repository\SequenceRepository;
  19. use App\Repository\EvaluationRepository;
  20. use App\Repository\StudentRepository;
  21. use App\Repository\MainTeacherRepository;
  22. use App\Repository\MarkRepository;
  23. use App\Entity\ClassRoom;
  24. use App\Entity\Course;
  25. use App\Entity\SchoolYear;
  26. use App\Form\ClassRoomType;
  27. use App\Entity\Sequence;
  28. use App\Entity\Quater;
  29. use App\Repository\SubscriptionRepository;
  30. use App\Repository\InstallmentRepository;
  31. use App\Service\SchoolYearService;
  32. /**
  33.  * ClassRoom controller.
  34.  *
  35.  * @Route("prof/rooms")
  36.  */
  37. class ClassRoomController extends AbstractController
  38. {
  39.     private $em;
  40.     private $repo;
  41.     private $scRepo;
  42.     private $stdRepo;
  43.     private $subRepo;
  44.     private $seqRepo;
  45.     private $evalRepo;
  46.     private $qtRepo;
  47.     private $markRepo;
  48.     private  $snappy;
  49.     private $session;
  50.     private $quaterData;
  51.     private Pdf $pdf;
  52.     private SchoolYearService $schoolYearService;
  53.     private MainTeacherRepository $mainTeacherRepo;
  54.     private AttributionRepository $attRepo;
  55.     private InstallmentRepository $instRepo;
  56.     public function __construct(Pdf $pdf,InstallmentRepository $instRepoAttributionRepository $attRepoMainTeacherRepository $mainTeacherRepoSchoolYearService $schoolYearService,MarkRepository $markRepoQuaterRepository $qtRepoStudentRepository $stdRepoEvaluationRepository $evalRepoSchoolYearRepository $scRepoSequenceRepository $seqRepoClassRoomRepository $repo,  SubscriptionRepository $subRepo,  EntityManagerInterface $emPdf $snappy,  SessionInterface $session)
  57.     {
  58.         $this->quaterData = [];
  59.         $this->em $em;
  60.         $this->pdf $pdf;
  61.         $this->repo $repo;
  62.         $this->scRepo $scRepo;
  63.         $this->attRepo $attRepo;
  64.         $this->seqRepo $seqRepo;
  65.         $this->evalRepo $evalRepo;
  66.         $this->mainTeacherRepo $mainTeacherRepo;
  67.         $this->stdRepo $stdRepo;
  68.         $this->instRepo $instRepo;
  69.         $this->qtRepo $qtRepo;
  70.         $this->subRepo $subRepo;
  71.         $this->markRepo $markRepo;
  72.         $this->snappy $snappy;
  73.         $this->session $session;        
  74.         $this->schoolYearService $schoolYearService;
  75.     }
  76.     /**
  77.      * Lists all ClassRoomme entities.
  78.      *
  79.      * @Route("/", name="admin_classrooms")
  80.      * @Method("GET")
  81.      * @Template()
  82.      */
  83.     public function indexAction()
  84.     {
  85.         $classrooms $this->repo->findAll();
  86.         $year $this->schoolYearService->sessionYearById();
  87.         $seq $this->seqRepo->findOneBy(array("activated" => true));
  88.         $mainTeachers =  $this->mainTeacherRepo->findBy(array("schoolYear" => $year));
  89.         $mainTeachersMap = array();
  90.         foreach($mainTeachers as $mt){
  91.             $mainTeachersMap[$mt->getClassRoom()->getId()] = $mt->getTeacher();
  92.         }
  93.         return $this->render('classroom/index.html.twig', array(
  94.             'mainTeachers' => $mainTeachersMap,
  95.             'classrooms' => $classrooms,
  96.             'year' => $year,
  97.             'seq' => $seq->getId(),
  98.         ));
  99.     }
  100.     /** 
  101.      * Finds and displays a ClassRoomme entity.
  102.      *
  103.      * @Route("/{id}/show", name="admin_classrooms_show", requirements={"id"="\d+"})
  104.      * @Method("GET")
  105.      * @Template()
  106.      */
  107.     public function showAction(ClassRoom $classroomStudentRepository $stdRepo)
  108.     {
  109.         // Année scolaire et seuquence en cours
  110.         $year $this->schoolYearService->sessionYearById();
  111.         $seq $this->seqRepo->findOneBy(array("activated" => true));
  112.         // Elèves inscrits
  113.         $studentEnrolled $stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  114.         $fileExists = [];
  115.         foreach ($studentEnrolled as $std) {
  116.             $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  117.             $fileExists[$std->getId()] = file_exists($filename);
  118.         }
  119.         
  120.           // Attributions de cours durant l'annee
  121.         $attributions $this->attRepo->findByYearAndByRoom($year,$classroom);
  122.         $attributionsMapCourses null;
  123.         foreach($attributions as $att){
  124.               $attributionsMapCourses[$att->getCourse()->getId()] = $att;
  125.         }
  126.         // Liste des resulats au examens officiels
  127.         $officialExamResults $this->subRepo->countByMention($year$classroom);
  128.         $mentionCategories = [];
  129.         $mentionCountCategories = [];
  130.         foreach ($officialExamResults as $exam) {
  131.             switch ($exam["officialExamResult"]) {
  132.                 case  "0":
  133.                     $mentionCategories[] = "ECHEC";
  134.                     break;
  135.                 case  "1p":
  136.                     $mentionCategories[] = "PASSABLE";
  137.                     break;
  138.                 case  "1a":
  139.                     $mentionCategories[] = "ASSEZ-BIEN";
  140.                     break;
  141.                 case  "1b":
  142.                     $mentionCategories[] = "BIEN";
  143.                     break;
  144.                 case  "1t":
  145.                     $mentionCategories[] = "TRES-BIEN";
  146.                     break;
  147.                 case  "1e":
  148.                     $mentionCategories[] = "EXCELLENT";
  149.                     break;
  150.                 case  "A":
  151.                     $mentionCategories[] = "5 POINTS";
  152.                     break;
  153.                 case  "B":
  154.                     $mentionCategories[] = "4 POINTS";
  155.                     break;
  156.                 case  "C":
  157.                     $mentionCategories[] = "3 POINTS";
  158.                     break;
  159.                 case  "D":
  160.                     $mentionCategories[] = "2 POINTS";
  161.                     break;
  162.                 case  "E":
  163.                     $mentionCategories[] = "1 POINT";
  164.                     break;
  165.             }
  166.             $mentionCountCategories[] = $exam["count"];
  167.         }
  168.         // Extraction de donnees pour les graphes
  169.         $seqs $this->seqRepo->findSequenceThisYear($year);
  170.         $evalSeqs = [];
  171.         foreach ($seqs as $seq) {
  172.             $evalSeqs[$seq->getId()] = $this->evalRepo->findBy(array("classRoom" => $classroom"sequence" => $seq));
  173.         }
  174.         $courses = [];
  175.         $averageSeqs = [];
  176.         // Traitements de donnees pour les graphes de notes sequentielles
  177.         foreach ($evalSeqs[$seq->getId()] as $eval) {
  178.             $courses[] = $eval->getCourse()->getWording();
  179.         }
  180.         foreach ($seqs as $seq) {
  181.             $average = [];
  182.             foreach ($evalSeqs[$seq->getId()]  as $eval) {
  183.                 $average[] = $eval->getMoyenne();
  184.             }
  185.             $averageSeqs[$seq->getId()] = $average;
  186.         }
  187.         // Recherche de l'enseignant titulaire
  188.         $mainTeacher null;
  189.         foreach($classroom->getMainTeachers() as $mainT){
  190.                 if($mainT->getSchoolYear()->getId() == $year->getId()){
  191.                     $mainTeacher $mainT->getTeacher();
  192.                 }
  193.         }
  194.     
  195.         $results['mainteacher'] = $mainTeacher;
  196.         $results['classroom'] = $classroom;
  197.         $results['attributions'] = $attributionsMapCourses;
  198.         $results['modules'] = $classroom->getModules();
  199.         $results['studentEnrolled'] = $studentEnrolled;
  200.         $results['cours'] = json_encode($courses);
  201.         $results['fileExists'] = $fileExists;
  202.         $results['sessions'] = json_encode($seqs);
  203.         $results['mentionCategories'] = json_encode($mentionCategories);
  204.         $results['mentionCountCategories'] = json_encode($mentionCountCategories);
  205.         foreach ($seqs as $seq) {
  206.             $results[strtolower($seq->getWording())] = json_encode($averageSeqs[$seq->getId()]);
  207.         }
  208.         return $this->render('classroom/show.html.twig'$results);
  209.     }
  210.     /** 
  211.      * Finds and displays a ClassRoomme entity.
  212.      *
  213.      * @Route("/{id}/stat", name="admin_classrooms_stat", requirements={"id"="\d+"})
  214.      * @Method("GET")
  215.      * @Template()
  216.      */
  217.     public function statAction(ClassRoom $classroom)
  218.     {
  219.         return $this->render('classroom/show.html.twig', array());
  220.     }
  221.     
  222.     /**
  223.      * Finds and displays a ClassRoom entity.
  224.      *
  225.      * @Route("/{id}/reportCardsYear", name="admin_classrooms_reportcards_year", requirements={"id"="\d+"})
  226.      * @Method("GET")
  227.      * @Template()
  228.      */
  229.     public function reportCardsYearAction(ClassRoom $classroom)
  230.     {
  231.         set_time_limit(600);
  232.         $connection $this->em->getConnection();
  233.         $year $this->schoolYearService->sessionYearById();
  234.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  235.         $statement $connection->prepare(
  236.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ1 AS
  237.             SELECT DISTINCT  eval.id as eval,crs.id as crs, room.id as room,year.id as year, std.matricule as matricule, std.image_name as profileImagePath,  std.lastname as lastname, std.firstname as firstname, std.birthday as birthday, std.gender as gender,std.birthplace as birthplace , teach.full_name as teacher    , modu.name as module , crs.wording as wording, crs.coefficient as coefficient,m.value as valeur, m.weight as weight, m.appreciation as appreciation
  238.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  239.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  240.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  241.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  242.             JOIN  attribution att    ON  att.course_id      =   crs.id
  243.             JOIN  user  teach ON  att.teacher_id  =   teach.id
  244.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  245.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  246.             JOIN  quater   quat     ON  seq.quater_id     =   quat.id
  247.             JOIN  school_year   year     ON  quat.school_year_id     =   year.id
  248.             WHERE    room.id = ? AND eval.sequence_id =1
  249.           "
  250.         );
  251.         $statement->bindValue(1$classroom->getId());
  252.         $statement->execute();
  253.         $statement $connection->prepare(
  254.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ2 AS
  255.             SELECT DISTINCT  crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  256.             FROM  mark  m   
  257.             JOIN  student    std     ON  m.student_id        =   std.id
  258.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  259.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  260.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 2
  261.             ORDER BY matricule,eval; "
  262.         );
  263.         $statement->bindValue(1$classroom->getId());
  264.         $statement->execute();
  265.         $statement $connection->prepare(
  266.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ3 AS
  267.             SELECT DISTINCT  crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  268.             FROM  mark  m   
  269.             JOIN  student    std     ON  m.student_id        =   std.id
  270.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  271.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  272.             WHERE  eval.class_room_id =? AND eval.sequence_id = 3
  273.             ORDER BY matricule,eval; "
  274.         );
  275.         $statement->bindValue(1$classroom->getId());
  276.         $statement->execute();
  277.         $statement $connection->prepare(
  278.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ4 AS
  279.             SELECT DISTINCT  crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  280.             FROM  mark  m   
  281.             JOIN  student    std     ON  m.student_id        =   std.id
  282.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  283.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  284.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 4
  285.             ORDER BY matricule,eval; "
  286.         );
  287.         $statement->bindValue(1$classroom->getId());
  288.         $statement->execute();
  289.         $statement $connection->prepare(
  290.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ5 AS
  291.             SELECT DISTINCT  crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  292.             FROM  mark  m   
  293.             JOIN  student    std     ON  m.student_id        =   std.id
  294.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  295.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  296.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 5
  297.             ORDER BY matricule,eval; "
  298.         );
  299.         $statement->bindValue(1$classroom->getId());
  300.         $statement->execute();
  301.         $statement $connection->prepare(
  302.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ6 AS
  303.             SELECT DISTINCT  eval.id as eval,crs.id as crs, std.matricule as matricule,  m.value as valeur, m.weight as weight, m.appreciation as appreciation
  304.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  305.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  306.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  307.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  308.             WHERE    room.id = ? AND eval.sequence_id = 6
  309.             ORDER BY std.matricule"
  310.         );
  311.         $statement->bindValue(1$classroom->getId());
  312.         $statement->execute();
  313.         $dataYear $this->em->getConnection()->executeQuery("select *  from V_STUDENT_MARK_DATA_SEQ1 
  314.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ2 ON  V_STUDENT_MARK_DATA_SEQ1.matricule = V_STUDENT_MARK_DATA_SEQ2.matricule 
  315.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ3 ON  V_STUDENT_MARK_DATA_SEQ2.matricule = V_STUDENT_MARK_DATA_SEQ3.matricule 
  316.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ4 ON  V_STUDENT_MARK_DATA_SEQ3.matricule = V_STUDENT_MARK_DATA_SEQ4.matricule 
  317.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ5 ON  V_STUDENT_MARK_DATA_SEQ4.matricule = V_STUDENT_MARK_DATA_SEQ5.matricule 
  318.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ6 ON  V_STUDENT_MARK_DATA_SEQ5.matricule = V_STUDENT_MARK_DATA_SEQ6.matricule 
  319.             ")->fetchAll();
  320.         $this->snappy->setTimeout(600);
  321.         $html $this->renderView('classroom/reportcard/annual.html.twig', array(
  322.             'year' => $year,
  323.             'data' => $dataYear,
  324.             'room' => $classroom,
  325.             'year' => $year,
  326.             'students' => $studentEnrolled,
  327.         ));
  328.         return new Response(
  329.             $this->snappy->getOutputFromHtml($html),
  330.             200,
  331.             array(
  332.                 'Content-Type' => 'application/pdf',
  333.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  334.             )
  335.         );
  336.     }
  337.     public function viewSeq(int $i){
  338.         $year $this->schoolYearService->sessionYearById();
  339.         $connection $this->em->getConnection();
  340.         $statement $connection->prepare(
  341.             " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  342.             SELECT DISTINCT  eval.id as eval,crs.id as crs, room.id as room,year.id as year, std.id as std,  teach.full_name as teacher    , modu.id as module,m.value as value, m.weight as weight
  343.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  344.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  345.             JOIN  class_room room    ON  eval.class_room_id     =   room.id
  346.             JOIN  course      crs    ON  eval.course_id      =   crs.id
  347.             JOIN  attribution att    ON  att.course_id      =   crs.id  
  348.             JOIN  user      teach    ON  att.teacher_id  =   teach.id
  349.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  350.             JOIN  sequence    seq    ON  seq.id     =   eval.sequence_id
  351.             JOIN  quater     quat    ON  seq.quater_id     =   quat.id
  352.             JOIN  school_year   year ON  quat.school_year_id     =   year.id
  353.             WHERE att.year_id =? AND  room.id = ? AND eval.sequence_id =?  
  354.             ORDER BY room.id,modu.id ,  std;    "
  355.         );
  356.         $statement->bindValue(1$year->getId());
  357.         $statement->bindValue(2$classroom->getId());
  358.         $statement->bindValue(3$seq->getId());
  359.         $statement->execute();
  360.     }
  361.     /**
  362.      * Finds and displays a ClassRoom entity.
  363.      *
  364.      * @Route("/{id}/reportCardsApcYearapc", name="admin_class_reportcards_apc_year", requirements={"id"="\d+"})
  365.      * @Method("GET")
  366.      * @Template()
  367.      */
  368.     public function reportCards2YearAction(ClassRoom $classroom)
  369.     {
  370.         set_time_limit(600);
  371.         $connection $this->em->getConnection();
  372.         $year $this->schoolYearService->sessionYearById();
  373.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  374.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  375.         $i 1;
  376.         foreach ($sequences as $seq) {
  377.             /*******************************************************************************************************************/
  378.             /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE LA CLASSE**************/
  379.             /*******************************************************************************************************************/
  380.             // CAS DES NOTES SEQUENTIELLES
  381.               // $this->viewSeq($i, $classroom, $seq);
  382.             $this->getViewSeqData$classroom$seq$i);
  383.             
  384.            
  385.             $i++;
  386.         }
  387.         // CAS DES NOTES TRIMESTRIELLES
  388.         $statement $connection->prepare(
  389.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  390.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs,  (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  391.             FROM V_STUDENT_MARK_SEQ1 seq1
  392.             JOIN  V_STUDENT_MARK_SEQ2 seq2  
  393.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  394.             ORDER BY seq1.std"
  395.         );
  396.         $statement->execute();
  397.         $statement $connection->prepare(
  398.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  399.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs,  (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  400.             FROM V_STUDENT_MARK_SEQ3 seq1
  401.             JOIN  V_STUDENT_MARK_SEQ4 seq2  
  402.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  403.             ORDER BY seq1.std"
  404.         );
  405.         $statement->execute();
  406.         $statement $connection->prepare(
  407.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  408.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs,  (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  409.             FROM V_STUDENT_MARK_SEQ5 seq1
  410.             JOIN  V_STUDENT_MARK_SEQ6 seq2  
  411.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  412.             ORDER BY seq1.std"
  413.         );
  414.         $statement->execute();
  415.         // CAS DES NOTES ANNUELLES
  416.         $statement $connection->prepare(
  417.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  418.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule ,  student.image_name as profileImagePath, 
  419.             student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  420.             student.gender as gender,student.birthplace as birthplace , 
  421.             class_room.name as room_name,
  422.             course.wording as course, course.coefficient as coef, 
  423.             module.name as module,
  424.             user.full_name as teacher,
  425.             quat1.std,quat1.modu,
  426.             quat1.value as value1, quat1.weight as weight1,  
  427.             quat2.value as value2,  quat2.weight as weight2,  
  428.             quat3.value as value3,quat3.weight as weight3,
  429.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  430.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  431.             FROM student  
  432.             JOIN V_STUDENT_MARK_QUATER_1  quat1 ON  student.id = quat1.std
  433.             JOIN  class_room ON class_room.id = quat1.room
  434.             JOIN  course    ON course.id = quat1.crs
  435.             JOIN  module    ON course.module_id = quat1.modu
  436.             JOIN user ON user.full_name = quat1.teacher
  437.             JOIN   V_STUDENT_MARK_QUATER_2   quat2  ON  quat1.std = quat2.std AND quat1.crs = quat2.crs
  438.             JOIN 
  439.             V_STUDENT_MARK_QUATER_3   quat3  ON  quat1.std = quat3.std AND quat1.crs = quat3.crs
  440.             ORDER BY  quat1.std, quat1.modu
  441.         
  442.             "
  443.         );
  444.         $statement->execute();
  445.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  446.         // For calculating ranks
  447.         $statement $connection->prepare(
  448.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  449.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  450.             FROM ANNUAL_DATA 
  451.             GROUP BY idStd
  452.             ORDER BY SUM(value*weight*coef) DESC"
  453.         );
  454.         $statement->execute();
  455.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  456.         $annualAvgArray = [];
  457.         $sumAvg 0;
  458.         $rank 0;
  459.         $rankArray = [];
  460.         foreach ($annualAvg as $avg) {
  461.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  462.             $rankArray[$avg['idStd']] = ++$rank;
  463.             $sumAvg += $avg['moyenne'];
  464.         }
  465.         $this->snappy->setTimeout(600);
  466.         $html $this->renderView('classroom/reportcardYear.html.twig', array(
  467.             'year' => $year,
  468.             'data' => $dataYear,
  469.             'room' => $classroom,
  470.             'students' => $studentEnrolled,
  471.             'ranks' => $rankArray,
  472.             'means' => $annualAvgArray,
  473.             'genMean' => $sumAvg sizeof($annualAvgArray),
  474.         ));
  475.         //return new Response($html);
  476.         return new Response(
  477.             $this->snappy->getOutputFromHtml($html),
  478.             200,
  479.             array(
  480.                 'Content-Type' => 'application/pdf',
  481.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  482.             )
  483.         );
  484.     }
  485.     /**
  486.      * Finds and displays a Evaluation entity.
  487.      *
  488.      * @Route("/{room}/{seq}/pdf", name="admin_classrooms_recapitulatif", requirements={"room"="\d+","seq"="\d+"})
  489.      * @Method("GET")
  490.      * @Template()
  491.      * @return Response
  492.      */
  493.     public function recapitulatifAction(ClassRoom $roomSequence $seq)
  494.     {
  495.         // Année scolaire en cours
  496.         $year $this->schoolYearService->sessionYearById();
  497.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  498.         $html $this->renderView('classroom/templating/recapitulatifseqvierge.html.twig', array(
  499.             'room' => $room,
  500.             'seq' => $seq,
  501.             'students' => $studentEnrolled,
  502.             'year' => $year,
  503.         ));
  504.         $options = [
  505.             'orientation' => 'Landscape'// Changer ici entre 'Portrait' ou 'Landscape'
  506.             'page-size' => 'A4',          // Format de page
  507.         ];
  508.         return new Response(
  509.             $this->pdf->getOutputFromHtml($html,  $options),
  510.             200,
  511.             array(
  512.                 'Content-Type'          => 'application/pdf',
  513.                 'Content-Disposition'   => 'inline; filename="fiche_recep_' $room->getName() . '.pdf"'
  514.             )
  515.         );
  516.     }
  517.     /**
  518.      * Finds and displays a ClassRoom entity.
  519.      *
  520.      * @Route("/{id}/recapitulatifseq", name="admin_classrooms_recapitulatif_seq", requirements={"id"="\d+"})
  521.      * @Method("GET")
  522.      * @Template()
  523.      */
  524.     public function recapSeqAction(ClassRoom $roomRequest $request)
  525.     {
  526.         // set_time_limit(600);
  527.         $checkedValues $request->request->get('selected_courses');
  528.         $em $this->getDoctrine()->getManager();
  529.         $year $this->schoolYearService->sessionYearById();
  530.         $seq $this->seqRepo->findOneBy(array("activated" => true));
  531.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  532.         $datas $this->markRepo->findMarksBySequenceAndClassOrderByStd($seq$room);
  533.         
  534.         $html $this->renderView('classroom/recapitulatifseq.html.twig', array(
  535.             'room' => $room,
  536.             'datas' => $datas,
  537.             'year' => $year,
  538.             'seq' => $seq,
  539.             'students' => $studentEnrolled,
  540.             'checkedValues' => $checkedValues
  541.         ));
  542.         return new Response($html);
  543.     }
  544.     /**
  545.      * @Route("/create",name= "admin_classrooms_new", methods={"GET","POST"})
  546.      */
  547.     public function create(Request $request): Response
  548.     {
  549.         if (!$this->getUser()) {
  550.             $this->addFlash('warning''You need login first!');
  551.             return $this->redirectToRoute('app_login');
  552.         }
  553.         $schoolyear = new ClassRoom();
  554.         $form $this->createForm(ClassRoomType::class, $schoolyear);
  555.         $form->handleRequest($request);
  556.         if ($form->isSubmitted() && $form->isValid()) {
  557.             $this->em->persist($schoolyear);
  558.             $this->em->flush();
  559.             $this->addFlash('success''ClassRoom succesfully created');
  560.             return $this->redirectToRoute('admin_classrooms');
  561.         }
  562.         return $this->render(
  563.             'classroom/new.html.twig',
  564.             ['form' => $form->createView()]
  565.         );
  566.     }
  567.     /**
  568.      * Rapport séquentiel d'enregistrement des notes.
  569.      *
  570.      * @Route("/{id}/evalrepport", name="admin_current_fulfilled_eval_show", requirements={"id"="\d+"})
  571.      * @Method("GET")
  572.      * @Template()
  573.      */
  574.     public function currentFullfilledEvalAction(ClassRoom $classroom)
  575.     {
  576.         $em $this->getDoctrine()->getManager();
  577.         $year = ($this->session->has('session_school_year') && ($this->session->get('session_school_year')!= null)) ? $this->session->get('session_school_year') : $this->scRepo->findOneBy(array("activated" => true));
  578.         // Liste des séquences de l'année scolaire en cours
  579.         $sequences $em->getRepository('AppBundle:Sequence')->findSequencesBySchoolYear($year);
  580.         // Liste des matières
  581.         $courses $em->getRepository('AppBundle:Course')->findProgrammedCoursesInClass($classroom);
  582.         // Elèves inscrits
  583.         foreach ($sequences as $seq) {
  584.             // Lecture de chaque tableau de chaque ligne
  585.             foreach ($courses as $course) {
  586.                 // Liste des évaluations
  587.                 $evaluation $em->getRepository('AppBundle:Evaluation')->findOneBy(array(
  588.                     "classRoom" => $classroom,
  589.                     "sequence" => $seq"course" => $course
  590.                 ));
  591.                 if ($evaluation != null) {
  592.                     $evaluations[$seq->getId()][$course->getId()] = 1;
  593.                 } else {
  594.                     $evaluations[$seq->getId()][$course->getId()] = 0;
  595.                 }
  596.             }
  597.         }
  598.         return $this->render('classroom/eval_repport.html.twig', array(
  599.             'evaluations' => $evaluations,
  600.             'courses' => $courses,
  601.             'room' => $classroom,
  602.             'sequences' => $sequences,
  603.         ));
  604.     }
  605.     /**
  606.      * Displays a form to edit an existing ClassRoomme entity.
  607.      *
  608.      * @Route("/{id}/edit", name="admin_classrooms_edit", requirements={"id"="\d+"}, methods={"GET","PUT"})
  609.      * @Template()
  610.      */
  611.     public function edit(Request $requestClassRoom $room): Response
  612.     {
  613.         $form $this->createForm(ClassRoomType::class, $room, [
  614.             'method' => 'PUT'
  615.                 ]);
  616.         
  617.         $form->handleRequest($request);
  618.         if ($form->isSubmitted() && $form->isValid()) {
  619.             $this->em->flush();
  620.             $this->addFlash('success''ClassRoom succesfully updated');
  621.             return $this->redirectToRoute('admin_classrooms');
  622.         }
  623.         return $this->render('classroom/edit.html.twig', [
  624.             'room' => $room,
  625.             'form' => $form->createView()
  626.         ]);
  627.     }
  628.     /**
  629.      * Deletes a ClassRoom entity.
  630.      *
  631.      * @Route("/{id}/delete", name="admin_classrooms_delete", requirements={"id"="\d+"}, methods={"DELETE"})
  632.      
  633.      */
  634.     public function delete(ClassRoom $qRequest $request): Response
  635.     {
  636.        
  637.         // if($this->isCsrfTokenValid('classrooms_deletion'.$schoolyear->getId(), $request->request->get('crsf_token') )){
  638.         $this->em->remove($q);
  639.         $this->em->flush();
  640.         $this->addFlash('info''ClassRoom succesfully deleted');
  641.         //    }
  642.         return $this->redirectToRoute('admin_classrooms');
  643.     }
  644.     /**
  645.      * Finds and displays a ClassRoom entity.
  646.      *
  647.      * @Route("/{id}/fichesimple", name="admin_classrooms_fichesimple", requirements={"id"="\d+"})
  648.      * @Method("GET")
  649.      * @Template()
  650.      */
  651.     public function fichesiplmeAction(ClassRoom $classroom)
  652.     {
  653.         // Année scolaire en cours
  654.         $year $this->schoolYearService->sessionYearById();
  655.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  656.         $html $this->renderView('classroom/templating/fiche_repport_notes.html.twig', array(
  657.             'year' => $year,
  658.             'room' => $classroom,
  659.             'students' => $studentEnrolled,
  660.         ));
  661.         return new Response(
  662.             $this->pdf->getOutputFromHtml($html),
  663.             200,
  664.             array(
  665.                 'Content-Type'          => 'application/pdf',
  666.                 'Content-Disposition'   => 'inline; filename="fiche_pv_' $classroom->getName() . '.pdf"'
  667.             )
  668.         );
  669.     }
  670.      /**
  671.      * Finds and displays a ClassRoom entity.
  672.      *
  673.      * @Route("/{id}/disciplinary_record", name="admin_classrooms_disciplinary_record", requirements={"id"="\d+"})
  674.      * @Method("GET")
  675.      * @Template()
  676.      */
  677.     public function ficheDisciplineAction(ClassRoom $classroom)
  678.     {
  679.         // Année scolaire en cours
  680.         $year $this->schoolYearService->sessionYearById();
  681.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  682.         $html $this->renderView('classroom/templating/fiche_repport_disc.html.twig', array(
  683.             'year' => $year,
  684.             'room' => $classroom,
  685.             'students' => $studentEnrolled,
  686.         ));
  687.         return new Response(
  688.             $this->pdf->getOutputFromHtml($html),
  689.             200,
  690.             array(
  691.                 'Content-Type'          => 'application/pdf',
  692.                 'Content-Disposition'   => 'inline; filename="fich_disc_' $classroom->getName() . '.pdf"'
  693.             )
  694.         );
  695.     }
  696.     /**
  697.      * LISTE DES ELEVES DE LA CLASSE DANS UNE FICHE DE PRESENTATION.
  698.      *
  699.      * @Route("/{id}/presentation", name="admin_classrooms_presentation", requirements={"id"="\d+"})
  700.      * @Method("GET")
  701.      * @Template()
  702.      */
  703.     public function presentationAction(ClassRoom $classroom)
  704.     {
  705.         // Année scolaire en cours
  706.         $year $this->schoolYearService->sessionYearById();
  707.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  708.         $html $this->renderView('classroom/templating/student_list.html.twig', array(
  709.             'year' => $year,
  710.             'room' => $classroom,
  711.             'students' => $studentEnrolled,
  712.         ));
  713.         return new Response(
  714.             $this->pdf->getOutputFromHtml($html),
  715.             200,
  716.             array(
  717.                 'Content-Type'          => 'application/pdf',
  718.                 'Content-Disposition'   => 'inline; filename="std_list_' $classroom->getName() . '.pdf"'
  719.             )
  720.         );
  721.     }
  722.     /**
  723.      * MOYENNE GENERALE DE LA CLASSE A UNE SEQUENCE
  724.      * @Route("/{id_room}/{id_seq}/sqavg", name="admin_classrooms_avg_seq", requirements={"id_room"="\d+", "id_seq"="\d+"})
  725.      * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  726.      * @ParamConverter("seq", options={"mapping": {"id_seq"   : "id"}})
  727.      * @Method("GET")
  728.      * @Template()
  729.      */
  730.     public function generalSeqAverage(ClassRoom $roomSequence $seq)
  731.     {
  732.         $dql =     "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient)  FROM App\Entity\Evaluation evaluation , App\Entity\Course  course
  733.         WHERE evaluation.course=         course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  734.         $avg_seq1 $this->em->createQuery($dql)
  735.             ->setParameter(1$room->getId())
  736.             ->setParameter(2$seq->getId())
  737.             ->getSingleScalarResult();
  738.         return round($avg_seq12);
  739.     }
  740.     /**
  741.      * MOYENNE GENERALE DE LA CLASSE A UN TRIMESTRE
  742.      * @Route("/{id_room}/{id_quat}/qtavg", name="admin_classrooms_avg_quat", requirements={"id_room"="\d+", "id_quat"="\d+"})
  743.      * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  744.      * @ParamConverter("quater", options={"mapping": {"id_quat"   : "id"}})
  745.      * @Method("GET")
  746.      * @Template()
  747.      */
  748.     public function generalQuatAverage(ClassRoom $roomQuater $quater)
  749.     {
  750.         $dql =     "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient)  FROM App\Entity\Evaluation evaluation , App\Entity\Course  course
  751.         WHERE evaluation.course=         course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  752.         $avg_seq 0;
  753.         foreach ($quater->getSequences() as $seq) {
  754.             $avg_seq += $this->em->createQuery($dql)
  755.                 ->setParameter(1$room->getId())
  756.                 ->setParameter(2$seq->getId())
  757.                 ->getSingleScalarResult();
  758.         }
  759.         return round($avg_seq 22);
  760.     }
  761.     /**
  762.      * Finds and displays a Evaluation entity.
  763.      *
  764.      * @Route("/{room}/pdf", name="admin_classrooms_blanc_ann", requirements={"room"="\d+"})
  765.      * @Method("GET")
  766.      * @Template()
  767.      * @return Response
  768.      */
  769.     public function annualSummaryAction(ClassRoom $room)
  770.     {
  771.         $year $this->schoolYearService->sessionYearById();
  772.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  773.         $html $this->renderView('classroom/templating/blankAnnualForm.html.twig', array(
  774.             'room' => $room,
  775.             'students' => $studentEnrolled,
  776.             'year' => $year,
  777.         ));
  778.         return new Response(
  779.             $this->pdf->getOutputFromHtml($html, array(
  780.                 'default-header' => false
  781.             )),
  782.             200,
  783.             array(
  784.                 'Content-Type' => 'application/pdf',
  785.                 'Content-Disposition' => 'attachment; filename="recap_empty_' $room->getName() . '.pdf"',
  786.             )
  787.         );
  788.     }
  789.     /**
  790.      * Finds and displays a ClassRoom entity.
  791.      *
  792.      * @Route("/{id}/reportCardSeq", name="admin_classrooms_reportcards_seq", requirements={"id"="\d+"})
  793.      * @Method("GET")
  794.      * @Template()
  795.      */
  796.     public function reportCardSeqAction(ClassRoom $classroom)
  797.     {
  798.         set_time_limit(600);
  799.         $totalNtCoef 0;
  800.         $totalCoef 0;
  801.         $em $this->getDoctrine()->getManager();
  802.         $year =$this->schoolYearService->sessionYearById();
  803.         $sequence $this->seqRepo->findOneBy(array("activated" => true));
  804.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  805.         // Existance des photos d'eleves
  806.         $fileExists = [];
  807.         foreach ($studentEnrolled as $std) {
  808.             $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  809.             $fileExists[$std->getId()] = file_exists($filename);
  810.         }
  811.         $evaluations $this->evalRepo->findSequantialExamsOfRoom($classroom->getId(), $sequence->getId());
  812.         foreach ($evaluations as $ev) {
  813.             $totalNtCoef += $ev->getMoyenne() * $ev->getCourse()->getCoefficient();
  814.             $totalCoef += $ev->getCourse()->getCoefficient();
  815.         }
  816.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  817.         $this->getViewSeqData($classroom$sequence0);
  818.         $connection $this->em->getConnection();
  819.         $datas $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_SEQ0  ")->fetchAll();
  820.          // For calculating ranks
  821.         $statement $connection->prepare(
  822.             "   CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  823.                 SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  824.                 FROM V_STUDENT_MARK_SEQ0 
  825.                 GROUP BY std
  826.                 ORDER BY SUM(value*weight*coef) DESC"
  827.         );
  828.         $statement->execute();
  829.         $seqAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  830.         $seqAvgArray = [];
  831.         $sumAvg 0;
  832.         $rank 0;
  833.         $rankArray = [];
  834.        
  835.         foreach ($seqAvg as $avg) {
  836.             $seqAvgArray[$avg['std']] = $avg['moyenne'];
  837.             $rankArray[$avg['std']] = ++$rank;
  838.             $sumAvg += $avg['moyenne'];
  839.         }
  840.         // CAS DES ABSCENCES SEQUENTIELLES
  841.         $statement $connection->prepare(
  842.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ AS
  843.             SELECT DISTINCT   seq.std as std , seq.total_hours  as abscences
  844.             FROM V_STUDENT_ABSCENCE_SEQ0 seq
  845.             ORDER BY std "
  846.         );
  847.         $statement->execute();
  848.          // Traitement des abscences
  849.          $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_SEQ ")->fetchAll();
  850.          $absencesArray = [];
  851.          foreach ($absences as $abs) {
  852.              $absencesArray[$abs['std']] = $abs['abscences'];
  853.          }
  854.         $html $this->renderView('classroom/reportcard/sequential.html.twig', array(
  855.             'year' => $year,
  856.             'datas' => $datas,
  857.             'students' => $studentEnrolled,
  858.             'sequence' => $sequence,
  859.             'quater' => $sequence->getQuater(),
  860.             'room' => $classroom,
  861.             'students' => $studentEnrolled,
  862.             
  863.             'means' => $seqAvgArray,
  864.             'abscences' => $absencesArray,
  865.             'genMean' => $sumAvg sizeof($seqAvgArray),
  866.             'ranks' => $rankArray,
  867.             'fileExists'=> $fileExists
  868.         ));
  869.         return new Response(
  870.             $this->pdf->getOutputFromHtml($html),
  871.             200,
  872.             array(
  873.                 'Content-Type'          => 'application/pdf',
  874.                 'Content-Disposition'   => 'inline; filename="bull_seq_' $classroom->getName() . '.pdf"'
  875.             )
  876.         );
  877.         
  878.     }
  879.     public function buildAbsViewSeq(ClassRoom $room,Sequence $seq){
  880.         $connection $this->em->getConnection();
  881.         $statement $connection->prepare(
  882.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" $seq->getId() ."_".$room->getId()." AS
  883.             SELECT DISTINCT  abs.student_id as std, sum( abs.weight) as total_hours
  884.             FROM   class_room room  
  885.             LEFT JOIN  abscence_sheet   sheet     ON  sheet.class_room_id = room.id AND sheet.sequence_id = ?
  886.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  887.             WHERE  room.id = ? 
  888.             GROUP BY  std
  889.             ORDER BY  std; "
  890.         );
  891.         $statement->bindValue(1$seq->getId());
  892.         $statement->bindValue(2$room->getId());
  893.         $statement->execute();
  894.        
  895.     }
  896.     public function getAbsSeqFromView(ClassRoom $room,Sequence $seq){
  897.         $connection $this->em->getConnection();
  898.        
  899.         return $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_SEQ".$seq->getId()."_".$room->getId()."  ")->fetchAllAssociative();
  900.     }
  901.     public function getAbsQuater(ClassRoom $room,Quater $quater){
  902.          
  903.          $sequences $this->seqRepo->findBy(array("quater" => $quater));
  904.          foreach ($sequences as $seq) {
  905.              $this->buildAbsViewSeq($room$seq);
  906.          }
  907.          $absSeq1 $this->getAbsSeqFromView($room$sequences[0]);
  908.          $absSeq2 $this->getAbsSeqFromView($room$sequences[1]);
  909.          $absQuater =[];
  910.          $year $this->schoolYearService->sessionYearById();
  911.          $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  912.          foreach($studentEnrolled as $std){
  913.             foreach($absSeq1 as $abs){
  914.                 if($abs["std"]==$std->getId()){
  915.                    // $absQuater[$std->getId()] = $abs["total_hours"];
  916.                 }
  917.             }
  918.             foreach($absSeq2 as $abs){
  919.                 if($abs["std"]==$std->getId()){
  920.                     $absQuater[$std->getId()] = isset($absQuater[$std->getId()]) ? $absQuater[$std->getId()] + $abs["total_hours"] : $abs["total_hours"];;
  921.                 }
  922.             }
  923.          }
  924.          return $absQuater;
  925.     }
  926.     public function getViewSeqData(ClassRoom $room,Sequence $seqint $i){
  927.         $connection $this->em->getConnection();
  928.         $year $this->schoolYearService->sessionYearById();
  929.          // CAS DES NOTES SEQUENTIELLES
  930.         $statement $connection->prepare(
  931.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  932.             SELECT DISTINCT  eval.id as eval,crs.id as crs, crs.coefficient as coef, room.id as room, std.id as std,  teach.full_name as teacher    , modu.id as module,m.value as value, m.weight as weight
  933.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  934.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  935.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  936.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  937.             JOIN  attribution att    ON  att.course_id      =   crs.id  and att.year_id = ?
  938.             JOIN  user  teach        ON  att.teacher_id  =   teach.id
  939.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  940.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  941.             LEFT JOIN  abscence_sheet   sheet     ON  seq.id     =   sheet.sequence_id AND sheet.class_room_id = room.id
  942.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  943.             JOIN  quater   quat      ON  seq.quater_id     =   quat.id
  944.             WHERE    room.id = ? AND eval.sequence_id =? 
  945.             ORDER BY room.id,modu.id ,  std; "
  946.         );
  947.         $statement->bindValue(1$year->getId());
  948.         $statement->bindValue(2$room->getId());
  949.         $statement->bindValue(3$seq->getId());
  950.         $statement->execute();
  951.         $statement $connection->prepare(
  952.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" $i " AS
  953.             SELECT DISTINCT  room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  954.             FROM   class_room room  
  955.             LEFT JOIN  abscence_sheet   sheet     ON  sheet.class_room_id = room.id AND sheet.sequence_id = ?
  956.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  957.             WHERE  room.id = ? 
  958.             GROUP BY  std
  959.             ORDER BY room.id, std; "
  960.         );
  961.         $statement->bindValue(1$seq->getId());
  962.         $statement->bindValue(2$room->getId());
  963.         $statement->execute();
  964.        
  965.     }
  966.     public function getViewSeqData2024(ClassRoom $room,Sequence $seq){
  967.         $connection $this->em->getConnection();
  968.         $year $this->schoolYearService->sessionYearById();
  969.          // CAS DES NOTES SEQUENTIELLES
  970.         $statement $connection->prepare(
  971.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ".$room->getId()."_".$seq->getId(). " AS
  972.             SELECT DISTINCT  crs.id as crs, crs.coefficient as coef, std.id as std,m.value as value, m.weight as weight
  973.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  974.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  975.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  976.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  977.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  978.             WHERE    room.id = ? AND eval.sequence_id =? 
  979.             ORDER BY  std, crs; "
  980.         );
  981.         $statement->bindValue(1$room->getId());
  982.         $statement->bindValue(2$seq->getId());
  983.         $statement->execute();
  984.     }
  985.     public function getViewQuaterData(ClassRoom $roomint $i){
  986.         $connection $this->em->getConnection();
  987.         $year $this->schoolYearService->sessionYearById();
  988.          // CAS DES NOTES SEQUENTIELLES
  989.         $statement $connection->prepare(
  990.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_ROOM" $room->getId() . " AS
  991.             SELECT DISTINCT  eval.id as eval,crs.id as crs, crs.coefficient as coef, room.id as room, std.id as std,  teach.full_name as teacher    , modu.id as module,m.value as value, m.weight as weight
  992.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  993.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  994.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  995.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  996.             JOIN  attribution att    ON  att.course_id      =   crs.id  and att.year_id = ?
  997.             JOIN  user  teach        ON  att.teacher_id  =   teach.id
  998.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  999.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  1000.             LEFT JOIN  abscence_sheet   sheet     ON  seq.id     =   sheet.sequence_id AND sheet.class_room_id = room.id
  1001.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  1002.             JOIN  quater   quat      ON  seq.quater_id     =   quat.id AND  quat.id = ?
  1003.             WHERE    room.id = ?  
  1004.             ORDER BY  std.id,modu.id , crs.id,seq.id ; "
  1005.         );
  1006.         $statement->bindValue(1$year->getId());
  1007.         $statement->bindValue(2$seq->getQuater()->getId());
  1008.         $statement->bindValue(3$room->getId());
  1009.         $statement->execute();
  1010.         $statement $connection->prepare(
  1011.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" $i " AS
  1012.             SELECT DISTINCT  room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  1013.             FROM   class_room room  
  1014.             LEFT JOIN  abscence_sheet   sheet     ON  sheet.class_room_id = room.id AND sheet.sequence_id = ?
  1015.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  1016.             WHERE  room.id = ? 
  1017.             GROUP BY  std
  1018.             ORDER BY room.id, std; "
  1019.         );
  1020.         $statement->bindValue(1$seq->getId());
  1021.         $statement->bindValue(2$room->getId());
  1022.         $statement->execute();
  1023.        
  1024.     }
  1025.     /**
  1026.      * Finds and displays a ClassRoom entity.
  1027.      *
  1028.      * @Route("/{id}/reportCardsTrim", name="admin_classrooms_reportcards_trim", requirements={"id"="\d+"})
  1029.      * @Method("GET")
  1030.      * @Template()
  1031.      */
  1032.     public function reportCardsTrimAction(ClassRoom $roomRequest $request)
  1033.     {
  1034.         $connection $this->em->getConnection();
  1035.         $year $this->schoolYearService->sessionYearById();
  1036.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1037.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  1038.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  1039.          // Existance des photos d'eleves
  1040.          $fileExists = [];
  1041.          foreach ($studentEnrolled as $std) {
  1042.              $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  1043.              $fileExists[$std->getId()] = file_exists($filename);
  1044.          }
  1045.         
  1046.         /*******************************************************************************************************************/
  1047.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1048.         /*******************************************************************************************************************/
  1049.         $i 1;
  1050.         foreach ($sequences as $seq) {
  1051.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1052.             $this->getViewSeqData($room$seq$i);
  1053.             $i++;
  1054.         }
  1055.         // CAS DES NOTES TRIMESTRIELLES
  1056.         $statement $connection->prepare(
  1057.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1058.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   module, seq1.room as room
  1059.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1060.             JOIN  V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1061.             ORDER BY std , module"
  1062.         );
  1063.         $statement->execute();
  1064.         // CAS DES ABSCENCES TRIMESTRIELLES
  1065.         $statement $connection->prepare(
  1066.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER AS
  1067.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1068.             FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1069.              JOIN  V_STUDENT_ABSCENCE_SEQ2 seq2  ON  (seq1.std    =   seq2.std  )
  1070.             ORDER BY std "
  1071.         );
  1072.         $statement->execute();
  1073.         $dataQuater $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_QUATER marks  ")->fetchAll();
  1074.         // For calculating ranks
  1075.         $statement $connection->prepare(
  1076.         "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1077.         SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1078.         FROM V_STUDENT_MARK_QUATER 
  1079.         GROUP BY std
  1080.         ORDER BY SUM(value*weight*coef) DESC"
  1081.         );
  1082.         $statement->execute();
  1083.         $quaterAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1084.         $quaterAvgArray = [];
  1085.         $sumAvg 0;
  1086.         $rank 0;
  1087.         $rankArray = [];
  1088.        
  1089.         foreach ($quaterAvg as $avg) {
  1090.             $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1091.             $rankArray[$avg['std']] = ++$rank;
  1092.             $sumAvg += $avg['moyenne'];
  1093.         }
  1094.         
  1095.         // Traitement des abscences
  1096.         $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_QUATER ")->fetchAll();
  1097.         $absencesArray = [];
  1098.         foreach ($absences as $abs) {
  1099.             $absencesArray[$abs['std']] = $abs['abscences'];
  1100.         }
  1101.         $this->pdf->setTimeout(600);
  1102.         $html $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1103.             'year' => $year,
  1104.             'data' => $dataQuater,
  1105.             'ranks' => $rankArray,
  1106.             'means' => $quaterAvgArray,
  1107.             'abscences' => $absencesArray,
  1108.             'genMean' => $sumAvg sizeof($quaterAvgArray),
  1109.             'room' => $room,
  1110.             'quater' => $quater,
  1111.             'sequences' => $sequences,
  1112.             'students' => $studentEnrolled,
  1113.             'fileExists'=> $fileExists
  1114.         ));
  1115.         return new Response(
  1116.             $this->pdf->getOutputFromHtml($html),
  1117.             200,
  1118.             array(
  1119.                 'Content-Type'          => 'application/pdf',
  1120.                 'Content-Disposition'   => 'inline; filename="' $room->getName() . '.pdf"'
  1121.             )
  1122.         );
  1123.         // return new Response($html);
  1124.     }
  1125.      /**
  1126.      * Finds and displays a ClassRoom entity.
  1127.      *
  1128.      * @Route("/{id}/reportCardsTrim2024", name="admin_classrooms_reportcards_trim_2024", requirements={"id"="\d+"})
  1129.      * @Method("GET")
  1130.      * @Template()
  1131.      */
  1132.     public function reportCardsTrim2024Action(ClassRoom $roomRequest $request)
  1133.     {
  1134.         if (!$this->getUser()) {
  1135.             $this->addFlash('warning''You need login first!');
  1136.             return $this->redirectToRoute('app_login');
  1137.         }
  1138.         if (!$this->getUser()->isVerified()) {
  1139.             $this->addFlash('warning''You need to have a verified account!');
  1140.             return $this->redirectToRoute('app_login');
  1141.         }
  1142.         $headerFontSize $request->request->get('header_font_size');
  1143.         $lineHeight $request->request->get('line_height');
  1144.         $copyright =  $request->request->get('copyright')=="on";
  1145.         $reverse =  $request->request->get('reverse')=="on";
  1146.         $connection $this->em->getConnection();
  1147.         $year $this->schoolYearService->sessionYearById();
  1148.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1149.         $students $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  1150.         $mainTeacher $this->mainTeacherRepo->findOneBy(array("classRoom" => $room"schoolYear" => $year))-> getTeacher();
  1151.         // Existance des photos d'eleves
  1152.         $fileExists = [];
  1153.         foreach ($students as $std) {
  1154.             $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  1155.             $fileExists[$std->getId()] = file_exists($filename);
  1156.         }
  1157.         // Retrieve of marks
  1158.         $query =  "  SELECT DISTINCT student.id as student_id, student.firstname as student_firstname, student.lastname as student_last_name, student.birthday as student_birthday, student.matricule as matricule,  sequence.id as sequence, course.id as course_id ,course.wording , course.coefficient, mark.value, mark.weight, mark.rank2, evaluation.mini as mini, evaluation.maxi as maxi, evaluation.competence, attribution.teacher_id, school_year.id, user.full_name
  1159.         FROM sequence 
  1160.         JOIN evaluation ON evaluation.sequence_id = sequence.id AND evaluation.class_room_id = :room_id
  1161.         JOIN course ON evaluation.course_id = course.id
  1162.         JOIN attribution on attribution.course_id = course.id
  1163.         JOIN user ON user.id = attribution.teacher_id
  1164.         JOIN mark ON evaluation.id = mark.evaluation_id
  1165.         JOIN student ON mark.student_id = student.id
  1166.         JOIN quater ON sequence.quater_id = quater.id
  1167.         JOIN school_year on quater.school_year_id= school_year.id and school_year.id = attribution.year_id
  1168.         WHERE quater.id = :quater_id 
  1169.         ORDER BY student_id, course.id,sequence.id; ";
  1170.         $params = [
  1171.             'quater_id' => $quater->getId(),       
  1172.             'room_id' => $room->getId(), // Remplace :room_id
  1173.             
  1174.         ];
  1175.         $result $connection->executeQuery($query$params);
  1176.         $dataMarks $result->fetchAllAssociative();
  1177.         $dataAbs $this->getAbsQuater($room$quater);
  1178.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  1179.         // Calculation of rank and general average
  1180.         foreach ($sequences as $seq) {
  1181.             $this->getViewSeqData2024($room,$seq);
  1182.         }
  1183.         // CAS DES NOTES TRIMESTRIELLES
  1184.         $query =
  1185.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1186.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight 
  1187.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1188.             JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1189.             ORDER BY std ";
  1190.         $connection->executeQuery($query);
  1191.         $statement $connection->prepare(
  1192.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1193.             SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1194.             FROM V_STUDENT_MARK_QUATER 
  1195.             GROUP BY std
  1196.             ORDER BY SUM(value*weight*coef) DESC"
  1197.             );
  1198.             $statement->execute();
  1199.             $quaterAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1200.             $quaterAvgArray = [];
  1201.             $sumAvg 0;
  1202.             $rank 0;
  1203.             $minAgv 20;
  1204.             $maxAvg 0;
  1205.             $rankArray = [];
  1206.            
  1207.             foreach ($quaterAvg as $avg) {
  1208.                 $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1209.                 $rankArray[$avg['std']] = ++$rank;
  1210.                 $sumAvg += $avg['moyenne'];
  1211.                 if($minAgv $avg['moyenne']){
  1212.                     $minAgv $avg['moyenne'];
  1213.                 }
  1214.                 if($maxAvg $avg['moyenne']){
  1215.                     $maxAvg $avg['moyenne'];
  1216.                 }
  1217.             }
  1218.        
  1219.         $html $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1220.             'genMean' => $sumAvg sizeof($quaterAvgArray),
  1221.             'ranks' => $rankArray,
  1222.             'year' => $year,
  1223.             'minAvg' => $minAgv,
  1224.             'maxAvg' => $maxAvg,
  1225.             'quater' => $quater,
  1226.             'mainTeacher'=>$mainTeacher,
  1227.             'dataMarks' => $dataMarks,
  1228.             'dataAbs' => $dataAbs,
  1229.             'std'  => $std,
  1230.             'students' => $students,
  1231.             'room' => $room,
  1232.             'fileExists' => $fileExists,
  1233.             "headerFontSize" => 0.75*$headerFontSize,
  1234.             "lineHeight" => 1.5*$lineHeight,
  1235.             "copyright" => $copyright,
  1236.             "reverse" => $reverse
  1237.         ));
  1238.         return new Response(
  1239.             $this->pdf->getOutputFromHtml($html),
  1240.             200,
  1241.             array(
  1242.                 'Content-Type'          => 'application/pdf',
  1243.                 'Content-Disposition'   => 'inline; filename="bull_' .  $quater->getId().'_'.$std->getMatricule()  . '.pdf"'
  1244.             )
  1245.         );
  1246.     }
  1247.       
  1248.    
  1249.     /**
  1250.      * Finds and displays a ClassRoom entity.
  1251.      *
  1252.      * @Route("/{id}/annualavglist", name="admin_avg_list", requirements={"id"="\d+"})
  1253.      * @Method("GET")
  1254.      * @Template()
  1255.      */
  1256.     public function annualAvgList(ClassRoom $classroomRequest $request)
  1257.     {
  1258.         $connection $this->em->getConnection();
  1259.         $year $this->schoolYearService->sessionYearById();
  1260.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1261.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  1262.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  1263.          /*******************************************************************************************************************/
  1264.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1265.         /*******************************************************************************************************************/
  1266.         $i 1;
  1267.         foreach ($sequences as $seq) {
  1268.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1269.             $this->getViewSeqData($classroom$seq$i);
  1270.             $i++;
  1271.         }
  1272.          // CAS DES NOTES TRIMESTRIELLES1
  1273.          $statement $connection->prepare(
  1274.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1275.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1276.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1277.             JOIN  V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1278.             ORDER BY std , modu"
  1279.         );
  1280.         $statement->execute();
  1281.        
  1282.          // CAS DES NOTES TRIMESTRIELLES2
  1283.          $statement $connection->prepare(
  1284.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1285.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1286.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[2]->getId()." seq1
  1287.             JOIN  V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[3]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1288.             ORDER BY std , modu"
  1289.         );
  1290.         $statement->execute();
  1291.           // CAS DES NOTES TRIMESTRIELLES3
  1292.           $statement $connection->prepare(
  1293.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1294.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1295.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[4]->getId()." seq1
  1296.             JOIN  V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[5]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1297.             ORDER BY std , modu"
  1298.         );
  1299.         $statement->execute();
  1300.         $statement $connection->prepare(
  1301.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1302.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule 
  1303.             student.lastname as lastname, student.firstname as firstname
  1304.             course.wording as course, course.coefficient as coef, 
  1305.             module.name as module,
  1306.             user.full_name as teacher,
  1307.             quat1.std, quat1.modu,
  1308.             quat1.value as value1,  quat1.weight as weight1,
  1309.             quat2.value as value2,  quat2.weight as weight2,
  1310.             quat3.value as value3,  quat3.weight as weight3,
  1311.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1312.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1313.             FROM student  
  1314.             JOIN   V_STUDENT_MARK_QUATER_1      quat1   ON  student.id = quat1.std 
  1315.             JOIN   V_STUDENT_MARK_QUATER_2      quat2  ON  student.id = quat2.std AND quat1.crs = quat2.crs
  1316.             JOIN   V_STUDENT_MARK_QUATER_3      quat3   ON  student.id = quat3.std AND quat2.crs = quat3.crs
  1317.             JOIN  class_room ON class_room.id = quat1.room
  1318.             JOIN  course     ON course.id = quat1.crs
  1319.             JOIN  module     ON course.module_id = quat1.modu
  1320.             JOIN  user       ON user.full_name = quat1.teacher
  1321.             ORDER BY  quat1.std, quat1.modu
  1322.             "
  1323.         );
  1324.         $statement->execute();
  1325.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  1326.         // For calculating ranks
  1327.         $statement $connection->prepare(
  1328.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1329.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1330.             FROM ANNUAL_DATA 
  1331.             GROUP BY idStd
  1332.             ORDER BY SUM(value*weight*coef) DESC"
  1333.         );
  1334.         $statement->execute();
  1335.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1336.         $annualAvgArray = [];
  1337.         $sumAvg 0;
  1338.         $rank 0;
  1339.         $rankArray = [];
  1340.         foreach ($annualAvg as $avg) {
  1341.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1342.             $rankArray[$avg['idStd']] = ++$rank;
  1343.             $sumAvg += $avg['moyenne'];
  1344.         }
  1345.         $html $this->renderView('classroom/avglist.html.twig', array(
  1346.            
  1347.             'year' => $year,
  1348.             'room' => $classroom,
  1349.             'students' => $studentEnrolled,
  1350.             'ranks' => $rankArray,
  1351.             'means' => $annualAvgArray,
  1352.             'genMean' => $sumAvg sizeof($annualAvgArray),
  1353.         ));
  1354.         return new Response(
  1355.             $this->snappy->getOutputFromHtml($html,  [
  1356.                 'page-size' => 'A4',
  1357.                
  1358.             ]),
  1359.             200,
  1360.             array(
  1361.                 'Content-Type' => 'application/pdf',
  1362.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  1363.             )
  1364.         );
  1365.     }
  1366.     /**
  1367.      * Finds and displays a ClassRoom entity.
  1368.      *
  1369.      * @Route("/{id}/reportCards3ApcYearApc", name="admin_class_reportcards_3_apc_year", requirements={"id"="\d+"})
  1370.      * @Method("GET")
  1371.      * @Template()
  1372.      */
  1373.     public function reportCards3YearAction(ClassRoom $classroomRequest $request)
  1374.     {
  1375.         $headerFontSize $request->request->get('header_font_size');
  1376.         $lineHeight $request->request->get('line_height');
  1377.         $copyright =  $request->request->get('copyright')=="on";
  1378.         $reverse =  $request->request->get('reverse')=="on";
  1379.         
  1380.         $connection $this->em->getConnection();
  1381.         $year $this->schoolYearService->sessionYearById();
  1382.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1383.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  1384.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  1385.          // Existance des photos d'eleves
  1386.          $fileExists = [];
  1387.          foreach ($studentEnrolled as $std) {
  1388.              $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  1389.              $fileExists[$std->getId()] = file_exists($filename);
  1390.          }
  1391.         /*******************************************************************************************************************/
  1392.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1393.         /*******************************************************************************************************************/
  1394.         $i 1;
  1395.         foreach ($sequences as $seq) {
  1396.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1397.             $this->getViewSeqData($classroom$seq$i);
  1398.             $i++;
  1399.         }
  1400.         // CAS DES NOTES TRIMESTRIELLES1
  1401.         $statement $connection->prepare(
  1402.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1403.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1404.             FROM V_STUDENT_MARK_SEQ1 seq1
  1405.             JOIN  V_STUDENT_MARK_SEQ2 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1406.             ORDER BY std , modu"
  1407.         );
  1408.         $statement->execute();
  1409.         // CAS DES ABSCENCES TRIMESTRIELLES1
  1410.         $statement $connection->prepare(
  1411.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_1 AS
  1412.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1413.             FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1414.              JOIN  V_STUDENT_ABSCENCE_SEQ2 seq2  ON  (seq1.std    =   seq2.std  )
  1415.             ORDER BY std "
  1416.         );
  1417.         $statement->execute();
  1418.          // CAS DES NOTES TRIMESTRIELLES2
  1419.          $statement $connection->prepare(
  1420.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1421.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1422.             FROM V_STUDENT_MARK_SEQ3 seq1
  1423.             JOIN  V_STUDENT_MARK_SEQ4 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1424.             ORDER BY std , modu"
  1425.         );
  1426.         $statement->execute();
  1427.         // CAS DES ABSCENCES TRIMESTRIELLES2
  1428.         $statement $connection->prepare(
  1429.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_2 AS
  1430.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1431.             FROM V_STUDENT_ABSCENCE_SEQ3 seq1
  1432.              JOIN  V_STUDENT_ABSCENCE_SEQ4 seq2  ON  (seq1.std    =   seq2.std  )
  1433.             ORDER BY std "
  1434.         );
  1435.         $statement->execute();
  1436.          // CAS DES NOTES TRIMESTRIELLES3
  1437.          $statement $connection->prepare(
  1438.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1439.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight ,  seq1.teacher as teacher, seq1.module as   modu, seq1.room as room
  1440.             FROM V_STUDENT_MARK_SEQ5 seq1
  1441.             JOIN  V_STUDENT_MARK_SEQ6 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1442.             ORDER BY std , modu"
  1443.         );
  1444.         $statement->execute();
  1445.         // CAS DES ABSCENCES TRIMESTRIELLES3
  1446.         $statement $connection->prepare(
  1447.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_3 AS
  1448.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1449.             FROM V_STUDENT_ABSCENCE_SEQ5 seq1
  1450.              JOIN  V_STUDENT_ABSCENCE_SEQ6 seq2  ON  (seq1.std    =   seq2.std  )
  1451.             ORDER BY std "
  1452.         );
  1453.         $statement->execute();
  1454.         set_time_limit(600);
  1455.         $statement $connection->prepare(
  1456.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1457.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule ,  student.image_name as profileImagePath, 
  1458.             student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  1459.             student.gender as gender,student.birthplace as birthplace , 
  1460.             class_room.name as room_name,
  1461.             course.wording as course, course.coefficient as coef, 
  1462.             module.name as module,
  1463.             user.full_name as teacher,
  1464.             quat1.std, quat1.modu,
  1465.             quat1.value as value1,  quat1.weight as weight1,
  1466.             quat2.value as value2,  quat2.weight as weight2,
  1467.             quat3.value as value3,  quat3.weight as weight3,
  1468.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1469.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1470.             FROM student  
  1471.             JOIN   V_STUDENT_MARK_QUATER_1      quat1   ON  student.id = quat1.std 
  1472.             JOIN   V_STUDENT_MARK_QUATER_2      quat2  ON  student.id = quat2.std AND quat1.crs = quat2.crs
  1473.             JOIN   V_STUDENT_MARK_QUATER_3      quat3   ON  student.id = quat3.std AND quat2.crs = quat3.crs
  1474.             JOIN  class_room ON class_room.id = quat1.room
  1475.             JOIN  course     ON course.id = quat1.crs
  1476.             JOIN  module     ON course.module_id = quat1.modu
  1477.             JOIN  user       ON user.full_name = quat1.teacher
  1478.             ORDER BY  quat1.std, quat1.modu
  1479.             "
  1480.         );
  1481.         $statement->execute();
  1482.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  1483.         // For calculating ranks
  1484.         $statement $connection->prepare(
  1485.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1486.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1487.             FROM ANNUAL_DATA 
  1488.             GROUP BY idStd
  1489.             ORDER BY SUM(value*weight*coef) DESC"
  1490.         );
  1491.         $statement->execute();
  1492.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1493.         $annualAvgArray = [];
  1494.         $sumAvg 0;
  1495.         $rank 0;
  1496.         $rankArray = [];
  1497.         foreach ($annualAvg as $avg) {
  1498.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1499.             $rankArray[$avg['idStd']] = ++$rank;
  1500.             $sumAvg += $avg['moyenne'];
  1501.         }
  1502.          // CAS DES ABSCENCES ANNUELLES
  1503.          $statement $connection->prepare(
  1504.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_ANNUAL AS
  1505.             SELECT DISTINCT   q1.std as std , q1.abscences + q2.abscences + q3.abscences as abscences
  1506.              FROM  V_STUDENT_ABSCENCE_QUATER_1 q1
  1507.              JOIN  V_STUDENT_ABSCENCE_QUATER_2 q2  ON  (q1.std    =   q2.std  )
  1508.              JOIN  V_STUDENT_ABSCENCE_QUATER_3 q3  ON  (q1.std    =   q3.std  )
  1509.             ORDER BY std "
  1510.         );
  1511.         $statement->execute();
  1512.          // Traitement des abscences
  1513.          $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_ANNUAL ")->fetchAll();
  1514.          $absencesArray = [];
  1515.          foreach ($absences as $abs) {
  1516.              $absencesArray[$abs['std']] = $abs['abscences'];
  1517.          }
  1518.         $html $this->renderView('classroom/reportcard/annual.html.twig', array(
  1519.             "headerFontSize" => $headerFontSize,
  1520.             "lineHeight" => $lineHeight,
  1521.             "copyright" => $copyright,
  1522.             "reverse" => $reverse,
  1523.             'year' => $year,
  1524.             'data' => $dataYear,
  1525.             'room' => $classroom,
  1526.             'students' => $studentEnrolled,
  1527.             'abscences' => $absencesArray,
  1528.             'ranks' => $rankArray,
  1529.             'means' => $annualAvgArray,
  1530.             'genMean' => $sumAvg sizeof($annualAvgArray),
  1531.             'fileExists'=> $fileExists
  1532.         ));
  1533.         return new Response(
  1534.             $this->snappy->getOutputFromHtml($html,  [
  1535.                 'page-size' => 'A4',
  1536.                
  1537.             ]),
  1538.             200,
  1539.             array(
  1540.                 'Content-Type' => 'application/pdf',
  1541.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  1542.             )
  1543.         );
  1544.     }
  1545.     public function getStudentQuaterMark(Array  $std,Course $crs){
  1546.         foreach ($this->quaterData as $data) {
  1547.             if($std["id"] == $data["std"] && $crs->getId() == $data["crs"] ){
  1548.                 return ["seq1"=>$data["value1"], "weight1"=>$data["weight1"], "seq2"=>$data["value2"],"weight2"=>$data["weight2"],"coef"=>$data["coef"] ];
  1549.             }
  1550.         }
  1551.         return null;
  1552.     }
  1553.     public function getViewQuaterData2024(ClassRoom $room,Quater $quater){
  1554.         $em $this->getDoctrine()->getManager();
  1555.         $year $this->schoolYearService->sessionYearById();
  1556.         $connection $this->em->getConnection();
  1557.         $sequences $this->seqRepo->findBy(array("quater" => $quater));        
  1558.         foreach ($sequences as $seq) {
  1559.             $this->getViewSeqData2024($room,$seq );
  1560.         }
  1561.         $query =
  1562.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1563.             SELECT DISTINCT   seq1.std as std , seq1.crs as crs , seq1.coef as coef,  seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2,    (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight)  as value, greatest(seq1.weight , seq2.weight ) as weight 
  1564.             FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1565.             JOIN  V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1566.             ORDER BY std ";
  1567.         $connection->executeQuery($query);
  1568.         $query "SELECT * FROM V_STUDENT_MARK_QUATER";
  1569.         $this->quaterData $connection->fetchAllAssociative($query);
  1570.     }
  1571.     /**
  1572.      * Finds and displays a ClassRoom entity.
  1573.      *
  1574.      * @Route("/{id}/recapitulatiftrim", name="admin_classrooms_recapitulatif_trim", requirements={"id"="\d+"})
  1575.      * @Method("GET")
  1576.      * @Template()
  1577.      */
  1578.     public function recapTrimAction(ClassRoom $roomRequest $request)
  1579.     {
  1580.         $checkedValues $request->request->get('selected_courses');
  1581.         set_time_limit(600);
  1582.         $em $this->getDoctrine()->getManager();
  1583.         $year $this->schoolYearService->sessionYearById();
  1584.         $connection $this->em->getConnection();
  1585.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1586.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYear($room$year->getId());
  1587.         $this->getViewQuaterData2024($room$quater);
  1588.         $result = [];
  1589.         foreach ($studentEnrolled as $std) {  // Parcourir les étudiants inscrits
  1590.             $result[$std["id"]] = [];      // Initialiser un sous-tableau pour chaque étudiant
  1591.             foreach ($room->getModules() as $module) {      // Parcourir les modules de la salle
  1592.                 foreach ($module->getCourses() as $crs) {
  1593.                     if(in_array($crs->getId(), $checkedValues))
  1594.                     {
  1595.                          // Collecter les note de chaque combinaison étudiant/module
  1596.                         $result[$std["id"]][$crs->getId()] = $this->getStudentQuaterMark($std$crs); // Remplacer 'null' par la donnée que vous voulez associer
  1597.              
  1598.                     }
  1599.                 }
  1600.             }
  1601.         }
  1602.         
  1603.         $mainTeacher $this->mainTeacherRepo->findOneBy(array("classRoom" => $room"schoolYear" => $year))-> getTeacher();
  1604.         $options = [
  1605.             'orientation' => 'Landscape',  // Spécifie l'orientation paysage
  1606.             'page-size' => 'A4',           // Taille de page A4
  1607.             'margin-top' => '10mm',         // Marges pour personnaliser l'apparence
  1608.             'margin-bottom' => '10mm',
  1609.             'margin-left' => '10mm',
  1610.             'margin-right' => '10mm'
  1611.         ];
  1612.         $html $this->renderView('classroom/recapitulatiftrimWithMoy.html.twig', array(
  1613.             'year' => $year,
  1614.             'datas' => $result,
  1615.             'room' => $room,
  1616.             'quater' => $quater
  1617.             'checkedValues'=>$checkedValues,
  1618.             'students' => $studentEnrolled,
  1619.             'mainTeacher' => $mainTeacher
  1620.         ));
  1621.         return new Response(
  1622.             $this->pdf->getOutputFromHtml($html,  $options),
  1623.             200,
  1624.             array(
  1625.                 'Content-Type'          => 'application/pdf',
  1626.                 'Content-Disposition'   => 'inline; filename="recap_trim' .  $quater->getId().'_'.$room->getName()  . '.pdf"'
  1627.             )
  1628.         );
  1629.         
  1630.         
  1631.     }
  1632.     public function officialExam()
  1633.     {
  1634.         // Retrieve student categories from the corresponding repository
  1635.         $categoriesStudent $this->getDoctrine()->getRepository(CategStudent::class)->findAll();
  1636.         // Initialize arrays for student categories, mentions, and counters
  1637.         $studentCategories = [];
  1638.         $mentionCategories = [];
  1639.         $studentCountCategories = [];
  1640.         $mentionCountCategories = [];
  1641.         // Fill the arrays with data from student categories
  1642.         foreach ($categoriesStudent as $category) {
  1643.             $studentCategories[] = $category->getName();
  1644.             $mentionCategories[] = $category->getMention();
  1645.             $studentCountCategories[] = $category->getCountStudent();
  1646.             $mentionCountCategories[] = $category->getCountMention();
  1647.         }
  1648.         // Render the Twig template and pass the data in JSON format
  1649.         return $this->render('admin/class_room/show.html.twig', [
  1650.             'studentCategories' => json_encode($studentCategories),
  1651.             'mentionCategories' => json_encode($mentionCategories),
  1652.             'studentCountCategories' => json_encode($studentCountCategories),
  1653.             'mentionCountCategories' => json_encode($mentionCountCategories),
  1654.         ]);
  1655.     }
  1656.         /**
  1657.      * @Route("/classroom/insolvents", name="admin_classroom_insolvents")
  1658.      */
  1659.     public function listInsolventStudents(): Response
  1660.     {
  1661.         $year $this->schoolYearService->sessionYearById();
  1662.         $paymentPlan =  $year->getPaymentPlan();
  1663.         // List of student subscriptions for the class
  1664.         $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year), array("classRoom"=>"ASC"));
  1665.         $insolventSub = [];
  1666.      
  1667.         foreach($subscriptions as $sub){
  1668.             if($year->paymentThresholdAmount($sub->getClassRoom()) > $sub->getStudent()->getPaymentsSum($year) ){
  1669.                 $insolventSub[]  = $sub;
  1670.             }
  1671.         }
  1672.          $html $this->render('school_year/templating/insolvent_students_list.html.twig', [
  1673.             
  1674.             'students' => $insolventSub,
  1675.             'year' => $year,
  1676.         ]);
  1677.         return new Response(
  1678.             $this->pdf->getOutputFromHtml($html),
  1679.             200,
  1680.             array(
  1681.                 'Content-Type'          => 'application/pdf',
  1682.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $year->getCode() . '.pdf"'
  1683.             )
  1684.         );
  1685.     }
  1686.     /**
  1687.      * @Route("/classroom/{id}", name="class_room_stats")
  1688.      */
  1689.     public function showClassRoomStats(ClassRoomRepository $classRoomRepositoryClassRoom $room): Response
  1690.     {
  1691.         $classRoom $classRoomRepository->find($id);
  1692.         $successfulCount $classRoomRepository->countSuccessfulStudentsForClass($classRoom);
  1693.         $unsuccessfulCount $classRoomRepository->countUnsuccessfulStudentsForClass($classRoom);
  1694.         $mentionStatistics $classRoomRepository->getMentionStatisticsForClass($classRoom);
  1695.         return $this->render('class_room/stats.html.twig', [
  1696.             'classRoom' => $classRoom,
  1697.             'successfulCount' => $successfulCount,
  1698.             'unsuccessfulCount' => $unsuccessfulCount,
  1699.             'mentionStatistics' => $mentionStatistics,
  1700.         ]);
  1701.     }
  1702.       /**
  1703.      * @Route("/classroom/{id}/insolvent", name="admin_classroom_insolvent")
  1704.      */
  1705.     public function listInsolventStudentsByRoom(ClassRoom $room): Response
  1706.     {
  1707.         $year $this->schoolYearService->sessionYearById();
  1708.         $paymentPlan =  $year->getPaymentPlan();
  1709.         // List of student subscriptions for the class
  1710.         $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year"classRoom" => $room));
  1711.         $students = [];
  1712.         $dueAmounts = [];
  1713.         foreach($subscriptions as $sub){
  1714.             if($year->paymentThresholdAmount($room) > $sub->getStudent()->getPaymentsSum($year) ){
  1715.                 $students[] = $sub->getStudent() ;
  1716.                 $dueAmounts[$sub->getStudent()->getId()] = $year->paymentThresholdAmount($room)-$sub->getStudent()->getPaymentsSum($year);
  1717.             }
  1718.         }
  1719.         $html $this->render('classroom/templating/insolvent_student_list.html.twig', [
  1720.             'room' => $room,
  1721.             'students' => $students,
  1722.             'year' => $year,
  1723.             'amounts' =>  $dueAmounts 
  1724.         ]);
  1725.         return new Response(
  1726.             $this->pdf->getOutputFromHtml($html),
  1727.             200,
  1728.             array(
  1729.                 'Content-Type'          => 'application/pdf',
  1730.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $room->getName() . '.pdf"'
  1731.             )
  1732.         );
  1733.     }
  1734.      /**
  1735.      * @Route("/insolventspercentage", name="admin_classroom_insolvents_percentage")
  1736.      */
  1737.     public function insolventStudentsRate(): Response
  1738.     {
  1739.         $year $this->schoolYearService->sessionYearById();
  1740.         $paymentPlan =  $year->getPaymentPlan();
  1741.         $rooms $this->repo->findAll();
  1742.         $rates = [];
  1743.         
  1744.         foreach($rooms as $room){
  1745.             $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year"classRoom" =>  $room));
  1746.             $installments $this->instRepo->findBy(array("classRoom" =>  $room"paymentPlan" =>  $paymentPlan));
  1747.             $sum 0;
  1748.             foreach($installments as $installment){
  1749.                 $sum += $installment->getAmount();
  1750.             }
  1751.             $ratesByRoom = [];
  1752.             foreach($subscriptions as $sub){
  1753.                  $ratesByRoom[]  = 100*$sub->getStudent()->getPaymentsSum($year) / $sum;
  1754.             }
  1755.               // Calculer la somme des valeurs entières
  1756.             $sum array_sum($ratesByRoom);
  1757.             // Calculer la moyenne
  1758.             $avg count($ratesByRoom) > $sum count($ratesByRoom) : 0;
  1759.             $rates[$room->getName()] = $avg ;
  1760.         }
  1761.         $html $this->render('school_year/templating/recovery_rates_by_room.html.twig', [
  1762.             
  1763.             'rates' => $rates,
  1764.             'year' => $year,
  1765.         ]);
  1766.         return new Response(
  1767.             $this->pdf->getOutputFromHtml($html),
  1768.             200,
  1769.             array(
  1770.                 'Content-Type'          => 'application/pdf',
  1771.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $year->getCode() . '.pdf"'
  1772.             )
  1773.         );
  1774.     }
  1775.    
  1776.  
  1777. }