src/Controller/StudentController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Student;
  4. use App\Entity\Subscription;
  5. use App\Entity\ClassRoom;
  6. use App\Form\StudentType;
  7. use App\Repository\StudentRepository;
  8. use App\Repository\EvaluationRepository;
  9. use App\Repository\SequenceRepository;
  10. use App\Repository\MarkRepository;
  11. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  12. use Knp\Snappy\Pdf;
  13. use App\Repository\SchoolYearRepository;
  14. use App\Repository\SubscriptionRepository;
  15. use App\Repository\PaymentRepository;
  16. use App\Repository\QuaterRepository;
  17. use App\Repository\InstallmentRepository;
  18. use App\Repository\PaymentPlanRepository;
  19. use App\Repository\MainTeacherRepository;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  28. use App\Service\SchoolYearService;
  29. /**
  30.  * Studentme controller.
  31.  *
  32.  * @Route("/prof/students")
  33.  */
  34. class StudentController extends AbstractController
  35. {
  36.     private EntityManagerInterface $em;
  37.     private $repo;
  38.     private $scRepo;
  39.     private $seqRepo;
  40.     private SubscriptionRepository $subRepo;
  41.     private $markRepo;
  42.     private $evalRepo;
  43.     private $qtRepo;
  44.     private  $snappy;
  45.     private SchoolYearService      $schoolYearService;
  46.     private PaymentPlanRepository $ppRepo;
  47.     private InstallmentRepository $instRepo;
  48.     private PaymentRepository $pRepo;
  49.     private MainTeacherRepository $mainTeacherRepo;
  50.     public function __construct(PaymentRepository $pRepoInstallmentRepository $instRepoPaymentPlanRepository $ppRepo,SchoolYearService $schoolYearService,EntityManagerInterface $emSubscriptionRepository $subRepoMarkRepository $markRepoEvaluationRepository $evalRepoStudentRepository $repoSequenceRepository $seqRepoSchoolYearRepository $scRepoQuaterRepository $qtRepo,MainTeacherRepository $mainTeacherRepoPdf $snappy)
  51.     {
  52.         $this->em       $em;
  53.         $this->repo     $repo;
  54.         $this->scRepo   $scRepo;
  55.         $this->markRepo $markRepo;
  56.         $this->seqRepo  $seqRepo;
  57.         $this->evalRepo $evalRepo;
  58.         $this->subRepo  $subRepo;
  59.         $this->qtRepo   $qtRepo;
  60.         $this->snappy   $snappy;
  61.         $this->ppRepo   $ppRepo;
  62.         $this->pRepo    $pRepo;
  63.         $this->instRepo $instRepo;
  64.         $this->mainTeacherRepo $mainTeacherRepo;
  65.         $this->schoolYearService $schoolYearService;
  66.     }
  67.       /**
  68.      * @Route("/create",name= "admin_students_new", methods={"GET","POST"})
  69.      */
  70.     public function create(Request $request): Response
  71.     {
  72.         if (!$this->getUser()) {
  73.             $this->addFlash('warning''You need login first!');
  74.             return $this->redirectToRoute('app_login');
  75.         }
  76.         if (!$this->getUser()->isVerified()) {
  77.             $this->addFlash('warning''You need to have a verified account!');
  78.             return $this->redirectToRoute('app_login');
  79.         }
  80.         $student = new Student();
  81.         $form $this->createForm(StudentType::class, $student);
  82.         $numero $this->repo->getNumeroDispo();
  83.         $student->setMatricule($numero);
  84.         $form->handleRequest($request);
  85.         if ($form->isSubmitted() && $form->isValid()) {
  86.             if($student->getEntryClass()!=NULL){
  87.                 $sub = new Subscription();
  88.                 $sub->setStudent($student);
  89.                 $sub->setClassRoom($student->getEntryClass());
  90.                 $sub->setSchoolYear($this->schoolYearService->sessionYearById());
  91.                 $this->em->persist($sub);
  92.             }
  93.             $this->em->persist($student);
  94.             $this->em->flush();
  95.             $this->addFlash('success''Student succesfully created');
  96.             return $this->redirectToRoute('admin_students', [
  97.                 'type' =>"new_students_not_yet_registered_checkbox",
  98.             ]);
  99.         }
  100.         return $this->render(
  101.             'student/new.html.twig',
  102.             ['form' => $form->createView()]
  103.         );
  104.     }
  105.     /**
  106.      * Lists all Studentme entities.
  107.      *
  108.      * @Route("/{type}", name="admin_students")
  109.      * @Method("GET")
  110.      * @Template()
  111.      */
  112.     public function indexAction($type)
  113.     {
  114.         if (!$this->getUser()) {
  115.             $this->addFlash('warning''You need login first!');
  116.             return $this->redirectToRoute('app_login');
  117.         }
  118.         if (!$this->getUser()->isVerified()) {
  119.             $this->addFlash('warning''You need to have a verified account!');
  120.             return $this->redirectToRoute('app_login');
  121.         }
  122.         $year $this->schoolYearService->sessionYearById();
  123.        
  124.        
  125.         switch ($type) {
  126.             case "new_students_not_yet_registered_checkbox":
  127.                 $students $this->repo->findNewStudents($year);
  128.                 break;
  129.             case "new_registered_students_checkbox":
  130.                 $students =  $this->repo->findNewRegisteredStudents($year);
  131.                 break;
  132.             case "registered_former_students_checkbox":
  133.                 $students =  $this->repo->findFormerRegisteredStudents($year);
  134.                 break;
  135.             case "complete_registered_students_checkbox":
  136.                     $students =  $this->repo->findEnrolledStudentsThisYear2($year);
  137.                 break;
  138.             default:
  139.                 $students $this->repo->findEnrolledStudentsThisYear2();
  140.                 break;
  141.         }
  142.         
  143.         return $this->render('student/list.html.twig'compact("students"));
  144.     }
  145.    /**
  146.      * @Route("/{id}/unregister/{room_id}", name="admin_students_unregister", requirements={"id"="\d+", "room_id"="\d+"})
  147.      * @ParamConverter("std", options={"mapping": {"id": "id"}})
  148.      * @ParamConverter("room", options={"mapping": {"room_id": "id"}})
  149.      */
  150.     public function unregisterAction(Student $stdClassRoom $room)
  151.     {
  152.         if (!$this->getUser()) {
  153.             $this->addFlash('warning''You need login first!');
  154.             return $this->redirectToRoute('app_login');
  155.         }
  156.         if (!$this->getUser()->isVerified()) {
  157.             $this->addFlash('warning''You need to have a verified account!');
  158.             return $this->redirectToRoute('app_login');
  159.         }
  160.         $year $this->schoolYearService->sessionYearById();
  161.         $sub $this->subRepo->findOneBy(array("student"=>$std"classRoom"=>$room"schoolYear"=>$year));
  162.         $this->em->remove($sub);
  163.         $this->em->flush();
  164.         return $this->redirectToRoute('admin_classrooms_show', ["id"=>$room->getId()]);
  165.     }
  166.     /**
  167.      * Finds and displays a Studentme entity.
  168.      *
  169.      * @Route("/{id}/show", name="admin_students_show", requirements={"id"="\d+"})
  170.      * @Method("GET")
  171.      * @Template()
  172.      */
  173.     public function showAction(Student $student)
  174.     {
  175.         // AnnĂ©e scolaire, seuquence, inscrption de l'eleve pour l'annee en cours
  176.         if (!$this->getUser()) {
  177.             $this->addFlash('warning''You need login first!');
  178.             return $this->redirectToRoute('app_login');
  179.         }
  180.         if (!$this->getUser()->isVerified()) {
  181.             $this->addFlash('warning''You need to have a verified account!');
  182.             return $this->redirectToRoute('app_login');
  183.         }
  184.         $year $this->schoolYearService->sessionYearById();
  185.         $seq $this->seqRepo->findOneBy(array("activated" => true));
  186.         
  187.         $sub $this->subRepo->findOneBy(array("student" => $student"schoolYear" => $year));
  188.         $results['student'] = $student;
  189.         $results['cours'] = null;
  190.         $results['session1'] = null;
  191.         $results['session2'] = null;
  192.         $results['session3'] = null;
  193.         $results['session4'] = null;
  194.         $results['session5'] = null;
  195.         $results['session6'] = null;
  196.         $evals = [];
  197.         $evalSeqs = [];
  198.         $payments $this->pRepo->findBy(array( "schoolYear"=> $year"student"=> $student), array('updatedAt' => 'ASC'));
  199.         $paymentPlan $this->ppRepo->findOneBy(array( "schoolYear"=> $year));
  200.         if($sub!=null){
  201.             $installments $this->instRepo->findBy(array( "paymentPlan"=> $paymentPlan"classRoom"=> $sub->getClassRoom()));
  202.         } else {
  203.             $installments $this->instRepo->findBy(array( "paymentPlan"=> $paymentPlan));
  204.         }
  205.         $seqs $this->seqRepo->findSequenceThisYear($year);
  206.         if ($sub != null) {
  207.             foreach ($seqs as $seq) {
  208.                 $evalSeqs[$seq->getId()] = $this->evalRepo->findBy(array("classRoom" => $sub->getClassRoom(), "sequence" => $seq));
  209.             }
  210.             $courses = [];
  211.             $averageSeqs = [];
  212.             // Traitements de donnees pour les graphes
  213.             foreach ($evalSeqs[$seq->getId()] as $eval) {
  214.                 $courses[] = $eval->getCourse()->getWording();
  215.             }
  216.             foreach ($seqs as $seq) {
  217.                 $average = [];
  218.                 foreach ($evalSeqs[$seq->getId()]  as $eval) {
  219.                     if ($this->markRepo->findOneBy(array("student" => $student"evaluation" => $eval)))
  220.                         $average[] = $this->markRepo->findOneBy(array("student" => $student"evaluation" => $eval))->getValue();
  221.                 }
  222.                 $averageSeqs[$seq->getId()] = $average;
  223.             }
  224.             $filename "assets/images/student/" $student->getMatricule() . ".jpg";
  225.             $file_exists file_exists($filename);
  226.             $results['payments'] = $payments;
  227.             $results['payment_plan'] = $paymentPlan;
  228.             $results['installments'] = $installments;
  229.             $results['sub'] = $sub;
  230.             $results['file_exists'] = $file_exists;
  231.             $results['cours'] = json_encode($courses);
  232.             
  233.             foreach ($seqs as $seq) {
  234.                 $results[strtolower($seq->getWording())] = json_encode($averageSeqs[$seq->getId()]);
  235.             }
  236.         }
  237.         return $this->render('student/show.html.twig'$results);
  238.     }
  239.   
  240.     /**
  241.      * Displays a form to edit an existing Studentme entity.
  242.      *
  243.      * @Route("/{id}/edit", name="admin_students_edit", requirements={"id"="\d+"}, methods={"GET","PUT"})
  244.      * @Template()
  245.      */
  246.     public function edit(Request $requestStudent $student): Response
  247.     {
  248.         if (!$this->getUser()) {
  249.             $this->addFlash('warning''You need login first!');
  250.             return $this->redirectToRoute('app_login');
  251.         }
  252.         if (!$this->getUser()->isVerified()) {
  253.             $this->addFlash('warning''You need to have a verified account!');
  254.             return $this->redirectToRoute('app_login');
  255.         }
  256.         $form $this->createForm(StudentType::class, $student, [
  257.             'method' => 'PUT'
  258.         ]);
  259.         $form->handleRequest($request);
  260.         if ($form->isSubmitted() && $form->isValid()) {
  261.             $this->em->flush();
  262.             $this->addFlash('success''Student succesfully updated');
  263.             //return $this->redirectToRoute('admin_students_show', ['id' => $student->getId()]);
  264.             /*return $this->redirectToRoute('admin_students', [
  265.                 'type' =>"new_students_not_yet_registered_checkbox",
  266.             ]);*/
  267.             $year $this->schoolYearService->sessionYearById();
  268.             $sub $this->subRepo->findOneBy(array("student"=>$student,"schoolYear"=>$year));
  269.             return $this->redirectToRoute('admin_classrooms_show', ["id"=>$sub->getClassRoom()->getId()]);
  270.         }
  271.         return $this->render('student/edit.html.twig', [
  272.             'student' => $student,
  273.             'form' => $form->createView()
  274.         ]);
  275.     }
  276.     /**
  277.      * Deletes a Studentme entity.
  278.      *
  279.      * @Route("/{id}/delete", name="admin_students_delete", requirements={"id"="\d+"}, methods={"DELETE"})
  280.      */
  281.     public function delete(Student $studentRequest $request): Response
  282.     {
  283.         if (!$this->getUser()) {
  284.             $this->addFlash('warning''You need login first!');
  285.             return $this->redirectToRoute('app_login');
  286.         }
  287.         if (!$this->getUser()->isVerified()) {
  288.             $this->addFlash('warning''You need to have a verified account!');
  289.             return $this->redirectToRoute('app_login');
  290.         }
  291.         if ($this->isCsrfTokenValid('students_deletion' $student->getId(), $request->request->get('csrf_token'))) {
  292.             $this->em->remove($student);
  293.             $this->em->flush();
  294.             $this->addFlash('info''Student succesfully deleted');
  295.         }
  296.         return $this->redirectToRoute('admin_students', [
  297.             'type' =>"new_students_not_yet_registered_checkbox",
  298.         ]);
  299.     }
  300.     /**
  301.      * Build student's school certificate
  302.      *
  303.      * @Route("/{id}/certificate", name="admin_student_certificate", requirements={"id"="\d+"})
  304.      */
  305.     public function schoolCertificate(Pdf $pdfStudent $std): Response
  306.     {
  307.         if (!$this->getUser()) {
  308.             $this->addFlash('warning''You need login first!');
  309.             return $this->redirectToRoute('app_login');
  310.         }
  311.         if (!$this->getUser()->isVerified()) {
  312.             $this->addFlash('warning''You need to have a verified account!');
  313.             return $this->redirectToRoute('app_login');
  314.         }
  315.         $year $this->schoolYearService->sessionYearById();
  316.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  317.         $html $this->renderView('student/school_certificate.html.twig', array(
  318.             'year' => $year,
  319.             'std'  => $std,
  320.             'sub' => $sub
  321.         ));
  322.         return new Response(
  323.             $pdf->getOutputFromHtml($html),
  324.             200,
  325.             array(
  326.                 'Content-Type'          => 'application/pdf',
  327.                 'Content-Disposition'   => 'inline; filename="certif_'.$std->getMatricule()  . '.pdf"'
  328.             )
  329.         );
  330.     }
  331.      /**
  332.      * Build student's school certificate
  333.      *
  334.      * @Route("/{id}/receipt", name="admin_student_receipt", requirements={"id"="\d+"})
  335.      */
  336.     public function tuitionReceiptAction(Pdf $pdfStudent $std): Response
  337.     {
  338.         if (!$this->getUser()) {
  339.             $this->addFlash('warning''You need login first!');
  340.             return $this->redirectToRoute('app_login');
  341.         }
  342.         if (!$this->getUser()->isVerified()) {
  343.             $this->addFlash('warning''You need to have a verified account!');
  344.             return $this->redirectToRoute('app_login');
  345.         }
  346.         $year $this->schoolYearService->sessionYearById();
  347.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  348.         $payments $this->pRepo->findBy(array( "schoolYear"=> $year"student"=> $std), array('updatedAt' => 'DESC'));
  349.         $paymentPlan $this->ppRepo->findOneBy(array( "schoolYear"=> $year));
  350.         $installments $this->instRepo->findBy(array( "paymentPlan"=> $paymentPlan"classRoom"=> $sub->getClassRoom()));
  351.         $html $this->renderView('student/tuition_receipt.html.twig', array(
  352.             'year' => $year,
  353.             'std'  => $std,
  354.             'sub' => $sub,
  355.             'payments' => $payments,
  356.             'payment_plan' => $paymentPlan,
  357.             'installments' => $installments
  358.         ));
  359.         return new Response(
  360.             $pdf->getOutputFromHtml($html),
  361.             200,
  362.             array(
  363.                 'Content-Type'          => 'application/pdf',
  364.                 'Content-Disposition'   => 'inline; filename="recu_'.$std->getMatricule()  . '.pdf"'
  365.             )
  366.         );
  367.     }
  368.     /**
  369.      * Build student's school certificate
  370.      *
  371.      * @Route("/{id}/badge", name="admin_student_badge", requirements={"id"="\d+"})
  372.      */
  373.     public function schoolBadge(Pdf $pdfStudent $std): Response
  374.     {
  375.         if (!$this->getUser()) {
  376.             $this->addFlash('warning''You need login first!');
  377.             return $this->redirectToRoute('app_login');
  378.         }
  379.         if (!$this->getUser()->isVerified()) {
  380.             $this->addFlash('warning''You need to have a verified account!');
  381.             return $this->redirectToRoute('app_login');
  382.         }
  383.         $year $this->schoolYearService->sessionYearById();
  384.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  385.         $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  386.         $fileExist file_exists($filename);
  387.         $html $this->renderView('student/badge.html.twig', array(
  388.             'sub' => $sub,
  389.             'fileExist' => $fileExist
  390.         ));
  391.         return new Response(
  392.             $pdf->getOutputFromHtml($html),
  393.             200,
  394.             array(
  395.                 'Content-Type'          => 'application/pdf',
  396.                 'Content-Disposition'   => 'inline; filename="badge_'.$std->getMatricule()  . '.pdf"'
  397.             )
  398.         );
  399.     }
  400.      /**
  401.      * Finds and displays a ClassRoom entity.
  402.      *
  403.      * @Route("/{id}/reportCardTrim2024", name="admin_students_reportcards_quat_2024", requirements={"id"="\d+"})
  404.      * @Method("GET")
  405.      * @Template()
  406.      */
  407.     public function reporCardTrimAction2024(Pdf $pdfStudent $std){
  408.         if (!$this->getUser()) {
  409.             $this->addFlash('warning''You need login first!');
  410.             return $this->redirectToRoute('app_login');
  411.         }
  412.         if (!$this->getUser()->isVerified()) {
  413.             $this->addFlash('warning''You need to have a verified account!');
  414.             return $this->redirectToRoute('app_login');
  415.         }
  416.         $connection $this->em->getConnection();
  417.         $year $this->schoolYearService->sessionYearById();
  418.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  419.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  420.         $students $this->repo->findEnrolledStudentsThisYearInClass($sub->getClassRoom(), $year);
  421.         $mainTeacher $this->mainTeacherRepo->findOneBy(array("classRoom" => $sub->getClassRoom(), "schoolYear" => $year))-> getTeacher();
  422.         $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  423.         $fileExist file_exists($filename);
  424.         $query =  "  SELECT DISTINCT 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
  425.         FROM sequence 
  426.         JOIN evaluation ON evaluation.sequence_id = sequence.id
  427.         JOIN course ON evaluation.course_id = course.id
  428.         JOIN attribution on attribution.course_id = course.id
  429.         JOIN user ON user.id = attribution.teacher_id
  430.         JOIN mark ON evaluation.id = mark.evaluation_id
  431.         JOIN quater ON sequence.quater_id = quater.id
  432.         JOIN school_year on quater.school_year_id= school_year.id and school_year.id = attribution.year_id
  433.         WHERE quater.id = :quater_id AND   mark.student_id=:student_id
  434.         ORDER BY course.id,sequence.id; ";
  435.         $params = [
  436.             'quater_id' => $quater->getId(),       
  437.             'student_id' => $std->getId(), // Remplace :city
  438.         ];
  439.         $result $connection->executeQuery($query$params);
  440.         $data $result->fetchAllAssociative();
  441.         $html $this->renderView('student/reportcard/quaterly_2024.html.twig', array(
  442.             'year' => $year,
  443.             'quater' => $quater,
  444.             'mainTeacher'=>$mainTeacher,
  445.             'data' => $data,
  446.             'std'  => $std,
  447.             'students' => $students,
  448.             'room' => $sub->getClassRoom(),
  449.             'fileExist' => $fileExist
  450.         ));
  451.         return new Response(
  452.             $pdf->getOutputFromHtml($html),
  453.             200,
  454.             array(
  455.                 'Content-Type'          => 'application/pdf',
  456.                 'Content-Disposition'   => 'inline; filename="bull_' .  $quater->getId().'_'.$std->getMatricule()  . '.pdf"'
  457.             )
  458.         );
  459.     }
  460.     /**
  461.      * Finds and displays a ClassRoom entity.
  462.      *
  463.      * @Route("/{id}/reportCardTrim", name="admin_students_reportcards_quat", requirements={"id"="\d+"})
  464.      * @Method("GET")
  465.      * @Template()
  466.      */
  467.     public function reporCardTrimAction(Pdf $pdfStudent $std)
  468.     {
  469.         if (!$this->getUser()) {
  470.             $this->addFlash('warning''You need login first!');
  471.             return $this->redirectToRoute('app_login');
  472.         }
  473.         if (!$this->getUser()->isVerified()) {
  474.             $this->addFlash('warning''You need to have a verified account!');
  475.             return $this->redirectToRoute('app_login');
  476.         }
  477.         $connection $this->em->getConnection();
  478.         $year $this->schoolYearService->sessionYearById();
  479.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  480.         $quater $this->qtRepo->findOneBy(array("activated" => true));
  481.         $sequences $this->seqRepo->findBy(array("quater" => $quater));
  482.         $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  483.         $fileExist file_exists($filename);
  484.         
  485.         $i 1;
  486.         foreach ($sequences as $seq) {
  487.             /*******************************************************************************************************************/
  488.             /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE L'ELEVE**************/
  489.             /*******************************************************************************************************************/
  490.             // CAS DES NOTES SEQUENTIELLES
  491.             $statement $connection->prepare(
  492.                 "  CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  493.                     SELECT DISTINCT  eval.id as eval,crs.id as crs, room.id as room,  teach.full_name as teacher    , modu.id as module,m.value as value, m.weight as weight
  494.                     FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  495.                     JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  496.                     JOIN  class_room room    ON   eval.class_room_id     =   room.id
  497.                     JOIN  course     crs     ON  eval.course_id      =   crs.id
  498.                     JOIN  attribution att    ON  att.course_id      =   crs.id
  499.                     JOIN  user  teach ON  att.teacher_id  =   teach.id
  500.                     JOIN  module     modu    ON  modu.id       =   crs.module_id
  501.                     JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  502.                     WHERE   std.id = ?  AND eval.sequence_id =?
  503.                     ORDER BY crs.id; "
  504.             );
  505.             $statement->bindValue(1$std->getId());
  506.             $statement->bindValue(2$seq->getId());
  507.             $statement->execute();
  508.             $i++;
  509.         }
  510.         $statement $connection->prepare(
  511.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  512.             SELECT DISTINCT    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.weight as weight1,seq2.weight as weight2, seq1.value as value1,seq2.value as value2,   seq1.teacher as teacher, seq1.module as   module, seq1.room as room
  513.             FROM V_STUDENT_MARK_SEQ1 seq1
  514.             JOIN  V_STUDENT_MARK_SEQ2 seq2  
  515.             ON  (seq1.crs = seq2.crs)
  516.             ORDER BY seq1.crs"
  517.         );
  518.         $statement->execute();
  519.         
  520.        
  521.         
  522.         $dataQuater $connection->executeQuery("SELECT *  FROM V_STUDENT_MARK_QUATER ")->fetchAll();
  523.         $html $this->renderView('student/reportcardTrimApc.html.twig', array(
  524.             'year' => $year,
  525.             'quater' => $quater,
  526.             'data' => $dataQuater,
  527.             'sequences' => $sequences,
  528.             'std'  => $std,
  529.             'room' => $sub->getClassRoom(),
  530.             'fileExist' => $fileExist
  531.         ));
  532.         return new Response(
  533.             $pdf->getOutputFromHtml($html),
  534.             200,
  535.             array(
  536.                 'Content-Type'          => 'application/pdf',
  537.                 'Content-Disposition'   => 'inline; filename="bull_' .  $quater->getId().'_'.$std->getMatricule()  . '.pdf"'
  538.             )
  539.         );
  540.     }
  541.     /**
  542.      * Finds and displays a ClassRoom entity.
  543.      *
  544.      * @Route("/{id}/reportCardYear", name="admin_students_reportcards_year", requirements={"id"="\d+"})
  545.      * @Method("GET")
  546.      * @Template()
  547.      */
  548.     public function reporCardYear(Student $std)
  549.     {
  550.         if (!$this->getUser()) {
  551.             $this->addFlash('warning''You need login first!');
  552.             return $this->redirectToRoute('app_login');
  553.         }
  554.         if (!$this->getUser()->isVerified()) {
  555.             $this->addFlash('warning''You need to have a verified account!');
  556.             return $this->redirectToRoute('app_login');
  557.         }
  558.         $connection $this->em->getConnection();
  559.         $year $this->schoolYearService->sessionYearById();
  560.         $sequences $this->seqRepo->findSequenceThisYear($year);
  561.         $sub $this->subRepo->findOneBy(array("student" => $std"schoolYear" => $year));
  562.         $filename "assets/images/student/" $std->getMatricule() . ".jpg";
  563.         $fileExist file_exists($filename);
  564.         $i 1;
  565.         foreach ($sequences as $seq) {
  566.             /*******************************************************************************************************************/
  567.             /***************CREATION DE la VIEW DES NOTES  SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE L'ELEVE**************/
  568.             /*******************************************************************************************************************/
  569.             // CAS DES NOTES SEQUENTIELLES
  570.             $statement $connection->prepare(
  571.                 "  CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" $i " AS
  572.                     SELECT DISTINCT  eval.id as eval,crs.id as crs, room.id as room,year.id as year,  teach.id as teacher    , modu.id as module,m.value as value, m.weight as weight
  573.                     FROM  mark  m   JOIN  student    std     ON  m.student_id        =   std.id
  574.                     JOIN  evaluation eval    ON  m.evaluation_id     =   eval.id
  575.                     JOIN  class_room room    ON   eval.class_room_id     =   room.id
  576.                     JOIN  course     crs     ON  eval.course_id      =   crs.id
  577.                     JOIN  attribution att    ON  att.course_id      =   crs.id
  578.                     JOIN  user  teach ON  att.teacher_id  =   teach.id
  579.                     JOIN  module     modu    ON  modu.id       =   crs.module_id
  580.                     JOIN  sequence   seq     ON  seq.id     =   eval.sequence_id
  581.                     JOIN  quater   quat     ON  seq.quater_id     =   quat.id
  582.                     JOIN  school_year   year ON  quat.school_year_id     =   year.id
  583.                     WHERE   std.id = ? AND  room.id = ? AND eval.sequence_id =?
  584.                     ORDER BY crs.id; "
  585.             );
  586.             $statement->bindValue(1$std->getId());
  587.             $statement->bindValue(2$sub->getClassRoom()->getId());
  588.             $statement->bindValue(3$seq->getId());
  589.             $statement->execute();
  590.             $i++;
  591.         }
  592.         // CAS DES NOTES TRIMESTRIELLES
  593.         $statement $connection->prepare(
  594.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER1 AS
  595.             SELECT DISTINCT    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
  596.             FROM V_STUDENT_MARK_SEQ1 seq1
  597.             JOIN  V_STUDENT_MARK_SEQ2 seq2  
  598.             ON  (seq1.crs = seq2.crs)
  599.             ORDER BY seq1.crs"
  600.         );
  601.         $statement->execute();
  602.         $statement $connection->prepare(
  603.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER2 AS
  604.             SELECT DISTINCT    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
  605.             FROM V_STUDENT_MARK_SEQ3 seq1
  606.             JOIN  V_STUDENT_MARK_SEQ4 seq2  
  607.             ON  (seq1.crs = seq2.crs)
  608.             ORDER BY seq1.crs"
  609.         );
  610.         $statement->execute();
  611.         $statement $connection->prepare(
  612.             "  CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER3 AS
  613.             SELECT DISTINCT    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
  614.             FROM V_STUDENT_MARK_SEQ5 seq1
  615.             JOIN  V_STUDENT_MARK_SEQ6 seq2  
  616.             ON  (seq1.crs = seq2.crs)
  617.             ORDER BY seq1.crs"
  618.         );
  619.         $statement->execute();
  620.        // dd($dataYear);
  621.         // CAS DES NOTES ANNUELLES
  622.         $statement $connection->prepare(
  623.             "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  624.             SELECT DISTINCT 
  625.             course.wording as course, course.coefficient as coef, 
  626.             module.name as module,
  627.             user.full_name as teacher,
  628.             quat1.value as value1, quat1.weight as weight1,  
  629.             quat2.value as value2,  quat2.weight as weight2,  
  630.             quat3.value as value3,quat3.weight as weight3,
  631.             ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  632.              
  633.             FROM V_STUDENT_MARK_QUATER1  quat1 
  634.             JOIN  class_room ON class_room.id = quat1.room
  635.             JOIN  course    ON course.id = quat1.crs
  636.             JOIN  module    ON course.module_id = quat1.modu
  637.             JOIN user ON user.id = quat1.teacher
  638.             JOIN   V_STUDENT_MARK_QUATER2   quat2  ON   quat1.crs = quat2.crs
  639.             JOIN 
  640.             V_STUDENT_MARK_QUATER3   quat3  ON  quat2.crs = quat3.crs
  641.             ORDER BY  module
  642.             "
  643.         );
  644.         $statement->execute();
  645.         $dataYear $connection->executeQuery("SELECT *  FROM ANNUAL_DATA ")->fetchAll();
  646.         
  647.         $html $this->renderView('student/reportcardYearApc.html.twig', array(
  648.             'year' => $year,
  649.             'data' => $dataYear,
  650.             'std'  => $std,
  651.             'room' => $sub->getClassRoom(),
  652.             'fileExist' => $fileExist
  653.         ));
  654.         return new Response(
  655.             $this->snappy->getOutputFromHtml($html),
  656.             200,
  657.             array(
  658.                 'Content-Type' => 'application/pdf',
  659.                 'Content-Disposition' => 'attachment; filename="BUL_ANN_' $std->getMatricule() . '.pdf"',
  660.             )
  661.         );
  662.     }
  663. }