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){
  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. $connection = $this->em->getConnection();
  411. $year = $this->schoolYearService->sessionYearById();
  412. $sub = $this->subRepo->findOneBy(array("student" => $std, "schoolYear" => $year));
  413. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  414. $students = $this->repo->findEnrolledStudentsThisYearInClass($sub->getClassRoom(), $year);
  415. $mainTeacher = $this->mainTeacherRepo->findOneBy(array("classRoom" => $sub->getClassRoom(), "schoolYear" => $year))-> getTeacher();
  416. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  417. $fileExist = file_exists($filename);
  418. $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
  419. FROM sequence
  420. JOIN evaluation ON evaluation.sequence_id = sequence.id
  421. JOIN course ON evaluation.course_id = course.id
  422. JOIN attribution on attribution.course_id = course.id
  423. JOIN user ON user.id = attribution.teacher_id
  424. JOIN mark ON evaluation.id = mark.evaluation_id
  425. JOIN quater ON sequence.quater_id = quater.id
  426. JOIN school_year on quater.school_year_id= school_year.id and school_year.id = attribution.year_id
  427. WHERE quater.id = :quater_id AND mark.student_id=:student_id
  428. ORDER BY course.id,sequence.id; ";
  429. $params = [
  430. 'quater_id' => $quater->getId(),
  431. 'student_id' => $std->getId(), // Remplace :city
  432. ];
  433. $result = $connection->executeQuery($query, $params);
  434. $data = $result->fetchAllAssociative();
  435. $html = $this->renderView('student/reportcard/quaterly_2024.html.twig', array(
  436. 'year' => $year,
  437. 'quater' => $quater,
  438. 'mainTeacher'=>$mainTeacher,
  439. 'data' => $data,
  440. 'std' => $std,
  441. 'students' => $students,
  442. 'room' => $sub->getClassRoom(),
  443. 'fileExist' => $fileExist
  444. ));
  445. return new Response(
  446. $pdf->getOutputFromHtml($html),
  447. 200,
  448. array(
  449. 'Content-Type' => 'application/pdf',
  450. 'Content-Disposition' => 'inline; filename="bull_' . $quater->getId().'_'.$std->getMatricule() . '.pdf"'
  451. )
  452. );
  453. }
  454. /**
  455. * Finds and displays a ClassRoom entity.
  456. *
  457. * @Route("/{id}/reportCardTrim", name="admin_students_reportcards_quat", requirements={"id"="\d+"})
  458. * @Method("GET")
  459. * @Template()
  460. */
  461. public function reporCardTrimAction(Pdf $pdf, Student $std)
  462. {
  463. if (!$this->getUser()) {
  464. $this->addFlash('warning', 'You need login first!');
  465. return $this->redirectToRoute('app_login');
  466. }
  467. if (!$this->getUser()->isVerified()) {
  468. $this->addFlash('warning', 'You need to have a verified account!');
  469. return $this->redirectToRoute('app_login');
  470. }
  471. $connection = $this->em->getConnection();
  472. $year = $this->schoolYearService->sessionYearById();
  473. $sub = $this->subRepo->findOneBy(array("student" => $std, "schoolYear" => $year));
  474. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  475. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  476. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  477. $fileExist = file_exists($filename);
  478. $i = 1;
  479. foreach ($sequences as $seq) {
  480. /*******************************************************************************************************************/
  481. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE L'ELEVE**************/
  482. /*******************************************************************************************************************/
  483. // CAS DES NOTES SEQUENTIELLES
  484. $statement = $connection->prepare(
  485. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" . $i . " AS
  486. 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
  487. FROM mark m JOIN student std ON m.student_id = std.id
  488. JOIN evaluation eval ON m.evaluation_id = eval.id
  489. JOIN class_room room ON eval.class_room_id = room.id
  490. JOIN course crs ON eval.course_id = crs.id
  491. JOIN attribution att ON att.course_id = crs.id
  492. JOIN user teach ON att.teacher_id = teach.id
  493. JOIN module modu ON modu.id = crs.module_id
  494. JOIN sequence seq ON seq.id = eval.sequence_id
  495. WHERE std.id = ? AND eval.sequence_id =?
  496. ORDER BY crs.id; "
  497. );
  498. $statement->bindValue(1, $std->getId());
  499. $statement->bindValue(2, $seq->getId());
  500. $statement->execute();
  501. $i++;
  502. }
  503. $statement = $connection->prepare(
  504. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  505. 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
  506. FROM V_STUDENT_MARK_SEQ1 seq1
  507. JOIN V_STUDENT_MARK_SEQ2 seq2
  508. ON (seq1.crs = seq2.crs)
  509. ORDER BY seq1.crs"
  510. );
  511. $statement->execute();
  512. $dataQuater = $connection->executeQuery("SELECT * FROM V_STUDENT_MARK_QUATER ")->fetchAll();
  513. $html = $this->renderView('student/reportcardTrimApc.html.twig', array(
  514. 'year' => $year,
  515. 'quater' => $quater,
  516. 'data' => $dataQuater,
  517. 'sequences' => $sequences,
  518. 'std' => $std,
  519. 'room' => $sub->getClassRoom(),
  520. 'fileExist' => $fileExist
  521. ));
  522. return new Response(
  523. $pdf->getOutputFromHtml($html),
  524. 200,
  525. array(
  526. 'Content-Type' => 'application/pdf',
  527. 'Content-Disposition' => 'inline; filename="bull_' . $quater->getId().'_'.$std->getMatricule() . '.pdf"'
  528. )
  529. );
  530. }
  531. /**
  532. * Finds and displays a ClassRoom entity.
  533. *
  534. * @Route("/{id}/reportCardYear", name="admin_students_reportcards_year", requirements={"id"="\d+"})
  535. * @Method("GET")
  536. * @Template()
  537. */
  538. public function reporCardYear(Student $std)
  539. {
  540. if (!$this->getUser()) {
  541. $this->addFlash('warning', 'You need login first!');
  542. return $this->redirectToRoute('app_login');
  543. }
  544. if (!$this->getUser()->isVerified()) {
  545. $this->addFlash('warning', 'You need to have a verified account!');
  546. return $this->redirectToRoute('app_login');
  547. }
  548. $connection = $this->em->getConnection();
  549. $year = $this->schoolYearService->sessionYearById();
  550. $sequences = $this->seqRepo->findSequenceThisYear($year);
  551. $sub = $this->subRepo->findOneBy(array("student" => $std, "schoolYear" => $year));
  552. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  553. $fileExist = file_exists($filename);
  554. $i = 1;
  555. foreach ($sequences as $seq) {
  556. /*******************************************************************************************************************/
  557. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE L'ELEVE**************/
  558. /*******************************************************************************************************************/
  559. // CAS DES NOTES SEQUENTIELLES
  560. $statement = $connection->prepare(
  561. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" . $i . " AS
  562. 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
  563. FROM mark m JOIN student std ON m.student_id = std.id
  564. JOIN evaluation eval ON m.evaluation_id = eval.id
  565. JOIN class_room room ON eval.class_room_id = room.id
  566. JOIN course crs ON eval.course_id = crs.id
  567. JOIN attribution att ON att.course_id = crs.id
  568. JOIN user teach ON att.teacher_id = teach.id
  569. JOIN module modu ON modu.id = crs.module_id
  570. JOIN sequence seq ON seq.id = eval.sequence_id
  571. JOIN quater quat ON seq.quater_id = quat.id
  572. JOIN school_year year ON quat.school_year_id = year.id
  573. WHERE std.id = ? AND room.id = ? AND eval.sequence_id =?
  574. ORDER BY crs.id; "
  575. );
  576. $statement->bindValue(1, $std->getId());
  577. $statement->bindValue(2, $sub->getClassRoom()->getId());
  578. $statement->bindValue(3, $seq->getId());
  579. $statement->execute();
  580. $i++;
  581. }
  582. // CAS DES NOTES TRIMESTRIELLES
  583. $statement = $connection->prepare(
  584. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER1 AS
  585. 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
  586. FROM V_STUDENT_MARK_SEQ1 seq1
  587. JOIN V_STUDENT_MARK_SEQ2 seq2
  588. ON (seq1.crs = seq2.crs)
  589. ORDER BY seq1.crs"
  590. );
  591. $statement->execute();
  592. $statement = $connection->prepare(
  593. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER2 AS
  594. 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
  595. FROM V_STUDENT_MARK_SEQ3 seq1
  596. JOIN V_STUDENT_MARK_SEQ4 seq2
  597. ON (seq1.crs = seq2.crs)
  598. ORDER BY seq1.crs"
  599. );
  600. $statement->execute();
  601. $statement = $connection->prepare(
  602. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER3 AS
  603. 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
  604. FROM V_STUDENT_MARK_SEQ5 seq1
  605. JOIN V_STUDENT_MARK_SEQ6 seq2
  606. ON (seq1.crs = seq2.crs)
  607. ORDER BY seq1.crs"
  608. );
  609. $statement->execute();
  610. // dd($dataYear);
  611. // CAS DES NOTES ANNUELLES
  612. $statement = $connection->prepare(
  613. "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  614. SELECT DISTINCT
  615. course.wording as course, course.coefficient as coef,
  616. module.name as module,
  617. user.full_name as teacher,
  618. quat1.value as value1, quat1.weight as weight1,
  619. quat2.value as value2, quat2.weight as weight2,
  620. quat3.value as value3,quat3.weight as weight3,
  621. ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  622. FROM V_STUDENT_MARK_QUATER1 quat1
  623. JOIN class_room ON class_room.id = quat1.room
  624. JOIN course ON course.id = quat1.crs
  625. JOIN module ON course.module_id = quat1.modu
  626. JOIN user ON user.id = quat1.teacher
  627. JOIN V_STUDENT_MARK_QUATER2 quat2 ON quat1.crs = quat2.crs
  628. JOIN
  629. V_STUDENT_MARK_QUATER3 quat3 ON quat2.crs = quat3.crs
  630. ORDER BY module
  631. "
  632. );
  633. $statement->execute();
  634. $dataYear = $connection->executeQuery("SELECT * FROM ANNUAL_DATA ")->fetchAll();
  635. $html = $this->renderView('student/reportcardYearApc.html.twig', array(
  636. 'year' => $year,
  637. 'data' => $dataYear,
  638. 'std' => $std,
  639. 'room' => $sub->getClassRoom(),
  640. 'fileExist' => $fileExist
  641. ));
  642. return new Response(
  643. $this->snappy->getOutputFromHtml($html),
  644. 200,
  645. array(
  646. 'Content-Type' => 'application/pdf',
  647. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $std->getMatricule() . '.pdf"',
  648. )
  649. );
  650. }
  651. }