src/Controller/StudentController.php line 193

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