src/Controller/ClassRoomController.php line 602

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