src/Controller/ClassRoomController.php line 40

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.      * Finds and displays a ClassRoom entity.
  220.      *
  221.      * @Route("/{id}/reportCardsYear", name="admin_classrooms_reportcards_year", requirements={"id"="\d+"})
  222.      * @Method("GET")
  223.      * @Template()
  224.      */
  225.     public function reportCardsYearAction(ClassRoom $classroom)
  226.     {
  227.         set_time_limit(600);
  228.         $connection $this->em->getConnection();
  229.         $year $this->schoolYearService->sessionYearById();
  230.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  231.         $statement $connection->prepare(
  232.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ1 AS
  233.             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
  234.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  235.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  236.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  237.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  238.             JOIN  attribution att    ON  att.course_id      =   crs.id
  239.             JOIN  user  teach ON  att.teacher_id  =   teach.id
  240.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  241.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  242.             JOIN  quater   quat     ON  seq.quater_id     =   quat.id
  243.             JOIN  school_year   year     ON  quat.school_year_id     =   year.id
  244.             WHERE    room.id = ? AND eval.sequence_id =1
  245.           "
  246.         );
  247.         $statement->bindValue(1$classroom->getId());
  248.         $statement->execute();
  249.         $statement $connection->prepare(
  250.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ2 AS
  251.             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
  252.             FROM  mark  m   
  253.             JOIN  student    std     ON  m.student_id        =   std.id
  254.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  255.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  256.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 2
  257.             ORDER BY matricule,eval; "
  258.         );
  259.         $statement->bindValue(1$classroom->getId());
  260.         $statement->execute();
  261.         $statement $connection->prepare(
  262.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ3 AS
  263.             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
  264.             FROM  mark  m   
  265.             JOIN  student    std     ON  m.student_id        =   std.id
  266.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  267.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  268.             WHERE  eval.class_room_id =? AND eval.sequence_id = 3
  269.             ORDER BY matricule,eval; "
  270.         );
  271.         $statement->bindValue(1$classroom->getId());
  272.         $statement->execute();
  273.         $statement $connection->prepare(
  274.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ4 AS
  275.             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
  276.             FROM  mark  m   
  277.             JOIN  student    std     ON  m.student_id        =   std.id
  278.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  279.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  280.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 4
  281.             ORDER BY matricule,eval; "
  282.         );
  283.         $statement->bindValue(1$classroom->getId());
  284.         $statement->execute();
  285.         $statement $connection->prepare(
  286.             "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ5 AS
  287.             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
  288.             FROM  mark  m   
  289.             JOIN  student    std     ON  m.student_id        =   std.id
  290.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  291.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  292.             WHERE  eval.class_room_id = ? AND eval.sequence_id = 5
  293.             ORDER BY matricule,eval; "
  294.         );
  295.         $statement->bindValue(1$classroom->getId());
  296.         $statement->execute();
  297.         $statement $connection->prepare(
  298.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ6 AS
  299.             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
  300.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  301.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  302.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  303.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  304.             WHERE    room.id = ? AND eval.sequence_id = 6
  305.             ORDER BY std.matricule"
  306.         );
  307.         $statement->bindValue(1$classroom->getId());
  308.         $statement->execute();
  309.         $dataYear $this->em->getConnection()->executeQuery("select *  from V_STUDENT_MARK_DATA_SEQ1 
  310.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ2 ON  V_STUDENT_MARK_DATA_SEQ1.matricule = V_STUDENT_MARK_DATA_SEQ2.matricule 
  311.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ3 ON  V_STUDENT_MARK_DATA_SEQ2.matricule = V_STUDENT_MARK_DATA_SEQ3.matricule 
  312.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ4 ON  V_STUDENT_MARK_DATA_SEQ3.matricule = V_STUDENT_MARK_DATA_SEQ4.matricule 
  313.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ5 ON  V_STUDENT_MARK_DATA_SEQ4.matricule = V_STUDENT_MARK_DATA_SEQ5.matricule 
  314.             INNER JOIN  V_STUDENT_MARK_DATA_SEQ6 ON  V_STUDENT_MARK_DATA_SEQ5.matricule = V_STUDENT_MARK_DATA_SEQ6.matricule 
  315.             ")->fetchAll();
  316.         $this->snappy->setTimeout(600);
  317.         $html $this->renderView('classroom/reportcard/annual.html.twig', array(
  318.             'year' => $year,
  319.             'data' => $dataYear,
  320.             'room' => $classroom,
  321.             'year' => $year,
  322.             'students' => $studentEnrolled,
  323.         ));
  324.         return new Response(
  325.             $this->snappy->getOutputFromHtml($html),
  326.             200,
  327.             array(
  328.                 'Content-Type' => 'application/pdf',
  329.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  330.             )
  331.         );
  332.     }
  333.     public function viewSeq(int $i){
  334.         $year $this->schoolYearService->sessionYearById();
  335.         $connection $this->em->getConnection();
  336.         $statement $connection->prepare(
  337.             " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  338.             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
  339.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  340.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  341.             JOIN  class_room room    ON  eval.class_room_id     =   room.id
  342.             JOIN  course      crs    ON  eval.course_id      =   crs.id
  343.             JOIN  attribution att    ON  att.course_id      =   crs.id  
  344.             JOIN  user      teach    ON  att.teacher_id  =   teach.id
  345.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  346.             JOIN  sequence    seq    ON  seq.id     =   eval.sequence_id
  347.             JOIN  quater     quat    ON  seq.quater_id     =   quat.id
  348.             JOIN  school_year   year ON  quat.school_year_id     =   year.id
  349.             WHERE att.year_id =? AND  room.id = ? AND eval.sequence_id =?  
  350.             ORDER BY room.id,modu.id ,  std;    "
  351.         );
  352.         $statement->bindValue(1$year->getId());
  353.         $statement->bindValue(2$classroom->getId());
  354.         $statement->bindValue(3$seq->getId());
  355.         $statement->execute();
  356.     }
  357.     /**
  358.      * Finds and displays a ClassRoom entity.
  359.      *
  360.      * @Route("/{id}/reportCardsApcYearapc", name="admin_class_reportcards_apc_year", requirements={"id"="\d+"})
  361.      * @Method("GET")
  362.      * @Template()
  363.      */
  364.     public function reportCards2YearAction(ClassRoom $classroom)
  365.     {
  366.         set_time_limit(600);
  367.         $connection $this->em->getConnection();
  368.         $year $this->schoolYearService->sessionYearById();
  369.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  370.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  371.         $i 1;
  372.         foreach ($sequences as $seq) {
  373.             /*******************************************************************************************************************/
  374.             /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE LA CLASSE**************/
  375.             /*******************************************************************************************************************/
  376.             // CAS DES NOTES SEQUENTIELLES
  377.               // $this->viewSeq($i, $classroom, $seq);
  378.             $this->getViewSeqData$classroom$seq$i);
  379.             
  380.            
  381.             $i++;
  382.         }
  383.         // CAS DES NOTES TRIMESTRIELLES
  384.         $statement $connection->prepare(
  385.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  386.             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
  387.             FROM V_STUDENT_MARK_SEQ1 seq1
  388.             JOIN  V_STUDENT_MARK_SEQ2 seq2  
  389.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  390.             ORDER BY seq1.std"
  391.         );
  392.         $statement->execute();
  393.         $statement $connection->prepare(
  394.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  395.             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
  396.             FROM V_STUDENT_MARK_SEQ3 seq1
  397.             JOIN  V_STUDENT_MARK_SEQ4 seq2  
  398.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  399.             ORDER BY seq1.std"
  400.         );
  401.         $statement->execute();
  402.         $statement $connection->prepare(
  403.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  404.             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
  405.             FROM V_STUDENT_MARK_SEQ5 seq1
  406.             JOIN  V_STUDENT_MARK_SEQ6 seq2  
  407.             ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs)
  408.             ORDER BY seq1.std"
  409.         );
  410.         $statement->execute();
  411.         // CAS DES NOTES ANNUELLES
  412.         $statement $connection->prepare(
  413.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  414.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule ,  student.image_name as profileImagePath, 
  415.             student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  416.             student.gender as gender,student.birthplace as birthplace , 
  417.             class_room.name as room_name,
  418.             course.wording as course, course.coefficient as coef, 
  419.             module.name as module,
  420.             user.full_name as teacher,
  421.             quat1.std,quat1.modu,
  422.             quat1.value as value1, quat1.weight as weight1,  
  423.             quat2.value as value2,  quat2.weight as weight2,  
  424.             quat3.value as value3,quat3.weight as weight3,
  425.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  426.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  427.             FROM student  
  428.             JOIN V_STUDENT_MARK_QUATER_1  quat1 ON  student.id = quat1.std
  429.             JOIN  class_room ON class_room.id = quat1.room
  430.             JOIN  course    ON course.id = quat1.crs
  431.             JOIN  module    ON course.module_id = quat1.modu
  432.             JOIN user ON user.full_name = quat1.teacher
  433.             JOIN   V_STUDENT_MARK_QUATER_2   quat2  ON  quat1.std = quat2.std AND quat1.crs = quat2.crs
  434.             JOIN 
  435.             V_STUDENT_MARK_QUATER_3   quat3  ON  quat1.std = quat3.std AND quat1.crs = quat3.crs
  436.             ORDER BY  quat1.std, quat1.modu
  437.         
  438.             "
  439.         );
  440.         $statement->execute();
  441.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  442.         // For calculating ranks
  443.         $statement $connection->prepare(
  444.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  445.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  446.             FROM ANNUAL_DATA 
  447.             GROUP BY idStd
  448.             ORDER BY SUM(value*weight*coef) DESC"
  449.         );
  450.         $statement->execute();
  451.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  452.         $annualAvgArray = [];
  453.         $sumAvg 0;
  454.         $rank 0;
  455.         $rankArray = [];
  456.         foreach ($annualAvg as $avg) {
  457.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  458.             $rankArray[$avg['idStd']] = ++$rank;
  459.             $sumAvg += $avg['moyenne'];
  460.         }
  461.         $this->snappy->setTimeout(600);
  462.         $html $this->renderView('classroom/reportcardYear.html.twig', array(
  463.             'year' => $year,
  464.             'data' => $dataYear,
  465.             'room' => $classroom,
  466.             'students' => $studentEnrolled,
  467.             'ranks' => $rankArray,
  468.             'means' => $annualAvgArray,
  469.             'genMean' => $sumAvg sizeof($annualAvgArray),
  470.         ));
  471.         //return new Response($html);
  472.         return new Response(
  473.             $this->snappy->getOutputFromHtml($html),
  474.             200,
  475.             array(
  476.                 'Content-Type' => 'application/pdf',
  477.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  478.             )
  479.         );
  480.     }
  481.     /**
  482.      * Finds and displays a Evaluation entity.
  483.      *
  484.      * @Route("/{room}/{seq}/pdf", name="admin_classrooms_recapitulatif", requirements={"room"="\d+","seq"="\d+"})
  485.      * @Method("GET")
  486.      * @Template()
  487.      * @return Response
  488.      */
  489.     public function recapitulatifAction(ClassRoom $roomSequence $seq)
  490.     {
  491.         // Année scolaire en cours
  492.         $year $this->schoolYearService->sessionYearById();
  493.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  494.         $html $this->renderView('classroom/templating/recapitulatifseqvierge.html.twig', array(
  495.             'room' => $room,
  496.             'seq' => $seq,
  497.             'students' => $studentEnrolled,
  498.             'year' => $year,
  499.         ));
  500.         $options = [
  501.             'orientation' => 'Landscape'// Changer ici entre 'Portrait' ou 'Landscape'
  502.             'page-size' => 'A4',          // Format de page
  503.         ];
  504.         return new Response(
  505.             $this->pdf->getOutputFromHtml($html,  $options),
  506.             200,
  507.             array(
  508.                 'Content-Type'          => 'application/pdf',
  509.                 'Content-Disposition'   => 'inline; filename="fiche_recep_' $room->getName() . '.pdf"'
  510.             )
  511.         );
  512.     }
  513.     /**
  514.      * Finds and displays a ClassRoom entity.
  515.      *
  516.      * @Route("/{id}/recapitulatifseq", name="admin_classrooms_recapitulatif_seq", requirements={"id"="\d+"})
  517.      * @Method("GET")
  518.      * @Template()
  519.      */
  520.     public function recapSeqAction(ClassRoom $roomRequest $request)
  521.     {
  522.         // set_time_limit(600);
  523.         $checkedValues $request->request->get('selected_courses');
  524.         $em $this->getDoctrine()->getManager();
  525.         $year $this->schoolYearService->sessionYearById();
  526.         $seq $this->seqRepo->findOneBy(array("activated" => true));
  527.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  528.         $datas $this->markRepo->findMarksBySequenceAndClassOrderByStd($seq$room);
  529.         
  530.         $html $this->renderView('classroom/recapitulatifseq.html.twig', array(
  531.             'room' => $room,
  532.             'datas' => $datas,
  533.             'year' => $year,
  534.             'seq' => $seq,
  535.             'students' => $studentEnrolled,
  536.             'checkedValues' => $checkedValues
  537.         ));
  538.         return new Response($html);
  539.     }
  540.     /**
  541.      * @Route("/create",name= "admin_classrooms_new", methods={"GET","POST"})
  542.      */
  543.     public function create(Request $request): Response
  544.     {
  545.         if (!$this->getUser()) {
  546.             $this->addFlash('warning''You need login first!');
  547.             return $this->redirectToRoute('app_login');
  548.         }
  549.         $schoolyear = new ClassRoom();
  550.         $form $this->createForm(ClassRoomType::class, $schoolyear);
  551.         $form->handleRequest($request);
  552.         if ($form->isSubmitted() && $form->isValid()) {
  553.             $this->em->persist($schoolyear);
  554.             $this->em->flush();
  555.             $this->addFlash('success''ClassRoom succesfully created');
  556.             return $this->redirectToRoute('admin_classrooms');
  557.         }
  558.         return $this->render(
  559.             'classroom/new.html.twig',
  560.             ['form' => $form->createView()]
  561.         );
  562.     }
  563.     /**
  564.      * Rapport séquentiel d'enregistrement des notes.
  565.      *
  566.      * @Route("/{id}/evalrepport", name="admin_current_fulfilled_eval_show", requirements={"id"="\d+"})
  567.      * @Method("GET")
  568.      * @Template()
  569.      */
  570.     public function currentFullfilledEvalAction(ClassRoom $classroom)
  571.     {
  572.         $em $this->getDoctrine()->getManager();
  573.         $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));
  574.         // Liste des séquences de l'année scolaire en cours
  575.         $sequences $em->getRepository('AppBundle:Sequence')->findSequencesBySchoolYear($year);
  576.         // Liste des matières
  577.         $courses $em->getRepository('AppBundle:Course')->findProgrammedCoursesInClass($classroom);
  578.         // Elèves inscrits
  579.         foreach ($sequences as $seq) {
  580.             // Lecture de chaque tableau de chaque ligne
  581.             foreach ($courses as $course) {
  582.                 // Liste des évaluations
  583.                 $evaluation $em->getRepository('AppBundle:Evaluation')->findOneBy(array(
  584.                     "classRoom" => $classroom,
  585.                     "sequence" => $seq"course" => $course
  586.                 ));
  587.                 if ($evaluation != null) {
  588.                     $evaluations[$seq->getId()][$course->getId()] = 1;
  589.                 } else {
  590.                     $evaluations[$seq->getId()][$course->getId()] = 0;
  591.                 }
  592.             }
  593.         }
  594.         return $this->render('classroom/eval_repport.html.twig', array(
  595.             'evaluations' => $evaluations,
  596.             'courses' => $courses,
  597.             'room' => $classroom,
  598.             'sequences' => $sequences,
  599.         ));
  600.     }
  601.     /**
  602.      * Displays a form to edit an existing ClassRoomme entity.
  603.      *
  604.      * @Route("/{id}/edit", name="admin_classrooms_edit", requirements={"id"="\d+"}, methods={"GET","PUT"})
  605.      * @Template()
  606.      */
  607.     public function edit(Request $requestClassRoom $room): Response
  608.     {
  609.         $form $this->createForm(ClassRoomType::class, $room, [
  610.             'method' => 'PUT'
  611.                 ]);
  612.         
  613.         $form->handleRequest($request);
  614.         if ($form->isSubmitted() && $form->isValid()) {
  615.             $this->em->flush();
  616.             $this->addFlash('success''ClassRoom succesfully updated');
  617.             return $this->redirectToRoute('admin_classrooms');
  618.         }
  619.         return $this->render('classroom/edit.html.twig', [
  620.             'room' => $room,
  621.             'form' => $form->createView()
  622.         ]);
  623.     }
  624.     /**
  625.      * Deletes a ClassRoom entity.
  626.      *
  627.      * @Route("/{id}/delete", name="admin_classrooms_delete", requirements={"id"="\d+"}, methods={"DELETE"})
  628.      
  629.      */
  630.     public function delete(ClassRoom $qRequest $request): Response
  631.     {
  632.         //  dd($q);
  633.         // if($this->isCsrfTokenValid('classrooms_deletion'.$schoolyear->getId(), $request->request->get('crsf_token') )){
  634.         $this->em->remove($q);
  635.         $this->em->flush();
  636.         $this->addFlash('info''ClassRoom succesfully deleted');
  637.         //    }
  638.         return $this->redirectToRoute('admin_classrooms');
  639.     }
  640.     /**
  641.      * Finds and displays a ClassRoom entity.
  642.      *
  643.      * @Route("/{id}/fichesimple", name="admin_classrooms_fichesimple", requirements={"id"="\d+"})
  644.      * @Method("GET")
  645.      * @Template()
  646.      */
  647.     public function fichesiplmeAction(ClassRoom $classroom)
  648.     {
  649.         // Année scolaire en cours
  650.         $year $this->schoolYearService->sessionYearById();
  651.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  652.         $html $this->renderView('classroom/templating/fiche_repport_notes.html.twig', array(
  653.             'year' => $year,
  654.             'room' => $classroom,
  655.             'students' => $studentEnrolled,
  656.         ));
  657.         return new Response(
  658.             $this->pdf->getOutputFromHtml($html),
  659.             200,
  660.             array(
  661.                 'Content-Type'          => 'application/pdf',
  662.                 'Content-Disposition'   => 'inline; filename="fiche_pv_' $classroom->getName() . '.pdf"'
  663.             )
  664.         );
  665.     }
  666.      /**
  667.      * Finds and displays a ClassRoom entity.
  668.      *
  669.      * @Route("/{id}/disciplinary_record", name="admin_classrooms_disciplinary_record", requirements={"id"="\d+"})
  670.      * @Method("GET")
  671.      * @Template()
  672.      */
  673.     public function ficheDisciplineAction(ClassRoom $classroom)
  674.     {
  675.         // Année scolaire en cours
  676.         $year $this->schoolYearService->sessionYearById();
  677.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  678.         $html $this->renderView('classroom/templating/fiche_repport_disc.html.twig', array(
  679.             'year' => $year,
  680.             'room' => $classroom,
  681.             'students' => $studentEnrolled,
  682.         ));
  683.         return new Response(
  684.             $this->pdf->getOutputFromHtml($html),
  685.             200,
  686.             array(
  687.                 'Content-Type'          => 'application/pdf',
  688.                 'Content-Disposition'   => 'inline; filename="fich_disc_' $classroom->getName() . '.pdf"'
  689.             )
  690.         );
  691.     }
  692.     /**
  693.      * LISTE DES ELEVES DE LA CLASSE DANS UNE FICHE DE PRESENTATION.
  694.      *
  695.      * @Route("/{id}/presentation", name="admin_classrooms_presentation", requirements={"id"="\d+"})
  696.      * @Method("GET")
  697.      * @Template()
  698.      */
  699.     public function presentationAction(ClassRoom $classroom)
  700.     {
  701.         // Année scolaire en cours
  702.         $year $this->schoolYearService->sessionYearById();
  703.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  704.         $html $this->renderView('classroom/templating/student_list.html.twig', array(
  705.             'year' => $year,
  706.             'room' => $classroom,
  707.             'students' => $studentEnrolled,
  708.         ));
  709.         return new Response(
  710.             $this->pdf->getOutputFromHtml($html),
  711.             200,
  712.             array(
  713.                 'Content-Type'          => 'application/pdf',
  714.                 'Content-Disposition'   => 'inline; filename="std_list_' $classroom->getName() . '.pdf"'
  715.             )
  716.         );
  717.     }
  718.     /**
  719.      * MOYENNE GENERALE DE LA CLASSE A UNE SEQUENCE
  720.      * @Route("/{id_room}/{id_seq}/sqavg", name="admin_classrooms_avg_seq", requirements={"id_room"="\d+", "id_seq"="\d+"})
  721.      * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  722.      * @ParamConverter("seq", options={"mapping": {"id_seq"   : "id"}})
  723.      * @Method("GET")
  724.      * @Template()
  725.      */
  726.     public function generalSeqAverage(ClassRoom $roomSequence $seq)
  727.     {
  728.         $dql =     "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient)  FROM App\Entity\Evaluation evaluation , App\Entity\Course  course
  729.         WHERE evaluation.course=         course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  730.         $avg_seq1 $this->em->createQuery($dql)
  731.             ->setParameter(1$room->getId())
  732.             ->setParameter(2$seq->getId())
  733.             ->getSingleScalarResult();
  734.         return round($avg_seq12);
  735.     }
  736.     /**
  737.      * MOYENNE GENERALE DE LA CLASSE A UN TRIMESTRE
  738.      * @Route("/{id_room}/{id_quat}/qtavg", name="admin_classrooms_avg_quat", requirements={"id_room"="\d+", "id_quat"="\d+"})
  739.      * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  740.      * @ParamConverter("quater", options={"mapping": {"id_quat"   : "id"}})
  741.      * @Method("GET")
  742.      * @Template()
  743.      */
  744.     public function generalQuatAverage(ClassRoom $roomQuater $quater)
  745.     {
  746.         $dql =     "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient)  FROM App\Entity\Evaluation evaluation , App\Entity\Course  course
  747.         WHERE evaluation.course=         course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  748.         $avg_seq 0;
  749.         foreach ($quater->getSequences() as $seq) {
  750.             $avg_seq += $this->em->createQuery($dql)
  751.                 ->setParameter(1$room->getId())
  752.                 ->setParameter(2$seq->getId())
  753.                 ->getSingleScalarResult();
  754.         }
  755.         return round($avg_seq 22);
  756.     }
  757.     /**
  758.      * Finds and displays a Evaluation entity.
  759.      *
  760.      * @Route("/{room}/pdf", name="admin_classrooms_blanc_ann", requirements={"room"="\d+"})
  761.      * @Method("GET")
  762.      * @Template()
  763.      * @return Response
  764.      */
  765.     public function annualSummaryAction(ClassRoom $room)
  766.     {
  767.         $year $this->schoolYearService->sessionYearById();
  768.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  769.         $html $this->renderView('classroom/templating/blankAnnualForm.html.twig', array(
  770.             'room' => $room,
  771.             'students' => $studentEnrolled,
  772.             'year' => $year,
  773.         ));
  774.         return new Response(
  775.             $this->pdf->getOutputFromHtml($html, array(
  776.                 'default-header' => false
  777.             )),
  778.             200,
  779.             array(
  780.                 'Content-Type' => 'application/pdf',
  781.                 'Content-Disposition' => 'attachment; filename="recap_empty_' $room->getName() . '.pdf"',
  782.             )
  783.         );
  784.     }
  785.     /**
  786.      * Finds and displays a ClassRoom entity.
  787.      *
  788.      * @Route("/{id}/reportCardSeq", name="admin_classrooms_reportcards_seq", requirements={"id"="\d+"})
  789.      * @Method("GET")
  790.      * @Template()
  791.      */
  792.     public function reportCardSeqAction(ClassRoom $classroom)
  793.     {
  794.         set_time_limit(600);
  795.         $totalNtCoef 0;
  796.         $totalCoef 0;
  797.         $em $this->getDoctrine()->getManager();
  798.         $year =$this->schoolYearService->sessionYearById();
  799.         $sequence $this->seqRepo->findOneBy(array("activated" => true));
  800.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  801.         // Existance des photos d'eleves
  802.         $fileExists = [];
  803.         foreach ($studentEnrolled as $std) {
  804.             $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  805.             $fileExists[$std->getId()] = file_exists($filename);
  806.         }
  807.         $evaluations $this->evalRepo->findSequantialExamsOfRoom($classroom->getId(), $sequence->getId());
  808.         foreach ($evaluations as $ev) {
  809.             $totalNtCoef += $ev->getMoyenne() * $ev->getCourse()->getCoefficient();
  810.             $totalCoef += $ev->getCourse()->getCoefficient();
  811.         }
  812.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  813.         $this->getViewSeqData($classroom$sequence0);
  814.         $connection $this->em->getConnection();
  815.         $datas $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_SEQ0  ")->fetchAll();
  816.          // For calculating ranks
  817.         $statement $connection->prepare(
  818.             "   CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  819.                 SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  820.                 FROM V_STUDENT_MARK_SEQ0 
  821.                 GROUP BY std
  822.                 ORDER BY SUM(value*weight*coef) DESC"
  823.         );
  824.         $statement->execute();
  825.         $seqAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  826.         $seqAvgArray = [];
  827.         $sumAvg 0;
  828.         $rank 0;
  829.         $rankArray = [];
  830.        
  831.         foreach ($seqAvg as $avg) {
  832.             $seqAvgArray[$avg['std']] = $avg['moyenne'];
  833.             $rankArray[$avg['std']] = ++$rank;
  834.             $sumAvg += $avg['moyenne'];
  835.         }
  836.         // CAS DES ABSCENCES SEQUENTIELLES
  837.         $statement $connection->prepare(
  838.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ AS
  839.             SELECT DISTINCT   seq.std as std , seq.total_hours  as abscences
  840.             FROM V_STUDENT_ABSCENCE_SEQ0 seq
  841.             ORDER BY std "
  842.         );
  843.         $statement->execute();
  844.          // Traitement des abscences
  845.          $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_SEQ ")->fetchAll();
  846.          $absencesArray = [];
  847.          foreach ($absences as $abs) {
  848.              $absencesArray[$abs['std']] = $abs['abscences'];
  849.          }
  850.         $html $this->renderView('classroom/reportcard/sequential.html.twig', array(
  851.             'year' => $year,
  852.             'datas' => $datas,
  853.             'students' => $studentEnrolled,
  854.             'sequence' => $sequence,
  855.             'quater' => $sequence->getQuater(),
  856.             'room' => $classroom,
  857.             'students' => $studentEnrolled,
  858.             'ranks' => $rankArray,
  859.             'means' => $seqAvgArray,
  860.             'abscences' => $absencesArray,
  861.             'genMean' => $sumAvg sizeof($seqAvgArray),
  862.             'fileExists'=> $fileExists
  863.         ));
  864.         return new Response(
  865.             $this->pdf->getOutputFromHtml($html),
  866.             200,
  867.             array(
  868.                 'Content-Type'          => 'application/pdf',
  869.                 'Content-Disposition'   => 'inline; filename="bull_seq_' $classroom->getName() . '.pdf"'
  870.             )
  871.         );
  872.         
  873.     }
  874.     public function getViewSeqData(ClassRoom $room,Sequence $seqint $i){
  875.         $connection $this->em->getConnection();
  876.         $year $this->schoolYearService->sessionYearById();
  877.          // CAS DES NOTES SEQUENTIELLES
  878.         $statement $connection->prepare(
  879.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  880.             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
  881.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  882.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  883.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  884.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  885.             JOIN  attribution att    ON  att.course_id      =   crs.id  and att.year_id = ?
  886.             JOIN  user  teach        ON  att.teacher_id  =   teach.id
  887.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  888.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  889.             LEFT JOIN  abscence_sheet   sheet     ON  seq.id     =   sheet.sequence_id AND sheet.class_room_id = room.id
  890.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  891.             JOIN  quater   quat      ON  seq.quater_id     =   quat.id
  892.             WHERE    room.id = ? AND eval.sequence_id =? 
  893.             ORDER BY room.id,modu.id ,  std; "
  894.         );
  895.         $statement->bindValue(1$year->getId());
  896.         $statement->bindValue(2$room->getId());
  897.         $statement->bindValue(3$seq->getId());
  898.         $statement->execute();
  899.         $statement $connection->prepare(
  900.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" $i " AS
  901.             SELECT DISTINCT  room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  902.             FROM   class_room room  
  903.             LEFT JOIN  abscence_sheet   sheet     ON  sheet.class_room_id = room.id AND sheet.sequence_id = ?
  904.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  905.             WHERE  room.id = ? 
  906.             GROUP BY  std
  907.             ORDER BY room.id, std; "
  908.         );
  909.         $statement->bindValue(1$seq->getId());
  910.         $statement->bindValue(2$room->getId());
  911.         $statement->execute();
  912.        
  913.     }
  914.     public function getViewQuaterData(ClassRoom $roomint $i){
  915.         $connection $this->em->getConnection();
  916.         $year $this->schoolYearService->sessionYearById();
  917.          // CAS DES NOTES SEQUENTIELLES
  918.         $statement $connection->prepare(
  919.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_ROOM" $room->getId() . " AS
  920.             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
  921.             FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  922.             JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  923.             JOIN  class_room room    ON   eval.class_room_id     =   room.id
  924.             JOIN  course     crs     ON  eval.course_id      =   crs.id
  925.             JOIN  attribution att    ON  att.course_id      =   crs.id  and att.year_id = ?
  926.             JOIN  user  teach        ON  att.teacher_id  =   teach.id
  927.             JOIN  module     modu    ON  modu.id       =   crs.module_id
  928.             JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  929.             LEFT JOIN  abscence_sheet   sheet     ON  seq.id     =   sheet.sequence_id AND sheet.class_room_id = room.id
  930.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  931.             JOIN  quater   quat      ON  seq.quater_id     =   quat.id AND  quat.id = ?
  932.             WHERE    room.id = ?  
  933.             ORDER BY  std.id,modu.id , crs.id,seq.id ; "
  934.         );
  935.         $statement->bindValue(1$year->getId());
  936.         $statement->bindValue(2$seq->getQuater()->getId());
  937.         $statement->bindValue(3$room->getId());
  938.         $statement->execute();
  939.         $statement $connection->prepare(
  940.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" $i " AS
  941.             SELECT DISTINCT  room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  942.             FROM   class_room room  
  943.             LEFT JOIN  abscence_sheet   sheet     ON  sheet.class_room_id = room.id AND sheet.sequence_id = ?
  944.             LEFT JOIN  abscence   abs     ON  sheet.id     =   abs.abscence_sheet_id
  945.             WHERE  room.id = ? 
  946.             GROUP BY  std
  947.             ORDER BY room.id, std; "
  948.         );
  949.         $statement->bindValue(1$seq->getId());
  950.         $statement->bindValue(2$room->getId());
  951.         $statement->execute();
  952.        
  953.     }
  954.     /**
  955.      * Finds and displays a ClassRoom entity.
  956.      *
  957.      * @Route("/{id}/reportCardsTrim", name="admin_classrooms_reportcards_trim", requirements={"id"="\d+"})
  958.      * @Method("GET")
  959.      * @Template()
  960.      */
  961.     public function reportCardsTrimAction(ClassRoom $roomRequest $request)
  962.     {
  963.         $connection $this->em->getConnection();
  964.         $year $this->schoolYearService->sessionYearById();
  965.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  966.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  967.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  968.          // Existance des photos d'eleves
  969.          $fileExists = [];
  970.          foreach ($studentEnrolled as $std) {
  971.              $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  972.              $fileExists[$std->getId()] = file_exists($filename);
  973.          }
  974.         
  975.         /*******************************************************************************************************************/
  976.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  977.         /*******************************************************************************************************************/
  978.         $i 1;
  979.         foreach ($sequences as $seq) {
  980.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  981.             $this->getViewSeqData($room$seq$i);
  982.             $i++;
  983.         }
  984.         // CAS DES NOTES TRIMESTRIELLES
  985.         $statement $connection->prepare(
  986.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  987.             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
  988.             FROM V_STUDENT_MARK_SEQ1 seq1
  989.             JOIN  V_STUDENT_MARK_SEQ2 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  990.             ORDER BY std , module"
  991.         );
  992.         $statement->execute();
  993.         // CAS DES ABSCENCES TRIMESTRIELLES
  994.         $statement $connection->prepare(
  995.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER AS
  996.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  997.             FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  998.              JOIN  V_STUDENT_ABSCENCE_SEQ2 seq2  ON  (seq1.std    =   seq2.std  )
  999.             ORDER BY std "
  1000.         );
  1001.         $statement->execute();
  1002.         $dataQuater $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_QUATER marks  ")->fetchAll();
  1003.         // For calculating ranks
  1004.         $statement $connection->prepare(
  1005.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1006.         SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1007.         FROM V_STUDENT_MARK_QUATER 
  1008.         GROUP BY std
  1009.         ORDER BY SUM(value*weight*coef) DESC"
  1010.         );
  1011.         $statement->execute();
  1012.         $quaterAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1013.         $quaterAvgArray = [];
  1014.         $sumAvg 0;
  1015.         $rank 0;
  1016.         $rankArray = [];
  1017.        
  1018.         foreach ($quaterAvg as $avg) {
  1019.             $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1020.             $rankArray[$avg['std']] = ++$rank;
  1021.             $sumAvg += $avg['moyenne'];
  1022.         }
  1023.         
  1024.         // Traitement des abscences
  1025.         $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_QUATER ")->fetchAll();
  1026.         $absencesArray = [];
  1027.         foreach ($absences as $abs) {
  1028.             $absencesArray[$abs['std']] = $abs['abscences'];
  1029.         }
  1030.         $this->pdf->setTimeout(600);
  1031.         $html $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1032.             'year' => $year,
  1033.             'data' => $dataQuater,
  1034.             'ranks' => $rankArray,
  1035.             'means' => $quaterAvgArray,
  1036.             'abscences' => $absencesArray,
  1037.             'genMean' => $sumAvg sizeof($quaterAvgArray),
  1038.             'room' => $room,
  1039.             'quater' => $quater,
  1040.             'sequences' => $sequences,
  1041.             'students' => $studentEnrolled,
  1042.             'fileExists'=> $fileExists
  1043.         ));
  1044.         return new Response(
  1045.             $this->pdf->getOutputFromHtml($html),
  1046.             200,
  1047.             array(
  1048.                 'Content-Type'          => 'application/pdf',
  1049.                 'Content-Disposition'   => 'inline; filename="' $room->getName() . '.pdf"'
  1050.             )
  1051.         );
  1052.         // return new Response($html);
  1053.     }
  1054.      /**
  1055.      * Finds and displays a ClassRoom entity.
  1056.      *
  1057.      * @Route("/{id}/reportCardsTrim2024", name="admin_classrooms_reportcards_trim_2024", requirements={"id"="\d+"})
  1058.      * @Method("GET")
  1059.      * @Template()
  1060.      */
  1061.     public function reportCardsTrim2024Action(ClassRoom $roomRequest $request)
  1062.     {
  1063.         $connection $this->em->getConnection();
  1064.         $year $this->schoolYearService->sessionYearById();
  1065.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1066.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  1067.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($room$year);
  1068.          // Existance des photos d'eleves
  1069.          $fileExists = [];
  1070.          foreach ($studentEnrolled as $std) {
  1071.              $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  1072.              $fileExists[$std->getId()] = file_exists($filename);
  1073.          }
  1074.         
  1075.         /*******************************************************************************************************************/
  1076.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1077.         /*******************************************************************************************************************/
  1078.         $i 1;
  1079.         foreach ($sequences as $seq) {
  1080.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1081.             $this->getViewQuaterData($room,  $i);
  1082.             $i++;
  1083.         }
  1084.        
  1085.         // CAS DES ABSCENCES TRIMESTRIELLES
  1086.         $statement $connection->prepare(
  1087.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_ROOM AS
  1088.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1089.             FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1090.              JOIN  V_STUDENT_ABSCENCE_SEQ2 seq2  ON  (seq1.std    =   seq2.std  )
  1091.             ORDER BY std "
  1092.         );
  1093.         $statement->execute();
  1094.         $dataQuater $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_QUATER marks  ")->fetchAll();
  1095.         // For calculating ranks
  1096.         $statement $connection->prepare(
  1097.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1098.         SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1099.         FROM V_STUDENT_MARK_QUATER 
  1100.         GROUP BY std
  1101.         ORDER BY SUM(value*weight*coef) DESC"
  1102.         );
  1103.         $statement->execute();
  1104.         $quaterAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1105.         $quaterAvgArray = [];
  1106.         $sumAvg 0;
  1107.         $rank 0;
  1108.         $rankArray = [];
  1109.        
  1110.         foreach ($quaterAvg as $avg) {
  1111.             $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1112.             $rankArray[$avg['std']] = ++$rank;
  1113.             $sumAvg += $avg['moyenne'];
  1114.         }
  1115.         
  1116.         // Traitement des abscences
  1117.         $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_QUATER ")->fetchAll();
  1118.         $absencesArray = [];
  1119.         foreach ($absences as $abs) {
  1120.             $absencesArray[$abs['std']] = $abs['abscences'];
  1121.         }
  1122.         $this->pdf->setTimeout(600);
  1123.         $html $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1124.             'year' => $year,
  1125.             'data' => $dataQuater,
  1126.             'ranks' => $rankArray,
  1127.             'means' => $quaterAvgArray,
  1128.             'abscences' => $absencesArray,
  1129.             'genMean' => $sumAvg sizeof($quaterAvgArray),
  1130.             'room' => $room,
  1131.             'quater' => $quater,
  1132.             'sequences' => $sequences,
  1133.             'students' => $studentEnrolled,
  1134.             'fileExists'=> $fileExists
  1135.         ));
  1136.         return new Response(
  1137.             $this->pdf->getOutputFromHtml($html),
  1138.             200,
  1139.             array(
  1140.                 'Content-Type'          => 'application/pdf',
  1141.                 'Content-Disposition'   => 'inline; filename="' $room->getName() . '.pdf"'
  1142.             )
  1143.         );
  1144.         // return new Response($html);
  1145.     }
  1146.     /**
  1147.      * Finds and displays a ClassRoom entity.
  1148.      *
  1149.      * @Route("/{id}/annualavglist", name="admin_avg_list", requirements={"id"="\d+"})
  1150.      * @Method("GET")
  1151.      * @Template()
  1152.      */
  1153.     public function annualAvgList(ClassRoom $classroomRequest $request)
  1154.     {
  1155.         $connection $this->em->getConnection();
  1156.         $year $this->schoolYearService->sessionYearById();
  1157.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1158.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  1159.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  1160.          /*******************************************************************************************************************/
  1161.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1162.         /*******************************************************************************************************************/
  1163.         $i 1;
  1164.         foreach ($sequences as $seq) {
  1165.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1166.             $this->getViewSeqData($classroom$seq$i);
  1167.             $i++;
  1168.         }
  1169.          // CAS DES NOTES TRIMESTRIELLES1
  1170.          $statement $connection->prepare(
  1171.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1172.             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
  1173.             FROM V_STUDENT_MARK_SEQ1 seq1
  1174.             JOIN  V_STUDENT_MARK_SEQ2 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1175.             ORDER BY std , modu"
  1176.         );
  1177.         $statement->execute();
  1178.        
  1179.          // CAS DES NOTES TRIMESTRIELLES2
  1180.          $statement $connection->prepare(
  1181.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1182.             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
  1183.             FROM V_STUDENT_MARK_SEQ3 seq1
  1184.             JOIN  V_STUDENT_MARK_SEQ4 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1185.             ORDER BY std , modu"
  1186.         );
  1187.         $statement->execute();
  1188.           // CAS DES NOTES TRIMESTRIELLES3
  1189.           $statement $connection->prepare(
  1190.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1191.             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
  1192.             FROM V_STUDENT_MARK_SEQ5 seq1
  1193.             JOIN  V_STUDENT_MARK_SEQ6 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1194.             ORDER BY std , modu"
  1195.         );
  1196.         $statement->execute();
  1197.         $statement $connection->prepare(
  1198.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1199.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule 
  1200.             student.lastname as lastname, student.firstname as firstname
  1201.             course.wording as course, course.coefficient as coef, 
  1202.             module.name as module,
  1203.             user.full_name as teacher,
  1204.             quat1.std, quat1.modu,
  1205.             quat1.value as value1,  quat1.weight as weight1,
  1206.             quat2.value as value2,  quat2.weight as weight2,
  1207.             quat3.value as value3,  quat3.weight as weight3,
  1208.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1209.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1210.             FROM student  
  1211.             JOIN   V_STUDENT_MARK_QUATER_1      quat1   ON  student.id = quat1.std 
  1212.             JOIN   V_STUDENT_MARK_QUATER_2      quat2  ON  student.id = quat2.std AND quat1.crs = quat2.crs
  1213.             JOIN   V_STUDENT_MARK_QUATER_3      quat3   ON  student.id = quat3.std AND quat2.crs = quat3.crs
  1214.             JOIN  class_room ON class_room.id = quat1.room
  1215.             JOIN  course     ON course.id = quat1.crs
  1216.             JOIN  module     ON course.module_id = quat1.modu
  1217.             JOIN  user       ON user.full_name = quat1.teacher
  1218.             ORDER BY  quat1.std, quat1.modu
  1219.             "
  1220.         );
  1221.         $statement->execute();
  1222.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  1223.         // For calculating ranks
  1224.         $statement $connection->prepare(
  1225.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1226.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1227.             FROM ANNUAL_DATA 
  1228.             GROUP BY idStd
  1229.             ORDER BY SUM(value*weight*coef) DESC"
  1230.         );
  1231.         $statement->execute();
  1232.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1233.         $annualAvgArray = [];
  1234.         $sumAvg 0;
  1235.         $rank 0;
  1236.         $rankArray = [];
  1237.         foreach ($annualAvg as $avg) {
  1238.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1239.             $rankArray[$avg['idStd']] = ++$rank;
  1240.             $sumAvg += $avg['moyenne'];
  1241.         }
  1242.         $html $this->renderView('classroom/avglist.html.twig', array(
  1243.            
  1244.             'year' => $year,
  1245.             'room' => $classroom,
  1246.             'students' => $studentEnrolled,
  1247.             'ranks' => $rankArray,
  1248.             'means' => $annualAvgArray,
  1249.             'genMean' => $sumAvg sizeof($annualAvgArray),
  1250.         ));
  1251.         return new Response(
  1252.             $this->snappy->getOutputFromHtml($html,  [
  1253.                 'page-size' => 'A4',
  1254.                
  1255.             ]),
  1256.             200,
  1257.             array(
  1258.                 'Content-Type' => 'application/pdf',
  1259.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  1260.             )
  1261.         );
  1262.     }
  1263.     /**
  1264.      * Finds and displays a ClassRoom entity.
  1265.      *
  1266.      * @Route("/{id}/reportCards3ApcYearApc", name="admin_class_reportcards_3_apc_year", requirements={"id"="\d+"})
  1267.      * @Method("GET")
  1268.      * @Template()
  1269.      */
  1270.     public function reportCards3YearAction(ClassRoom $classroomRequest $request)
  1271.     {
  1272.         $headerFontSize $request->request->get('header_font_size');
  1273.         $lineHeight $request->request->get('line_height');
  1274.         $copyright =  $request->request->get('copyright')=="on";
  1275.         $reverse =  $request->request->get('reverse')=="on";
  1276.         
  1277.         $connection $this->em->getConnection();
  1278.         $year $this->schoolYearService->sessionYearById();
  1279.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1280.         $sequences  $this->seqRepo->findSequenceThisYear($year);
  1281.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom$year);
  1282.          // Existance des photos d'eleves
  1283.          $fileExists = [];
  1284.          foreach ($studentEnrolled as $std) {
  1285.              $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  1286.              $fileExists[$std->getId()] = file_exists($filename);
  1287.          }
  1288.         /*******************************************************************************************************************/
  1289.         /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES  DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1290.         /*******************************************************************************************************************/
  1291.         $i 1;
  1292.         foreach ($sequences as $seq) {
  1293.             // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1294.             $this->getViewSeqData($classroom$seq$i);
  1295.             $i++;
  1296.         }
  1297.         // CAS DES NOTES TRIMESTRIELLES1
  1298.         $statement $connection->prepare(
  1299.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1300.             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
  1301.             FROM V_STUDENT_MARK_SEQ1 seq1
  1302.             JOIN  V_STUDENT_MARK_SEQ2 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1303.             ORDER BY std , modu"
  1304.         );
  1305.         $statement->execute();
  1306.         // CAS DES ABSCENCES TRIMESTRIELLES1
  1307.         $statement $connection->prepare(
  1308.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_1 AS
  1309.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1310.             FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1311.              JOIN  V_STUDENT_ABSCENCE_SEQ2 seq2  ON  (seq1.std    =   seq2.std  )
  1312.             ORDER BY std "
  1313.         );
  1314.         $statement->execute();
  1315.          // CAS DES NOTES TRIMESTRIELLES2
  1316.          $statement $connection->prepare(
  1317.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1318.             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
  1319.             FROM V_STUDENT_MARK_SEQ3 seq1
  1320.             JOIN  V_STUDENT_MARK_SEQ4 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1321.             ORDER BY std , modu"
  1322.         );
  1323.         $statement->execute();
  1324.         // CAS DES ABSCENCES TRIMESTRIELLES2
  1325.         $statement $connection->prepare(
  1326.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_2 AS
  1327.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1328.             FROM V_STUDENT_ABSCENCE_SEQ3 seq1
  1329.              JOIN  V_STUDENT_ABSCENCE_SEQ4 seq2  ON  (seq1.std    =   seq2.std  )
  1330.             ORDER BY std "
  1331.         );
  1332.         $statement->execute();
  1333.          // CAS DES NOTES TRIMESTRIELLES3
  1334.          $statement $connection->prepare(
  1335.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1336.             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
  1337.             FROM V_STUDENT_MARK_SEQ5 seq1
  1338.             JOIN  V_STUDENT_MARK_SEQ6 seq2  ON  (seq1.std    =   seq2.std  AND seq1.crs = seq2.crs )
  1339.             ORDER BY std , modu"
  1340.         );
  1341.         $statement->execute();
  1342.         // CAS DES ABSCENCES TRIMESTRIELLES3
  1343.         $statement $connection->prepare(
  1344.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_3 AS
  1345.             SELECT DISTINCT   seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1346.             FROM V_STUDENT_ABSCENCE_SEQ5 seq1
  1347.              JOIN  V_STUDENT_ABSCENCE_SEQ6 seq2  ON  (seq1.std    =   seq2.std  )
  1348.             ORDER BY std "
  1349.         );
  1350.         $statement->execute();
  1351.         set_time_limit(600);
  1352.         $statement $connection->prepare(
  1353.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1354.             SELECT DISTINCT   student.id as idStd ,  student.matricule as matricule ,  student.image_name as profileImagePath, 
  1355.             student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  1356.             student.gender as gender,student.birthplace as birthplace , 
  1357.             class_room.name as room_name,
  1358.             course.wording as course, course.coefficient as coef, 
  1359.             module.name as module,
  1360.             user.full_name as teacher,
  1361.             quat1.std, quat1.modu,
  1362.             quat1.value as value1,  quat1.weight as weight1,
  1363.             quat2.value as value2,  quat2.weight as weight2,
  1364.             quat3.value as value3,  quat3.weight as weight3,
  1365.             greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1366.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1367.             FROM student  
  1368.             JOIN   V_STUDENT_MARK_QUATER_1      quat1   ON  student.id = quat1.std 
  1369.             JOIN   V_STUDENT_MARK_QUATER_2      quat2  ON  student.id = quat2.std AND quat1.crs = quat2.crs
  1370.             JOIN   V_STUDENT_MARK_QUATER_3      quat3   ON  student.id = quat3.std AND quat2.crs = quat3.crs
  1371.             JOIN  class_room ON class_room.id = quat1.room
  1372.             JOIN  course     ON course.id = quat1.crs
  1373.             JOIN  module     ON course.module_id = quat1.modu
  1374.             JOIN  user       ON user.full_name = quat1.teacher
  1375.             ORDER BY  quat1.std, quat1.modu
  1376.             "
  1377.         );
  1378.         $statement->execute();
  1379.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  1380.         // For calculating ranks
  1381.         $statement $connection->prepare(
  1382.             "  CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1383.             SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1384.             FROM ANNUAL_DATA 
  1385.             GROUP BY idStd
  1386.             ORDER BY SUM(value*weight*coef) DESC"
  1387.         );
  1388.         $statement->execute();
  1389.         $annualAvg $connection->executeQuery("SELECT *  FROM V_STUDENT_RANKS ")->fetchAll();
  1390.         $annualAvgArray = [];
  1391.         $sumAvg 0;
  1392.         $rank 0;
  1393.         $rankArray = [];
  1394.         foreach ($annualAvg as $avg) {
  1395.             $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1396.             $rankArray[$avg['idStd']] = ++$rank;
  1397.             $sumAvg += $avg['moyenne'];
  1398.         }
  1399.          // CAS DES ABSCENCES ANNUELLES
  1400.          $statement $connection->prepare(
  1401.             "  CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_ANNUAL AS
  1402.             SELECT DISTINCT   q1.std as std , q1.abscences + q2.abscences + q3.abscences as abscences
  1403.              FROM  V_STUDENT_ABSCENCE_QUATER_1 q1
  1404.              JOIN  V_STUDENT_ABSCENCE_QUATER_2 q2  ON  (q1.std    =   q2.std  )
  1405.              JOIN  V_STUDENT_ABSCENCE_QUATER_3 q3  ON  (q1.std    =   q3.std  )
  1406.             ORDER BY std "
  1407.         );
  1408.         $statement->execute();
  1409.          // Traitement des abscences
  1410.          $absences $connection->executeQuery("SELECT *  FROM V_STUDENT_ABSCENCE_ANNUAL ")->fetchAll();
  1411.          $absencesArray = [];
  1412.          foreach ($absences as $abs) {
  1413.              $absencesArray[$abs['std']] = $abs['abscences'];
  1414.          }
  1415.         $html $this->renderView('classroom/reportcard/annual.html.twig', array(
  1416.             "headerFontSize" => $headerFontSize,
  1417.             "lineHeight" => $lineHeight,
  1418.             "copyright" => $copyright,
  1419.             "reverse" => $reverse,
  1420.             'year' => $year,
  1421.             'data' => $dataYear,
  1422.             'room' => $classroom,
  1423.             'students' => $studentEnrolled,
  1424.             'abscences' => $absencesArray,
  1425.             'ranks' => $rankArray,
  1426.             'means' => $annualAvgArray,
  1427.             'genMean' => $sumAvg sizeof($annualAvgArray),
  1428.             'fileExists'=> $fileExists
  1429.         ));
  1430.         return new Response(
  1431.             $this->snappy->getOutputFromHtml($html,  [
  1432.                 'page-size' => 'A4',
  1433.                
  1434.             ]),
  1435.             200,
  1436.             array(
  1437.                 'Content-Type' => 'application/pdf',
  1438.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $classroom->getName() . '.pdf"',
  1439.             )
  1440.         );
  1441.     }
  1442.     /**
  1443.      * Finds and displays a ClassRoom entity.
  1444.      *
  1445.      * @Route("/{id}/recapitulatiftrim", name="admin_classrooms_recapitulatif_trim", requirements={"id"="\d+"})
  1446.      * @Method("GET")
  1447.      * @Template()
  1448.      */
  1449.     public function recapTrimAction(ClassRoom $room)
  1450.     {
  1451.         set_time_limit(600);
  1452.         $em $this->getDoctrine()->getManager();
  1453.         $year $this->schoolYearService->sessionYearById();
  1454.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  1455.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  1456.         $studentEnrolled $this->stdRepo->findEnrolledStudentsThisYear($room$year->getId());
  1457.         $data1 $this->markRepo->findMarksBySequenceAndClassOrderByStd($sequences[0], $room);
  1458.         $data1 $this->doubleEntry($data1$room);
  1459.         $data2 $this->markRepo->findMarksBySequenceAndClassOrderByStd($sequences[1], $room);
  1460.         $data2 $this->doubleEntry($data2$room);
  1461.         $datas null;
  1462.         foreach ($data1 as $students) {
  1463.             foreach ($students as $m) {
  1464.                 $n = new Mark();
  1465.                 $n->setStudent($m->getStudent());
  1466.                 $n->setRank($m->getEvaluation()->getCourse()->getCoefficient());
  1467.                 $n->setAppreciation($m->getEvaluation()->getCourse()->getWording());
  1468.                 $n->setValue($this->average($data1[$m->getStudent()->getMatricule()][$m->getEvaluation()->getCourse()->getId()], $data2[$m->getStudent()->getMatricule()][$m->getEvaluation()->getCourse()->getId()]));
  1469.                 $w $data1[$m->getStudent()->getMatricule()][$m->getEvaluation()->getCourse()->getId()]->getWeight() + $data2[$m->getStudent()->getMatricule()][$m->getEvaluation()->getCourse()->getId()]->getWeight();
  1470.                 if ($w != 0)
  1471.                     $n->setWeight($w);
  1472.                 else
  1473.                     $n->setWeight(0);
  1474.                 $datas[$m->getStudent()->getMatricule()][$m->getEvaluation()->getCourse()->getWording()] = $n;
  1475.             }
  1476.         }
  1477.         $this->get('knp_snappy.pdf')->setTimeout(600);
  1478.         //     if($classroom->getApc()){
  1479.         $html $this->renderView('classroom/recapitulatiftrimWithMoy.html.twig', array(
  1480.             'year' => $year,
  1481.             'datas' => $datas,
  1482.             'room' => $room,
  1483.             'quater' => $quater,
  1484.             'students' => $studentEnrolled
  1485.         ));
  1486.         return new Response($html);
  1487.     }
  1488.     public function officialExam()
  1489.     {
  1490.         // Retrieve student categories from the corresponding repository
  1491.         $categoriesStudent $this->getDoctrine()->getRepository(CategStudent::class)->findAll();
  1492.         // Initialize arrays for student categories, mentions, and counters
  1493.         $studentCategories = [];
  1494.         $mentionCategories = [];
  1495.         $studentCountCategories = [];
  1496.         $mentionCountCategories = [];
  1497.         // Fill the arrays with data from student categories
  1498.         foreach ($categoriesStudent as $category) {
  1499.             $studentCategories[] = $category->getName();
  1500.             $mentionCategories[] = $category->getMention();
  1501.             $studentCountCategories[] = $category->getCountStudent();
  1502.             $mentionCountCategories[] = $category->getCountMention();
  1503.         }
  1504.         // Render the Twig template and pass the data in JSON format
  1505.         return $this->render('admin/class_room/show.html.twig', [
  1506.             'studentCategories' => json_encode($studentCategories),
  1507.             'mentionCategories' => json_encode($mentionCategories),
  1508.             'studentCountCategories' => json_encode($studentCountCategories),
  1509.             'mentionCountCategories' => json_encode($mentionCountCategories),
  1510.         ]);
  1511.     }
  1512.         /**
  1513.      * @Route("/classroom/insolvents", name="admin_classroom_insolvents")
  1514.      */
  1515.     public function listInsolventStudents(): Response
  1516.     {
  1517.         $year $this->schoolYearService->sessionYearById();
  1518.         $paymentPlan =  $year->getPaymentPlan();
  1519.         // List of student subscriptions for the class
  1520.         $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year), array("classRoom"=>"ASC"));
  1521.         $insolventSub = [];
  1522.      
  1523.         foreach($subscriptions as $sub){
  1524.             if($year->paymentThresholdAmount($sub->getClassRoom()) > $sub->getStudent()->getPaymentsSum($year) ){
  1525.                 $insolventSub[]  = $sub;
  1526.             }
  1527.         }
  1528.          $html $this->render('school_year/templating/insolvent_students_list.html.twig', [
  1529.             
  1530.             'students' => $insolventSub,
  1531.             'year' => $year,
  1532.         ]);
  1533.         return new Response(
  1534.             $this->pdf->getOutputFromHtml($html),
  1535.             200,
  1536.             array(
  1537.                 'Content-Type'          => 'application/pdf',
  1538.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $year->getCode() . '.pdf"'
  1539.             )
  1540.         );
  1541.     }
  1542.     /**
  1543.      * @Route("/classroom/{id}", name="class_room_stats")
  1544.      */
  1545.     public function showClassRoomStats(ClassRoomRepository $classRoomRepositoryClassRoom $room): Response
  1546.     {
  1547.         $classRoom $classRoomRepository->find($id);
  1548.         $successfulCount $classRoomRepository->countSuccessfulStudentsForClass($classRoom);
  1549.         $unsuccessfulCount $classRoomRepository->countUnsuccessfulStudentsForClass($classRoom);
  1550.         $mentionStatistics $classRoomRepository->getMentionStatisticsForClass($classRoom);
  1551.         return $this->render('class_room/stats.html.twig', [
  1552.             'classRoom' => $classRoom,
  1553.             'successfulCount' => $successfulCount,
  1554.             'unsuccessfulCount' => $unsuccessfulCount,
  1555.             'mentionStatistics' => $mentionStatistics,
  1556.         ]);
  1557.     }
  1558.       /**
  1559.      * @Route("/classroom/{id}/insolvent", name="admin_classroom_insolvent")
  1560.      */
  1561.     public function listInsolventStudentsByRoom(ClassRoom $room): Response
  1562.     {
  1563.         $year $this->schoolYearService->sessionYearById();
  1564.         $paymentPlan =  $year->getPaymentPlan();
  1565.         // List of student subscriptions for the class
  1566.         $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year"classRoom" => $room));
  1567.         $students = [];
  1568.         $dueAmounts = [];
  1569.         foreach($subscriptions as $sub){
  1570.             if($year->paymentThresholdAmount($room) > $sub->getStudent()->getPaymentsSum($year) ){
  1571.                 $students[] = $sub->getStudent() ;
  1572.                 $dueAmounts[$sub->getStudent()->getId()] = $year->paymentThresholdAmount($room)-$sub->getStudent()->getPaymentsSum($year);
  1573.             }
  1574.         }
  1575.         $html $this->render('classroom/templating/insolvent_student_list.html.twig', [
  1576.             'room' => $room,
  1577.             'students' => $students,
  1578.             'year' => $year,
  1579.             'amounts' =>  $dueAmounts 
  1580.         ]);
  1581.         return new Response(
  1582.             $this->pdf->getOutputFromHtml($html),
  1583.             200,
  1584.             array(
  1585.                 'Content-Type'          => 'application/pdf',
  1586.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $room->getName() . '.pdf"'
  1587.             )
  1588.         );
  1589.     }
  1590.      /**
  1591.      * @Route("/insolventspercentage", name="admin_classroom_insolvents_percentage")
  1592.      */
  1593.     public function insolventStudentsRate(): Response
  1594.     {
  1595.         $year $this->schoolYearService->sessionYearById();
  1596.         $paymentPlan =  $year->getPaymentPlan();
  1597.         $rooms $this->repo->findAll();
  1598.         $rates = [];
  1599.         
  1600.         foreach($rooms as $room){
  1601.             $subscriptions $this->subRepo->findBy(array("schoolYear" =>  $year"classRoom" =>  $room));
  1602.             $installments $this->instRepo->findBy(array("classRoom" =>  $room"paymentPlan" =>  $paymentPlan));
  1603.             $sum 0;
  1604.             foreach($installments as $installment){
  1605.                 $sum += $installment->getAmount();
  1606.             }
  1607.             $ratesByRoom = [];
  1608.             foreach($subscriptions as $sub){
  1609.                  $ratesByRoom[]  = 100*$sub->getStudent()->getPaymentsSum($year) / $sum;
  1610.             }
  1611.               // Calculer la somme des valeurs entières
  1612.             $sum array_sum($ratesByRoom);
  1613.             // Calculer la moyenne
  1614.             $avg count($ratesByRoom) > $sum count($ratesByRoom) : 0;
  1615.             $rates[$room->getName()] = $avg ;
  1616.         }
  1617.         $html $this->render('school_year/templating/recovery_rates_by_room.html.twig', [
  1618.             
  1619.             'rates' => $rates,
  1620.             'year' => $year,
  1621.         ]);
  1622.         return new Response(
  1623.             $this->pdf->getOutputFromHtml($html),
  1624.             200,
  1625.             array(
  1626.                 'Content-Type'          => 'application/pdf',
  1627.                 'Content-Disposition'   => 'inline; filename="insolvent_student_' $year->getCode() . '.pdf"'
  1628.             )
  1629.         );
  1630.     }
  1631.    
  1632.  
  1633. }