src/Controller/StudentController.php line 190

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("subscription"=> $sub), 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( "subscription"=> $sub), array('updatedAt' => 'ASC'));
  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. $html = $this->renderView('student/reportcard/quaterly_2024.html.twig', array(
  440. 'year' => $year,
  441. 'quater' => $quater,
  442. 'mainTeacher'=>$mainTeacher,
  443. 'data' => $data,
  444. 'std' => $std,
  445. 'students' => $students,
  446. 'room' => $sub->getClassRoom(),
  447. "lineHeight" => 0.75*$lineHeight,
  448. "headerFontSize" => 0.75*$headerFontSize,
  449. "copyright" => $copyright,
  450. 'fileExist' => $fileExist
  451. ));
  452. return new Response(
  453. $pdf->getOutputFromHtml($html),
  454. 200,
  455. array(
  456. 'Content-Type' => 'application/pdf',
  457. 'Content-Disposition' => 'inline; filename="bull_' . $quater->getId().'_'.$std->getMatricule() . '.pdf"'
  458. )
  459. );
  460. }
  461. /**
  462. * Finds and displays a ClassRoom entity.
  463. *
  464. * @Route("/{id}/reportCardTrim", name="admin_students_reportcards_quat", requirements={"id"="\d+"})
  465. * @Method("GET")
  466. * @Template()
  467. */
  468. public function reporCardTrimAction(Pdf $pdf, Student $std)
  469. {
  470. if (!$this->getUser()) {
  471. $this->addFlash('warning', 'You need login first!');
  472. return $this->redirectToRoute('app_login');
  473. }
  474. if (!$this->getUser()->isVerified()) {
  475. $this->addFlash('warning', 'You need to have a verified account!');
  476. return $this->redirectToRoute('app_login');
  477. }
  478. $connection = $this->em->getConnection();
  479. $year = $this->schoolYearService->sessionYearById();
  480. $sub = $this->subRepo->findOneBy(array("student" => $std, "schoolYear" => $year));
  481. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  482. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  483. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  484. $fileExist = file_exists($filename);
  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. $dataQuater = $connection->executeQuery("SELECT * FROM V_STUDENT_MARK_QUATER ")->fetchAll();
  520. $html = $this->renderView('student/reportcardTrimApc.html.twig', array(
  521. 'year' => $year,
  522. 'quater' => $quater,
  523. 'data' => $dataQuater,
  524. 'sequences' => $sequences,
  525. 'std' => $std,
  526. 'room' => $sub->getClassRoom(),
  527. 'fileExist' => $fileExist
  528. ));
  529. return new Response(
  530. $pdf->getOutputFromHtml($html),
  531. 200,
  532. array(
  533. 'Content-Type' => 'application/pdf',
  534. 'Content-Disposition' => 'inline; filename="bull_' . $quater->getId().'_'.$std->getMatricule() . '.pdf"'
  535. )
  536. );
  537. }
  538. /**
  539. * Finds and displays a ClassRoom entity.
  540. *
  541. * @Route("/{id}/reportCardYear", name="admin_students_reportcards_year", requirements={"id"="\d+"})
  542. * @Method("GET")
  543. * @Template()
  544. */
  545. public function reporCardYear(Student $std, Request $request)
  546. {
  547. if (!$this->getUser()) {
  548. $this->addFlash('warning', 'You need login first!');
  549. return $this->redirectToRoute('app_login');
  550. }
  551. if (!$this->getUser()->isVerified()) {
  552. $this->addFlash('warning', 'You need to have a verified account!');
  553. return $this->redirectToRoute('app_login');
  554. }
  555. // Recuperation des parametres de presentation du bulletin
  556. $headerFontSize = $request->request->get('header_font_size');
  557. $lineHeight = $request->request->get('line_height');
  558. $copyright = $request->request->get('copyright')=="on";
  559. $connection = $this->em->getConnection();
  560. $year = $this->schoolYearService->sessionYearById();
  561. $sequences = $this->seqRepo->findSequenceThisYear($year);
  562. $sub = $this->subRepo->findOneBy(array("student" => $std, "schoolYear" => $year));
  563. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  564. $fileExist = file_exists($filename);
  565. $i = 1;
  566. foreach ($sequences as $seq) {
  567. /*******************************************************************************************************************/
  568. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE L'ELEVE**************/
  569. /*******************************************************************************************************************/
  570. // CAS DES NOTES SEQUENTIELLES
  571. $statement = $connection->prepare(
  572. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" . $i . " AS
  573. 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
  574. FROM mark m JOIN student std ON m.student_id = std.id
  575. JOIN evaluation eval ON m.evaluation_id = eval.id
  576. JOIN class_room room ON eval.class_room_id = room.id
  577. JOIN course crs ON eval.course_id = crs.id
  578. JOIN attribution att ON att.course_id = crs.id
  579. JOIN user teach ON att.teacher_id = teach.id
  580. JOIN module modu ON modu.id = crs.module_id
  581. JOIN sequence seq ON seq.id = eval.sequence_id
  582. JOIN quater quat ON seq.quater_id = quat.id
  583. JOIN school_year year ON quat.school_year_id = year.id
  584. WHERE std.id = ? AND room.id = ? AND eval.sequence_id =?
  585. ORDER BY crs.id; "
  586. );
  587. $statement->bindValue(1, $std->getId());
  588. $statement->bindValue(2, $sub->getClassRoom()->getId());
  589. $statement->bindValue(3, $seq->getId());
  590. $statement->execute();
  591. $i++;
  592. }
  593. // CAS DES NOTES TRIMESTRIELLES
  594. $statement = $connection->prepare(
  595. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER1 AS
  596. 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
  597. FROM V_STUDENT_MARK_SEQ1 seq1
  598. JOIN V_STUDENT_MARK_SEQ2 seq2
  599. ON (seq1.crs = seq2.crs)
  600. ORDER BY seq1.crs"
  601. );
  602. $statement->execute();
  603. $statement = $connection->prepare(
  604. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER2 AS
  605. 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
  606. FROM V_STUDENT_MARK_SEQ3 seq1
  607. JOIN V_STUDENT_MARK_SEQ4 seq2
  608. ON (seq1.crs = seq2.crs)
  609. ORDER BY seq1.crs"
  610. );
  611. $statement->execute();
  612. $statement = $connection->prepare(
  613. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER3 AS
  614. 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
  615. FROM V_STUDENT_MARK_SEQ5 seq1
  616. JOIN V_STUDENT_MARK_SEQ6 seq2
  617. ON (seq1.crs = seq2.crs)
  618. ORDER BY seq1.crs"
  619. );
  620. $statement->execute();
  621. // dd($dataYear);
  622. // CAS DES NOTES ANNUELLES
  623. $statement = $connection->prepare(
  624. "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  625. SELECT DISTINCT
  626. course.wording as course, course.coefficient as coef,
  627. module.name as module,
  628. user.full_name as teacher,
  629. quat1.value as value1, quat1.weight as weight1,
  630. quat2.value as value2, quat2.weight as weight2,
  631. quat3.value as value3,quat3.weight as weight3,
  632. ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  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. $html = $this->renderView('student/reportcardYearApc.html.twig', array(
  647. 'year' => $year,
  648. 'data' => $dataYear,
  649. 'std' => $std,
  650. 'room' => $sub->getClassRoom(),
  651. "headerFontSize" => 0.75*$headerFontSize,
  652. "lineHeight" => 1.5*$lineHeight,
  653. "copyright" => $copyright,
  654. 'fileExist' => $fileExist
  655. ));
  656. return new Response(
  657. $this->snappy->getOutputFromHtml($html),
  658. 200,
  659. array(
  660. 'Content-Type' => 'application/pdf',
  661. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $std->getMatricule() . '.pdf"',
  662. )
  663. );
  664. }
  665. }