src/Controller/ClassRoomController.php line 775

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  10. use Knp\Snappy\Pdf;
  11. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use App\Repository\AttributionRepository;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use App\Repository\ClassRoomRepository;
  16. use App\Repository\SchoolYearRepository;
  17. use App\Repository\QuaterRepository;
  18. use App\Repository\SequenceRepository;
  19. use App\Repository\EvaluationRepository;
  20. use App\Repository\StudentRepository;
  21. use App\Repository\MainTeacherRepository;
  22. use App\Repository\MarkRepository;
  23. use App\Entity\ClassRoom;
  24. use App\Entity\Course;
  25. use App\Entity\SchoolYear;
  26. use App\Form\ClassRoomType;
  27. use App\Entity\Sequence;
  28. use App\Entity\Quater;
  29. use App\Repository\SubscriptionRepository;
  30. use App\Repository\InstallmentRepository;
  31. use App\Service\SchoolYearService;
  32. /**
  33. * ClassRoom controller.
  34. *
  35. * @Route("prof/rooms")
  36. */
  37. class ClassRoomController extends AbstractController
  38. {
  39. private $em;
  40. private $repo;
  41. private $scRepo;
  42. private $stdRepo;
  43. private $subRepo;
  44. private $seqRepo;
  45. private $evalRepo;
  46. private $qtRepo;
  47. private $markRepo;
  48. private $snappy;
  49. private $session;
  50. private $quaterData;
  51. private Pdf $pdf;
  52. private SchoolYearService $schoolYearService;
  53. private MainTeacherRepository $mainTeacherRepo;
  54. private AttributionRepository $attRepo;
  55. private InstallmentRepository $instRepo;
  56. public function __construct(Pdf $pdf,InstallmentRepository $instRepo, AttributionRepository $attRepo, MainTeacherRepository $mainTeacherRepo, SchoolYearService $schoolYearService,MarkRepository $markRepo, QuaterRepository $qtRepo, StudentRepository $stdRepo, EvaluationRepository $evalRepo, SchoolYearRepository $scRepo, SequenceRepository $seqRepo, ClassRoomRepository $repo, SubscriptionRepository $subRepo, EntityManagerInterface $em, Pdf $snappy, SessionInterface $session)
  57. {
  58. $this->quaterData = [];
  59. $this->em = $em;
  60. $this->pdf = $pdf;
  61. $this->repo = $repo;
  62. $this->scRepo = $scRepo;
  63. $this->attRepo = $attRepo;
  64. $this->seqRepo = $seqRepo;
  65. $this->evalRepo = $evalRepo;
  66. $this->mainTeacherRepo = $mainTeacherRepo;
  67. $this->stdRepo = $stdRepo;
  68. $this->instRepo = $instRepo;
  69. $this->qtRepo = $qtRepo;
  70. $this->subRepo = $subRepo;
  71. $this->markRepo = $markRepo;
  72. $this->snappy = $snappy;
  73. $this->session = $session;
  74. $this->schoolYearService = $schoolYearService;
  75. }
  76. /**
  77. * Lists all ClassRoomme entities.
  78. *
  79. * @Route("/", name="admin_classrooms")
  80. * @Method("GET")
  81. * @Template()
  82. */
  83. public function indexAction()
  84. {
  85. $classrooms = $this->repo->findAll();
  86. $year = $this->schoolYearService->sessionYearById();
  87. $seq = $this->seqRepo->findOneBy(array("activated" => true));
  88. $mainTeachers = $this->mainTeacherRepo->findBy(array("schoolYear" => $year));
  89. $mainTeachersMap = array();
  90. foreach($mainTeachers as $mt){
  91. $mainTeachersMap[$mt->getClassRoom()->getId()] = $mt->getTeacher();
  92. }
  93. return $this->render('classroom/index.html.twig', array(
  94. 'mainTeachers' => $mainTeachersMap,
  95. 'classrooms' => $classrooms,
  96. 'year' => $year,
  97. 'seq' => $seq->getId(),
  98. ));
  99. }
  100. /**
  101. * Finds and displays a ClassRoomme entity.
  102. *
  103. * @Route("/{id}/show", name="admin_classrooms_show", requirements={"id"="\d+"})
  104. * @Method("GET")
  105. * @Template()
  106. */
  107. public function showAction(ClassRoom $classroom, StudentRepository $stdRepo)
  108. {
  109. // Année scolaire et seuquence en cours
  110. $year = $this->schoolYearService->sessionYearById();
  111. $seq = $this->seqRepo->findOneBy(array("activated" => true));
  112. // Elèves inscrits
  113. $studentEnrolled = $stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  114. $fileExists = [];
  115. foreach ($studentEnrolled as $std) {
  116. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  117. $fileExists[$std->getId()] = file_exists($filename);
  118. }
  119. // Attributions de cours durant l'annee
  120. $attributions = $this->attRepo->findByYearAndByRoom($year,$classroom);
  121. $attributionsMapCourses = null;
  122. foreach($attributions as $att){
  123. $attributionsMapCourses[$att->getCourse()->getId()] = $att;
  124. }
  125. // Liste des resulats au examens officiels
  126. $officialExamResults = $this->subRepo->countByMention($year, $classroom);
  127. $mentionCategories = [];
  128. $mentionCountCategories = [];
  129. foreach ($officialExamResults as $exam) {
  130. switch ($exam["officialExamResult"]) {
  131. case "0":
  132. $mentionCategories[] = "ECHEC";
  133. break;
  134. case "1p":
  135. $mentionCategories[] = "PASSABLE";
  136. break;
  137. case "1a":
  138. $mentionCategories[] = "ASSEZ-BIEN";
  139. break;
  140. case "1b":
  141. $mentionCategories[] = "BIEN";
  142. break;
  143. case "1t":
  144. $mentionCategories[] = "TRES-BIEN";
  145. break;
  146. case "1e":
  147. $mentionCategories[] = "EXCELLENT";
  148. break;
  149. case "A":
  150. $mentionCategories[] = "5 POINTS";
  151. break;
  152. case "B":
  153. $mentionCategories[] = "4 POINTS";
  154. break;
  155. case "C":
  156. $mentionCategories[] = "3 POINTS";
  157. break;
  158. case "D":
  159. $mentionCategories[] = "2 POINTS";
  160. break;
  161. case "E":
  162. $mentionCategories[] = "1 POINT";
  163. break;
  164. }
  165. $mentionCountCategories[] = $exam["count"];
  166. }
  167. // Extraction de donnees pour les graphes
  168. $seqs = $this->seqRepo->findSequenceThisYear($year);
  169. $evalSeqs = [];
  170. foreach ($seqs as $seq) {
  171. $evalSeqs[$seq->getId()] = $this->evalRepo->findBy(array("classRoom" => $classroom, "sequence" => $seq));
  172. }
  173. $courses = [];
  174. $averageSeqs = [];
  175. // Traitements de donnees pour les graphes de notes sequentielles
  176. foreach ($evalSeqs[$seq->getId()] as $eval) {
  177. $courses[] = $eval->getCourse()->getWording();
  178. }
  179. foreach ($seqs as $seq) {
  180. $average = [];
  181. foreach ($evalSeqs[$seq->getId()] as $eval) {
  182. $average[] = $eval->getMoyenne();
  183. }
  184. $averageSeqs[$seq->getId()] = $average;
  185. }
  186. // Recherche de l'enseignant titulaire
  187. $mainTeacher = null;
  188. foreach($classroom->getMainTeachers() as $mainT){
  189. if($mainT->getSchoolYear()->getId() == $year->getId()){
  190. $mainTeacher = $mainT->getTeacher();
  191. }
  192. }
  193. $results['mainteacher'] = $mainTeacher;
  194. $results['classroom'] = $classroom;
  195. $results['attributions'] = $attributionsMapCourses;
  196. $results['modules'] = $classroom->getModules();
  197. $results['studentEnrolled'] = $studentEnrolled;
  198. $results['cours'] = json_encode($courses);
  199. $results['fileExists'] = $fileExists;
  200. $results['sessions'] = json_encode($seqs);
  201. $results['mentionCategories'] = json_encode($mentionCategories);
  202. $results['mentionCountCategories'] = json_encode($mentionCountCategories);
  203. foreach ($seqs as $seq) {
  204. $results[strtolower($seq->getWording())] = json_encode($averageSeqs[$seq->getId()]);
  205. }
  206. return $this->render('classroom/show.html.twig', $results);
  207. }
  208. /**
  209. * Finds and displays a ClassRoomme entity.
  210. *
  211. * @Route("/{id}/stat", name="admin_classrooms_stat", requirements={"id"="\d+"})
  212. * @Method("GET")
  213. * @Template()
  214. */
  215. public function statAction(ClassRoom $classroom)
  216. {
  217. return $this->render('classroom/show.html.twig', array());
  218. }
  219. /**
  220. * Finds and displays a ClassRoom entity.
  221. *
  222. * @Route("/{id}/reportCardsYear", name="admin_classrooms_reportcards_year", requirements={"id"="\d+"})
  223. * @Method("GET")
  224. * @Template()
  225. */
  226. public function reportCardsYearAction(ClassRoom $classroom)
  227. {
  228. set_time_limit(600);
  229. $connection = $this->em->getConnection();
  230. $year = $this->schoolYearService->sessionYearById();
  231. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  232. $statement = $connection->prepare(
  233. " CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ1 AS
  234. SELECT DISTINCT eval.id as eval,crs.id as crs, room.id as room,year.id as year, std.matricule as matricule, std.image_name as profileImagePath, std.lastname as lastname, std.firstname as firstname, std.birthday as birthday, std.gender as gender,std.birthplace as birthplace , teach.full_name as teacher , modu.name as module , crs.wording as wording, crs.coefficient as coefficient,m.value as valeur, m.weight as weight, m.appreciation as appreciation
  235. FROM mark m JOIN student std ON m.student_id = std.id
  236. JOIN evaluation eval ON m.evaluation_id = eval.id
  237. JOIN class_room room ON eval.class_room_id = room.id
  238. JOIN course crs ON eval.course_id = crs.id
  239. JOIN attribution att ON att.course_id = crs.id
  240. JOIN user teach ON att.teacher_id = teach.id
  241. JOIN module modu ON modu.id = crs.module_id
  242. JOIN sequence seq ON seq.id = eval.sequence_id
  243. JOIN quater quat ON seq.quater_id = quat.id
  244. JOIN school_year year ON quat.school_year_id = year.id
  245. WHERE room.id = ? AND eval.sequence_id =1
  246. "
  247. );
  248. $statement->bindValue(1, $classroom->getId());
  249. $statement->execute();
  250. $statement = $connection->prepare(
  251. "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ2 AS
  252. SELECT DISTINCT crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  253. FROM mark m
  254. JOIN student std ON m.student_id = std.id
  255. JOIN evaluation eval ON m.evaluation_id = eval.id
  256. JOIN course crs ON eval.course_id = crs.id
  257. WHERE eval.class_room_id = ? AND eval.sequence_id = 2
  258. ORDER BY matricule,eval; "
  259. );
  260. $statement->bindValue(1, $classroom->getId());
  261. $statement->execute();
  262. $statement = $connection->prepare(
  263. "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ3 AS
  264. SELECT DISTINCT crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  265. FROM mark m
  266. JOIN student std ON m.student_id = std.id
  267. JOIN evaluation eval ON m.evaluation_id = eval.id
  268. JOIN course crs ON eval.course_id = crs.id
  269. WHERE eval.class_room_id =? AND eval.sequence_id = 3
  270. ORDER BY matricule,eval; "
  271. );
  272. $statement->bindValue(1, $classroom->getId());
  273. $statement->execute();
  274. $statement = $connection->prepare(
  275. "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ4 AS
  276. SELECT DISTINCT crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  277. FROM mark m
  278. JOIN student std ON m.student_id = std.id
  279. JOIN evaluation eval ON m.evaluation_id = eval.id
  280. JOIN course crs ON eval.course_id = crs.id
  281. WHERE eval.class_room_id = ? AND eval.sequence_id = 4
  282. ORDER BY matricule,eval; "
  283. );
  284. $statement->bindValue(1, $classroom->getId());
  285. $statement->execute();
  286. $statement = $connection->prepare(
  287. "CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ5 AS
  288. SELECT DISTINCT crs.id as crs, eval.id as eval, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  289. FROM mark m
  290. JOIN student std ON m.student_id = std.id
  291. JOIN evaluation eval ON m.evaluation_id = eval.id
  292. JOIN course crs ON eval.course_id = crs.id
  293. WHERE eval.class_room_id = ? AND eval.sequence_id = 5
  294. ORDER BY matricule,eval; "
  295. );
  296. $statement->bindValue(1, $classroom->getId());
  297. $statement->execute();
  298. $statement = $connection->prepare(
  299. " CREATE OR REPLACE VIEW V_STUDENT_MARK_DATA_SEQ6 AS
  300. SELECT DISTINCT eval.id as eval,crs.id as crs, std.matricule as matricule, m.value as valeur, m.weight as weight, m.appreciation as appreciation
  301. FROM mark m JOIN student std ON m.student_id = std.id
  302. JOIN evaluation eval ON m.evaluation_id = eval.id
  303. JOIN class_room room ON eval.class_room_id = room.id
  304. JOIN course crs ON eval.course_id = crs.id
  305. WHERE room.id = ? AND eval.sequence_id = 6
  306. ORDER BY std.matricule"
  307. );
  308. $statement->bindValue(1, $classroom->getId());
  309. $statement->execute();
  310. $dataYear = $this->em->getConnection()->executeQuery("select * from V_STUDENT_MARK_DATA_SEQ1
  311. INNER JOIN V_STUDENT_MARK_DATA_SEQ2 ON V_STUDENT_MARK_DATA_SEQ1.matricule = V_STUDENT_MARK_DATA_SEQ2.matricule
  312. INNER JOIN V_STUDENT_MARK_DATA_SEQ3 ON V_STUDENT_MARK_DATA_SEQ2.matricule = V_STUDENT_MARK_DATA_SEQ3.matricule
  313. INNER JOIN V_STUDENT_MARK_DATA_SEQ4 ON V_STUDENT_MARK_DATA_SEQ3.matricule = V_STUDENT_MARK_DATA_SEQ4.matricule
  314. INNER JOIN V_STUDENT_MARK_DATA_SEQ5 ON V_STUDENT_MARK_DATA_SEQ4.matricule = V_STUDENT_MARK_DATA_SEQ5.matricule
  315. INNER JOIN V_STUDENT_MARK_DATA_SEQ6 ON V_STUDENT_MARK_DATA_SEQ5.matricule = V_STUDENT_MARK_DATA_SEQ6.matricule
  316. ")->fetchAll();
  317. $this->snappy->setTimeout(600);
  318. $html = $this->renderView('classroom/reportcard/annual.html.twig', array(
  319. 'year' => $year,
  320. 'data' => $dataYear,
  321. 'room' => $classroom,
  322. 'year' => $year,
  323. 'students' => $studentEnrolled,
  324. ));
  325. return new Response(
  326. $this->snappy->getOutputFromHtml($html),
  327. 200,
  328. array(
  329. 'Content-Type' => 'application/pdf',
  330. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $classroom->getName() . '.pdf"',
  331. )
  332. );
  333. }
  334. public function viewSeq(int $i){
  335. $year = $this->schoolYearService->sessionYearById();
  336. $connection = $this->em->getConnection();
  337. $statement = $connection->prepare(
  338. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" . $i . " AS
  339. SELECT DISTINCT eval.id as eval,crs.id as crs, room.id as room,year.id as year, std.id as std, teach.full_name as teacher , modu.id as module,m.value as value, m.weight as weight
  340. FROM mark m JOIN student std ON m.student_id = std.id
  341. JOIN evaluation eval ON m.evaluation_id = eval.id
  342. JOIN class_room room ON eval.class_room_id = room.id
  343. JOIN course crs ON eval.course_id = crs.id
  344. JOIN attribution att ON att.course_id = crs.id
  345. JOIN user teach ON att.teacher_id = teach.id
  346. JOIN module modu ON modu.id = crs.module_id
  347. JOIN sequence seq ON seq.id = eval.sequence_id
  348. JOIN quater quat ON seq.quater_id = quat.id
  349. JOIN school_year year ON quat.school_year_id = year.id
  350. WHERE att.year_id =? AND room.id = ? AND eval.sequence_id =?
  351. ORDER BY room.id,modu.id , std; "
  352. );
  353. $statement->bindValue(1, $year->getId());
  354. $statement->bindValue(2, $classroom->getId());
  355. $statement->bindValue(3, $seq->getId());
  356. $statement->execute();
  357. }
  358. /**
  359. * Finds and displays a ClassRoom entity.
  360. *
  361. * @Route("/{id}/reportCardsApcYearapc", name="admin_class_reportcards_apc_year", requirements={"id"="\d+"})
  362. * @Method("GET")
  363. * @Template()
  364. */
  365. public function reportCards2YearAction(ClassRoom $classroom)
  366. {
  367. set_time_limit(600);
  368. $connection = $this->em->getConnection();
  369. $year = $this->schoolYearService->sessionYearById();
  370. $sequences = $this->seqRepo->findSequenceThisYear($year);
  371. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  372. $i = 1;
  373. foreach ($sequences as $seq) {
  374. /*******************************************************************************************************************/
  375. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES ET ANNUELLES DE LA CLASSE**************/
  376. /*******************************************************************************************************************/
  377. // CAS DES NOTES SEQUENTIELLES
  378. // $this->viewSeq($i, $classroom, $seq);
  379. $this->getViewSeqData( $classroom, $seq, $i);
  380. $i++;
  381. }
  382. // CAS DES NOTES TRIMESTRIELLES
  383. $statement = $connection->prepare(
  384. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  385. SELECT DISTINCT seq1.std as std , seq1.crs as crs, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  386. FROM V_STUDENT_MARK_SEQ1 seq1
  387. JOIN V_STUDENT_MARK_SEQ2 seq2
  388. ON (seq1.std = seq2.std AND seq1.crs = seq2.crs)
  389. ORDER BY seq1.std"
  390. );
  391. $statement->execute();
  392. $statement = $connection->prepare(
  393. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  394. SELECT DISTINCT seq1.std as std , seq1.crs as crs, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  395. FROM V_STUDENT_MARK_SEQ3 seq1
  396. JOIN V_STUDENT_MARK_SEQ4 seq2
  397. ON (seq1.std = seq2.std AND seq1.crs = seq2.crs)
  398. ORDER BY seq1.std"
  399. );
  400. $statement->execute();
  401. $statement = $connection->prepare(
  402. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  403. SELECT DISTINCT seq1.std as std , seq1.crs as crs, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  404. FROM V_STUDENT_MARK_SEQ5 seq1
  405. JOIN V_STUDENT_MARK_SEQ6 seq2
  406. ON (seq1.std = seq2.std AND seq1.crs = seq2.crs)
  407. ORDER BY seq1.std"
  408. );
  409. $statement->execute();
  410. // CAS DES NOTES ANNUELLES
  411. $statement = $connection->prepare(
  412. "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  413. SELECT DISTINCT student.id as idStd , student.matricule as matricule , student.image_name as profileImagePath,
  414. student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  415. student.gender as gender,student.birthplace as birthplace ,
  416. class_room.name as room_name,
  417. course.wording as course, course.coefficient as coef,
  418. module.name as module,
  419. user.full_name as teacher,
  420. quat1.std,quat1.modu,
  421. quat1.value as value1, quat1.weight as weight1,
  422. quat2.value as value2, quat2.weight as weight2,
  423. quat3.value as value3,quat3.weight as weight3,
  424. greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  425. ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  426. FROM student
  427. JOIN V_STUDENT_MARK_QUATER_1 quat1 ON student.id = quat1.std
  428. JOIN class_room ON class_room.id = quat1.room
  429. JOIN course ON course.id = quat1.crs
  430. JOIN module ON course.module_id = quat1.modu
  431. JOIN user ON user.full_name = quat1.teacher
  432. JOIN V_STUDENT_MARK_QUATER_2 quat2 ON quat1.std = quat2.std AND quat1.crs = quat2.crs
  433. JOIN
  434. V_STUDENT_MARK_QUATER_3 quat3 ON quat1.std = quat3.std AND quat1.crs = quat3.crs
  435. ORDER BY quat1.std, quat1.modu
  436. "
  437. );
  438. $statement->execute();
  439. $dataYear = $connection->executeQuery("SELECT * FROM ANNUAL_DATA ")->fetchAll();
  440. // For calculating ranks
  441. $statement = $connection->prepare(
  442. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  443. SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  444. FROM ANNUAL_DATA
  445. GROUP BY idStd
  446. ORDER BY SUM(value*weight*coef) DESC"
  447. );
  448. $statement->execute();
  449. $annualAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  450. $annualAvgArray = [];
  451. $sumAvg = 0;
  452. $rank = 0;
  453. $rankArray = [];
  454. foreach ($annualAvg as $avg) {
  455. $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  456. $rankArray[$avg['idStd']] = ++$rank;
  457. $sumAvg += $avg['moyenne'];
  458. }
  459. $this->snappy->setTimeout(600);
  460. $html = $this->renderView('classroom/reportcardYear.html.twig', array(
  461. 'year' => $year,
  462. 'data' => $dataYear,
  463. 'room' => $classroom,
  464. 'students' => $studentEnrolled,
  465. 'ranks' => $rankArray,
  466. 'means' => $annualAvgArray,
  467. 'genMean' => $sumAvg / sizeof($annualAvgArray),
  468. ));
  469. //return new Response($html);
  470. return new Response(
  471. $this->snappy->getOutputFromHtml($html),
  472. 200,
  473. array(
  474. 'Content-Type' => 'application/pdf',
  475. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $classroom->getName() . '.pdf"',
  476. )
  477. );
  478. }
  479. /**
  480. * Finds and displays a Evaluation entity.
  481. *
  482. * @Route("/{room}/{seq}/pdf", name="admin_classrooms_recapitulatif", requirements={"room"="\d+","seq"="\d+"})
  483. * @Method("GET")
  484. * @Template()
  485. * @return Response
  486. */
  487. public function recapitulatifAction(ClassRoom $room, Sequence $seq)
  488. {
  489. // Année scolaire en cours
  490. $year = $this->schoolYearService->sessionYearById();
  491. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  492. $html = $this->renderView('classroom/templating/recapitulatifseqvierge.html.twig', array(
  493. 'room' => $room,
  494. 'seq' => $seq,
  495. 'students' => $studentEnrolled,
  496. 'year' => $year,
  497. ));
  498. $options = [
  499. 'orientation' => 'Landscape', // Changer ici entre 'Portrait' ou 'Landscape'
  500. 'page-size' => 'A4', // Format de page
  501. ];
  502. return new Response(
  503. $this->pdf->getOutputFromHtml($html, $options),
  504. 200,
  505. array(
  506. 'Content-Type' => 'application/pdf',
  507. 'Content-Disposition' => 'inline; filename="fiche_recep_' . $room->getName() . '.pdf"'
  508. )
  509. );
  510. }
  511. /**
  512. * Finds and displays a ClassRoom entity.
  513. *
  514. * @Route("/{id}/recapitulatifseq", name="admin_classrooms_recapitulatif_seq", requirements={"id"="\d+"})
  515. * @Method("GET")
  516. * @Template()
  517. */
  518. public function recapSeqAction(ClassRoom $room, Request $request)
  519. {
  520. // set_time_limit(600);
  521. $checkedValues = $request->request->get('selected_courses');
  522. $em = $this->getDoctrine()->getManager();
  523. $year = $this->schoolYearService->sessionYearById();
  524. $seq = $this->seqRepo->findOneBy(array("activated" => true));
  525. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  526. $datas = $this->markRepo->findMarksBySequenceAndClassOrderByStd($seq, $room);
  527. $html = $this->renderView('classroom/recapitulatifseq.html.twig', array(
  528. 'room' => $room,
  529. 'datas' => $datas,
  530. 'year' => $year,
  531. 'seq' => $seq,
  532. 'students' => $studentEnrolled,
  533. 'checkedValues' => $checkedValues
  534. ));
  535. return new Response($html);
  536. }
  537. /**
  538. * @Route("/create",name= "admin_classrooms_new", methods={"GET","POST"})
  539. */
  540. public function create(Request $request): Response
  541. {
  542. if (!$this->getUser()) {
  543. $this->addFlash('warning', 'You need login first!');
  544. return $this->redirectToRoute('app_login');
  545. }
  546. $schoolyear = new ClassRoom();
  547. $form = $this->createForm(ClassRoomType::class, $schoolyear);
  548. $form->handleRequest($request);
  549. if ($form->isSubmitted() && $form->isValid()) {
  550. $this->em->persist($schoolyear);
  551. $this->em->flush();
  552. $this->addFlash('success', 'ClassRoom succesfully created');
  553. return $this->redirectToRoute('admin_classrooms');
  554. }
  555. return $this->render(
  556. 'classroom/new.html.twig',
  557. ['form' => $form->createView()]
  558. );
  559. }
  560. /**
  561. * Rapport séquentiel d'enregistrement des notes.
  562. *
  563. * @Route("/{id}/evalrepport", name="admin_current_fulfilled_eval_show", requirements={"id"="\d+"})
  564. * @Method("GET")
  565. * @Template()
  566. */
  567. public function currentFullfilledEvalAction(ClassRoom $classroom)
  568. {
  569. $em = $this->getDoctrine()->getManager();
  570. $year = ($this->session->has('session_school_year') && ($this->session->get('session_school_year')!= null)) ? $this->session->get('session_school_year') : $this->scRepo->findOneBy(array("activated" => true));
  571. // Liste des séquences de l'année scolaire en cours
  572. $sequences = $em->getRepository('AppBundle:Sequence')->findSequencesBySchoolYear($year);
  573. // Liste des matières
  574. $courses = $em->getRepository('AppBundle:Course')->findProgrammedCoursesInClass($classroom);
  575. // Elèves inscrits
  576. foreach ($sequences as $seq) {
  577. // Lecture de chaque tableau de chaque ligne
  578. foreach ($courses as $course) {
  579. // Liste des évaluations
  580. $evaluation = $em->getRepository('AppBundle:Evaluation')->findOneBy(array(
  581. "classRoom" => $classroom,
  582. "sequence" => $seq, "course" => $course
  583. ));
  584. if ($evaluation != null) {
  585. $evaluations[$seq->getId()][$course->getId()] = 1;
  586. } else {
  587. $evaluations[$seq->getId()][$course->getId()] = 0;
  588. }
  589. }
  590. }
  591. return $this->render('classroom/eval_repport.html.twig', array(
  592. 'evaluations' => $evaluations,
  593. 'courses' => $courses,
  594. 'room' => $classroom,
  595. 'sequences' => $sequences,
  596. ));
  597. }
  598. /**
  599. * Displays a form to edit an existing ClassRoomme entity.
  600. *
  601. * @Route("/{id}/edit", name="admin_classrooms_edit", requirements={"id"="\d+"}, methods={"GET","PUT"})
  602. * @Template()
  603. */
  604. public function edit(Request $request, ClassRoom $room): Response
  605. {
  606. $form = $this->createForm(ClassRoomType::class, $room, [
  607. 'method' => 'PUT'
  608. ]);
  609. $form->handleRequest($request);
  610. if ($form->isSubmitted() && $form->isValid()) {
  611. $this->em->flush();
  612. $this->addFlash('success', 'ClassRoom succesfully updated');
  613. return $this->redirectToRoute('admin_classrooms');
  614. }
  615. return $this->render('classroom/edit.html.twig', [
  616. 'room' => $room,
  617. 'form' => $form->createView()
  618. ]);
  619. }
  620. /**
  621. * Deletes a ClassRoom entity.
  622. *
  623. * @Route("/{id}/delete", name="admin_classrooms_delete", requirements={"id"="\d+"}, methods={"DELETE"})
  624. */
  625. public function delete(ClassRoom $q, Request $request): Response
  626. {
  627. // if($this->isCsrfTokenValid('classrooms_deletion'.$schoolyear->getId(), $request->request->get('crsf_token') )){
  628. $this->em->remove($q);
  629. $this->em->flush();
  630. $this->addFlash('info', 'ClassRoom succesfully deleted');
  631. // }
  632. return $this->redirectToRoute('admin_classrooms');
  633. }
  634. /**
  635. * Finds and displays a ClassRoom entity.
  636. *
  637. * @Route("/{id}/fichesimple", name="admin_classrooms_fichesimple", requirements={"id"="\d+"})
  638. * @Method("GET")
  639. * @Template()
  640. */
  641. public function fichesiplmeAction(ClassRoom $classroom)
  642. {
  643. // Année scolaire en cours
  644. $year = $this->schoolYearService->sessionYearById();
  645. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  646. $html = $this->renderView('classroom/templating/fiche_repport_notes.html.twig', array(
  647. 'year' => $year,
  648. 'room' => $classroom,
  649. 'students' => $studentEnrolled,
  650. ));
  651. return new Response(
  652. $this->pdf->getOutputFromHtml($html),
  653. 200,
  654. array(
  655. 'Content-Type' => 'application/pdf',
  656. 'Content-Disposition' => 'inline; filename="fiche_pv_' . $classroom->getName() . '.pdf"'
  657. )
  658. );
  659. }
  660. /**
  661. * Finds and displays a ClassRoom entity.
  662. *
  663. * @Route("/{id}/disciplinary_record", name="admin_classrooms_disciplinary_record", requirements={"id"="\d+"})
  664. * @Method("GET")
  665. * @Template()
  666. */
  667. public function ficheDisciplineAction(ClassRoom $classroom)
  668. {
  669. // Année scolaire en cours
  670. $year = $this->schoolYearService->sessionYearById();
  671. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  672. $html = $this->renderView('classroom/templating/fiche_repport_disc.html.twig', array(
  673. 'year' => $year,
  674. 'room' => $classroom,
  675. 'students' => $studentEnrolled,
  676. ));
  677. return new Response(
  678. $this->pdf->getOutputFromHtml($html),
  679. 200,
  680. array(
  681. 'Content-Type' => 'application/pdf',
  682. 'Content-Disposition' => 'inline; filename="fich_disc_' . $classroom->getName() . '.pdf"'
  683. )
  684. );
  685. }
  686. /**
  687. * LISTE DES ELEVES DE LA CLASSE DANS UNE FICHE DE PRESENTATION.
  688. *
  689. * @Route("/{id}/presentation", name="admin_classrooms_presentation", requirements={"id"="\d+"})
  690. * @Method("GET")
  691. * @Template()
  692. */
  693. public function presentationAction(ClassRoom $classroom)
  694. {
  695. // Année scolaire en cours
  696. $year = $this->schoolYearService->sessionYearById();
  697. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  698. $html = $this->renderView('classroom/templating/student_list.html.twig', array(
  699. 'year' => $year,
  700. 'room' => $classroom,
  701. 'students' => $studentEnrolled,
  702. ));
  703. return new Response(
  704. $this->pdf->getOutputFromHtml($html),
  705. 200,
  706. array(
  707. 'Content-Type' => 'application/pdf',
  708. 'Content-Disposition' => 'inline; filename="std_list_' . $classroom->getName() . '.pdf"'
  709. )
  710. );
  711. }
  712. /**
  713. * MOYENNE GENERALE DE LA CLASSE A UNE SEQUENCE
  714. * @Route("/{id_room}/{id_seq}/sqavg", name="admin_classrooms_avg_seq", requirements={"id_room"="\d+", "id_seq"="\d+"})
  715. * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  716. * @ParamConverter("seq", options={"mapping": {"id_seq" : "id"}})
  717. * @Method("GET")
  718. * @Template()
  719. */
  720. public function generalSeqAverage(ClassRoom $room, Sequence $seq)
  721. {
  722. $dql = "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient) FROM App\Entity\Evaluation evaluation , App\Entity\Course course
  723. WHERE evaluation.course= course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  724. $avg_seq1 = $this->em->createQuery($dql)
  725. ->setParameter(1, $room->getId())
  726. ->setParameter(2, $seq->getId())
  727. ->getSingleScalarResult();
  728. return round($avg_seq1, 2);
  729. }
  730. /**
  731. * MOYENNE GENERALE DE LA CLASSE A UN TRIMESTRE
  732. * @Route("/{id_room}/{id_quat}/qtavg", name="admin_classrooms_avg_quat", requirements={"id_room"="\d+", "id_quat"="\d+"})
  733. * @ParamConverter("room", options={"mapping": {"id_room" : "id"}})
  734. * @ParamConverter("quater", options={"mapping": {"id_quat" : "id"}})
  735. * @Method("GET")
  736. * @Template()
  737. */
  738. public function generalQuatAverage(ClassRoom $room, Quater $quater)
  739. {
  740. $dql = "SELECT SUM(evaluation.moyenne * course.coefficient)/SUM(course.coefficient) FROM App\Entity\Evaluation evaluation , App\Entity\Course course
  741. WHERE evaluation.course= course.id AND evaluation.sequence=?2 AND evaluation.classRoom=?1 ";
  742. $avg_seq = 0;
  743. foreach ($quater->getSequences() as $seq) {
  744. $avg_seq += $this->em->createQuery($dql)
  745. ->setParameter(1, $room->getId())
  746. ->setParameter(2, $seq->getId())
  747. ->getSingleScalarResult();
  748. }
  749. return round($avg_seq / 2, 2);
  750. }
  751. /**
  752. * Finds and displays a Evaluation entity.
  753. *
  754. * @Route("/{room}/pdf", name="admin_classrooms_blanc_ann", requirements={"room"="\d+"})
  755. * @Method("GET")
  756. * @Template()
  757. * @return Response
  758. */
  759. public function annualSummaryAction(ClassRoom $room)
  760. {
  761. $year = $this->schoolYearService->sessionYearById();
  762. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  763. $html = $this->renderView('classroom/templating/blankAnnualForm.html.twig', array(
  764. 'room' => $room,
  765. 'students' => $studentEnrolled,
  766. 'year' => $year,
  767. ));
  768. return new Response(
  769. $this->pdf->getOutputFromHtml($html, array(
  770. 'default-header' => false
  771. )),
  772. 200,
  773. array(
  774. 'Content-Type' => 'application/pdf',
  775. 'Content-Disposition' => 'attachment; filename="recap_empty_' . $room->getName() . '.pdf"',
  776. )
  777. );
  778. }
  779. /**
  780. * Finds and displays a ClassRoom entity.
  781. *
  782. * @Route("/{id}/reportCardSeq", name="admin_classrooms_reportcards_seq", requirements={"id"="\d+"})
  783. * @Method("GET")
  784. * @Template()
  785. */
  786. public function reportCardSeqAction(ClassRoom $classroom)
  787. {
  788. set_time_limit(600);
  789. $totalNtCoef = 0;
  790. $totalCoef = 0;
  791. $em = $this->getDoctrine()->getManager();
  792. $year =$this->schoolYearService->sessionYearById();
  793. $sequence = $this->seqRepo->findOneBy(array("activated" => true));
  794. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  795. // Existance des photos d'eleves
  796. $fileExists = [];
  797. foreach ($studentEnrolled as $std) {
  798. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  799. $fileExists[$std->getId()] = file_exists($filename);
  800. }
  801. $evaluations = $this->evalRepo->findSequantialExamsOfRoom($classroom->getId(), $sequence->getId());
  802. foreach ($evaluations as $ev) {
  803. $totalNtCoef += $ev->getMoyenne() * $ev->getCourse()->getCoefficient();
  804. $totalCoef += $ev->getCourse()->getCoefficient();
  805. }
  806. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  807. $this->getViewSeqData($classroom, $sequence, 0);
  808. $connection = $this->em->getConnection();
  809. $datas = $connection->executeQuery("SELECT * FROM V_STUDENT_MARK_SEQ0 ")->fetchAll();
  810. // For calculating ranks
  811. $statement = $connection->prepare(
  812. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  813. SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  814. FROM V_STUDENT_MARK_SEQ0
  815. GROUP BY std
  816. ORDER BY SUM(value*weight*coef) DESC"
  817. );
  818. $statement->execute();
  819. $seqAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  820. $seqAvgArray = [];
  821. $sumAvg = 0;
  822. $rank = 0;
  823. $rankArray = [];
  824. foreach ($seqAvg as $avg) {
  825. $seqAvgArray[$avg['std']] = $avg['moyenne'];
  826. $rankArray[$avg['std']] = ++$rank;
  827. $sumAvg += $avg['moyenne'];
  828. }
  829. // CAS DES ABSCENCES SEQUENTIELLES
  830. $statement = $connection->prepare(
  831. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ AS
  832. SELECT DISTINCT seq.std as std , seq.total_hours as abscences
  833. FROM V_STUDENT_ABSCENCE_SEQ0 seq
  834. ORDER BY std "
  835. );
  836. $statement->execute();
  837. // Traitement des abscences
  838. $absences = $connection->executeQuery("SELECT * FROM V_STUDENT_ABSCENCE_SEQ ")->fetchAll();
  839. $absencesArray = [];
  840. foreach ($absences as $abs) {
  841. $absencesArray[$abs['std']] = $abs['abscences'];
  842. }
  843. $html = $this->renderView('classroom/reportcard/sequential.html.twig', array(
  844. 'year' => $year,
  845. 'datas' => $datas,
  846. 'students' => $studentEnrolled,
  847. 'sequence' => $sequence,
  848. 'quater' => $sequence->getQuater(),
  849. 'room' => $classroom,
  850. 'students' => $studentEnrolled,
  851. 'means' => $seqAvgArray,
  852. 'abscences' => $absencesArray,
  853. 'genMean' => $sumAvg / sizeof($seqAvgArray),
  854. 'ranks' => $rankArray,
  855. 'fileExists'=> $fileExists
  856. ));
  857. return new Response(
  858. $this->pdf->getOutputFromHtml($html),
  859. 200,
  860. array(
  861. 'Content-Type' => 'application/pdf',
  862. 'Content-Disposition' => 'inline; filename="bull_seq_' . $classroom->getName() . '.pdf"'
  863. )
  864. );
  865. }
  866. public function buildAbsViewSeq(ClassRoom $room,Sequence $seq){
  867. $connection = $this->em->getConnection();
  868. $statement = $connection->prepare(
  869. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" . $seq->getId() ."_".$room->getId()." AS
  870. SELECT DISTINCT abs.student_id as std, sum( abs.weight) as total_hours
  871. FROM class_room room
  872. LEFT JOIN abscence_sheet sheet ON sheet.class_room_id = room.id AND sheet.sequence_id = ?
  873. LEFT JOIN abscence abs ON sheet.id = abs.abscence_sheet_id
  874. WHERE room.id = ?
  875. GROUP BY std
  876. ORDER BY std; "
  877. );
  878. $statement->bindValue(1, $seq->getId());
  879. $statement->bindValue(2, $room->getId());
  880. $statement->execute();
  881. }
  882. public function getAbsSeqFromView(ClassRoom $room,Sequence $seq){
  883. $connection = $this->em->getConnection();
  884. return $connection->executeQuery("SELECT * FROM V_STUDENT_ABSCENCE_SEQ".$seq->getId()."_".$room->getId()." ")->fetchAllAssociative();
  885. }
  886. public function getAbsQuater(ClassRoom $room,Quater $quater){
  887. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  888. foreach ($sequences as $seq) {
  889. $this->buildAbsViewSeq($room, $seq);
  890. }
  891. $absSeq1 = $this->getAbsSeqFromView($room, $sequences[0]);
  892. $absSeq2 = $this->getAbsSeqFromView($room, $sequences[1]);
  893. $absQuater =[];
  894. $year = $this->schoolYearService->sessionYearById();
  895. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  896. foreach($studentEnrolled as $std){
  897. foreach($absSeq1 as $abs){
  898. if($abs["std"]==$std->getId()){
  899. // $absQuater[$std->getId()] = $abs["total_hours"];
  900. }
  901. }
  902. foreach($absSeq2 as $abs){
  903. if($abs["std"]==$std->getId()){
  904. $absQuater[$std->getId()] = isset($absQuater[$std->getId()]) ? $absQuater[$std->getId()] + $abs["total_hours"] : $abs["total_hours"];;
  905. }
  906. }
  907. }
  908. return $absQuater;
  909. }
  910. public function getViewSeqData(ClassRoom $room,Sequence $seq, int $i){
  911. $connection = $this->em->getConnection();
  912. $year = $this->schoolYearService->sessionYearById();
  913. // CAS DES NOTES SEQUENTIELLES
  914. $statement = $connection->prepare(
  915. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ" . $i . " AS
  916. SELECT DISTINCT eval.id as eval,crs.id as crs, crs.coefficient as coef, room.id as room, std.id as std, teach.full_name as teacher , modu.id as module,m.value as value, m.weight as weight
  917. FROM mark m JOIN student std ON m.student_id = std.id
  918. JOIN evaluation eval ON m.evaluation_id = eval.id
  919. JOIN class_room room ON eval.class_room_id = room.id
  920. JOIN course crs ON eval.course_id = crs.id
  921. JOIN attribution att ON att.course_id = crs.id and att.year_id = ?
  922. JOIN user teach ON att.teacher_id = teach.id
  923. JOIN module modu ON modu.id = crs.module_id
  924. JOIN sequence seq ON seq.id = eval.sequence_id
  925. LEFT JOIN abscence_sheet sheet ON seq.id = sheet.sequence_id AND sheet.class_room_id = room.id
  926. LEFT JOIN abscence abs ON sheet.id = abs.abscence_sheet_id
  927. JOIN quater quat ON seq.quater_id = quat.id
  928. WHERE room.id = ? AND eval.sequence_id =?
  929. ORDER BY room.id,modu.id , std; "
  930. );
  931. $statement->bindValue(1, $year->getId());
  932. $statement->bindValue(2, $room->getId());
  933. $statement->bindValue(3, $seq->getId());
  934. $statement->execute();
  935. $statement = $connection->prepare(
  936. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" . $i . " AS
  937. SELECT DISTINCT room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  938. FROM class_room room
  939. LEFT JOIN abscence_sheet sheet ON sheet.class_room_id = room.id AND sheet.sequence_id = ?
  940. LEFT JOIN abscence abs ON sheet.id = abs.abscence_sheet_id
  941. WHERE room.id = ?
  942. GROUP BY std
  943. ORDER BY room.id, std; "
  944. );
  945. $statement->bindValue(1, $seq->getId());
  946. $statement->bindValue(2, $room->getId());
  947. $statement->execute();
  948. }
  949. public function getViewSeqData2024(ClassRoom $room,Sequence $seq){
  950. $connection = $this->em->getConnection();
  951. $year = $this->schoolYearService->sessionYearById();
  952. // CAS DES NOTES SEQUENTIELLES
  953. $statement = $connection->prepare(
  954. " CREATE OR REPLACE VIEW V_STUDENT_MARK_SEQ".$room->getId()."_".$seq->getId(). " AS
  955. SELECT DISTINCT crs.id as crs, crs.coefficient as coef, std.id as std,m.value as value, m.weight as weight
  956. FROM mark m JOIN student std ON m.student_id = std.id
  957. JOIN evaluation eval ON m.evaluation_id = eval.id
  958. JOIN class_room room ON eval.class_room_id = room.id
  959. JOIN course crs ON eval.course_id = crs.id
  960. JOIN sequence seq ON seq.id = eval.sequence_id
  961. WHERE room.id = ? AND eval.sequence_id =?
  962. ORDER BY std, crs; "
  963. );
  964. $statement->bindValue(1, $room->getId());
  965. $statement->bindValue(2, $seq->getId());
  966. $statement->execute();
  967. }
  968. public function getViewQuaterData(ClassRoom $room, int $i){
  969. $connection = $this->em->getConnection();
  970. $year = $this->schoolYearService->sessionYearById();
  971. // CAS DES NOTES SEQUENTIELLES
  972. $statement = $connection->prepare(
  973. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_ROOM" . $room->getId() . " AS
  974. SELECT DISTINCT eval.id as eval,crs.id as crs, crs.coefficient as coef, room.id as room, std.id as std, teach.full_name as teacher , modu.id as module,m.value as value, m.weight as weight
  975. FROM mark m JOIN student std ON m.student_id = std.id
  976. JOIN evaluation eval ON m.evaluation_id = eval.id
  977. JOIN class_room room ON eval.class_room_id = room.id
  978. JOIN course crs ON eval.course_id = crs.id
  979. JOIN attribution att ON att.course_id = crs.id and att.year_id = ?
  980. JOIN user teach ON att.teacher_id = teach.id
  981. JOIN module modu ON modu.id = crs.module_id
  982. JOIN sequence seq ON seq.id = eval.sequence_id
  983. LEFT JOIN abscence_sheet sheet ON seq.id = sheet.sequence_id AND sheet.class_room_id = room.id
  984. LEFT JOIN abscence abs ON sheet.id = abs.abscence_sheet_id
  985. JOIN quater quat ON seq.quater_id = quat.id AND quat.id = ?
  986. WHERE room.id = ?
  987. ORDER BY std.id,modu.id , crs.id,seq.id ; "
  988. );
  989. $statement->bindValue(1, $year->getId());
  990. $statement->bindValue(2, $seq->getQuater()->getId());
  991. $statement->bindValue(3, $room->getId());
  992. $statement->execute();
  993. $statement = $connection->prepare(
  994. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_SEQ" . $i . " AS
  995. SELECT DISTINCT room.id as room, abs.student_id as std, sum( abs.weight) as total_hours
  996. FROM class_room room
  997. LEFT JOIN abscence_sheet sheet ON sheet.class_room_id = room.id AND sheet.sequence_id = ?
  998. LEFT JOIN abscence abs ON sheet.id = abs.abscence_sheet_id
  999. WHERE room.id = ?
  1000. GROUP BY std
  1001. ORDER BY room.id, std; "
  1002. );
  1003. $statement->bindValue(1, $seq->getId());
  1004. $statement->bindValue(2, $room->getId());
  1005. $statement->execute();
  1006. }
  1007. /**
  1008. * Finds and displays a ClassRoom entity.
  1009. *
  1010. * @Route("/{id}/reportCardsTrim", name="admin_classrooms_reportcards_trim", requirements={"id"="\d+"})
  1011. * @Method("GET")
  1012. * @Template()
  1013. */
  1014. public function reportCardsTrimAction(ClassRoom $room, Request $request)
  1015. {
  1016. $connection = $this->em->getConnection();
  1017. $year = $this->schoolYearService->sessionYearById();
  1018. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  1019. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  1020. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  1021. // Existance des photos d'eleves
  1022. $fileExists = [];
  1023. foreach ($studentEnrolled as $std) {
  1024. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  1025. $fileExists[$std->getId()] = file_exists($filename);
  1026. }
  1027. /*******************************************************************************************************************/
  1028. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1029. /*******************************************************************************************************************/
  1030. $i = 1;
  1031. foreach ($sequences as $seq) {
  1032. // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1033. $this->getViewSeqData($room, $seq, $i);
  1034. $i++;
  1035. }
  1036. // CAS DES NOTES TRIMESTRIELLES
  1037. $statement = $connection->prepare(
  1038. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1039. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as module, seq1.room as room
  1040. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1041. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1042. ORDER BY std , module"
  1043. );
  1044. $statement->execute();
  1045. // CAS DES ABSCENCES TRIMESTRIELLES
  1046. $statement = $connection->prepare(
  1047. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER AS
  1048. SELECT DISTINCT seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1049. FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1050. JOIN V_STUDENT_ABSCENCE_SEQ2 seq2 ON (seq1.std = seq2.std )
  1051. ORDER BY std "
  1052. );
  1053. $statement->execute();
  1054. $dataQuater = $connection->executeQuery("SELECT * FROM V_STUDENT_MARK_QUATER marks ")->fetchAll();
  1055. // For calculating ranks
  1056. $statement = $connection->prepare(
  1057. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1058. SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1059. FROM V_STUDENT_MARK_QUATER
  1060. GROUP BY std
  1061. ORDER BY SUM(value*weight*coef) DESC"
  1062. );
  1063. $statement->execute();
  1064. $quaterAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  1065. $quaterAvgArray = [];
  1066. $sumAvg = 0;
  1067. $rank = 0;
  1068. $rankArray = [];
  1069. foreach ($quaterAvg as $avg) {
  1070. $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1071. $rankArray[$avg['std']] = ++$rank;
  1072. $sumAvg += $avg['moyenne'];
  1073. }
  1074. // Traitement des abscences
  1075. $absences = $connection->executeQuery("SELECT * FROM V_STUDENT_ABSCENCE_QUATER ")->fetchAll();
  1076. $absencesArray = [];
  1077. foreach ($absences as $abs) {
  1078. $absencesArray[$abs['std']] = $abs['abscences'];
  1079. }
  1080. $this->pdf->setTimeout(600);
  1081. $html = $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1082. 'year' => $year,
  1083. 'data' => $dataQuater,
  1084. 'ranks' => $rankArray,
  1085. 'means' => $quaterAvgArray,
  1086. 'abscences' => $absencesArray,
  1087. 'genMean' => $sumAvg / sizeof($quaterAvgArray),
  1088. 'room' => $room,
  1089. 'quater' => $quater,
  1090. 'sequences' => $sequences,
  1091. 'students' => $studentEnrolled,
  1092. 'fileExists'=> $fileExists
  1093. ));
  1094. return new Response(
  1095. $this->pdf->getOutputFromHtml($html),
  1096. 200,
  1097. array(
  1098. 'Content-Type' => 'application/pdf',
  1099. 'Content-Disposition' => 'inline; filename="' . $room->getName() . '.pdf"'
  1100. )
  1101. );
  1102. // return new Response($html);
  1103. }
  1104. /**
  1105. * Finds and displays a ClassRoom entity.
  1106. *
  1107. * @Route("/{id}/reportCardsTrim2024", name="admin_classrooms_reportcards_trim_2024", requirements={"id"="\d+"})
  1108. * @Method("GET")
  1109. * @Template()
  1110. */
  1111. public function reportCardsTrim2024Action(ClassRoom $room, Request $request)
  1112. {
  1113. if (!$this->getUser()) {
  1114. $this->addFlash('warning', 'You need login first!');
  1115. return $this->redirectToRoute('app_login');
  1116. }
  1117. if (!$this->getUser()->isVerified()) {
  1118. $this->addFlash('warning', 'You need to have a verified account!');
  1119. return $this->redirectToRoute('app_login');
  1120. }
  1121. $headerFontSize = $request->request->get('header_font_size');
  1122. $lineHeight = $request->request->get('line_height');
  1123. $copyright = $request->request->get('copyright')=="on";
  1124. $reverse = $request->request->get('reverse')=="on";
  1125. $connection = $this->em->getConnection();
  1126. $year = $this->schoolYearService->sessionYearById();
  1127. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  1128. $students = $this->stdRepo->findEnrolledStudentsThisYearInClass($room, $year);
  1129. $mainTeacher = $this->mainTeacherRepo->findOneBy(array("classRoom" => $room, "schoolYear" => $year))-> getTeacher();
  1130. // Existance des photos d'eleves
  1131. $fileExists = [];
  1132. foreach ($students as $std) {
  1133. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  1134. $fileExists[$std->getId()] = file_exists($filename);
  1135. }
  1136. // Retrieve of marks
  1137. $query = " SELECT DISTINCT student.id as student_id, student.firstname as student_firstname, student.lastname as student_last_name, student.birthday as student_birthday, student.matricule as matricule, 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
  1138. FROM sequence
  1139. JOIN evaluation ON evaluation.sequence_id = sequence.id AND evaluation.class_room_id = :room_id
  1140. JOIN course ON evaluation.course_id = course.id
  1141. JOIN attribution on attribution.course_id = course.id
  1142. JOIN user ON user.id = attribution.teacher_id
  1143. JOIN mark ON evaluation.id = mark.evaluation_id
  1144. JOIN student ON mark.student_id = student.id
  1145. JOIN quater ON sequence.quater_id = quater.id
  1146. JOIN school_year on quater.school_year_id= school_year.id and school_year.id = attribution.year_id
  1147. WHERE quater.id = :quater_id
  1148. ORDER BY student_id, course.id,sequence.id; ";
  1149. $params = [
  1150. 'quater_id' => $quater->getId(),
  1151. 'room_id' => $room->getId(), // Remplace :room_id
  1152. ];
  1153. $result = $connection->executeQuery($query, $params);
  1154. $dataMarks = $result->fetchAllAssociative();
  1155. $dataAbs = $this->getAbsQuater($room, $quater);
  1156. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  1157. // Calculation of rank and general average
  1158. foreach ($sequences as $seq) {
  1159. $this->getViewSeqData2024($room,$seq);
  1160. }
  1161. // CAS DES NOTES TRIMESTRIELLES
  1162. $query =
  1163. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1164. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight
  1165. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1166. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1167. ORDER BY std ";
  1168. $connection->executeQuery($query);
  1169. $statement = $connection->prepare(
  1170. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1171. SELECT DISTINCT std , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1172. FROM V_STUDENT_MARK_QUATER
  1173. GROUP BY std
  1174. ORDER BY SUM(value*weight*coef) DESC"
  1175. );
  1176. $statement->execute();
  1177. $quaterAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  1178. $quaterAvgArray = [];
  1179. $sumAvg = 0;
  1180. $rank = 0;
  1181. $minAgv = 20;
  1182. $maxAvg = 0;
  1183. $rankArray = [];
  1184. foreach ($quaterAvg as $avg) {
  1185. $quaterAvgArray[$avg['std']] = $avg['moyenne'];
  1186. $rankArray[$avg['std']] = ++$rank;
  1187. $sumAvg += $avg['moyenne'];
  1188. if($minAgv > $avg['moyenne']){
  1189. $minAgv = $avg['moyenne'];
  1190. }
  1191. if($maxAvg < $avg['moyenne']){
  1192. $maxAvg = $avg['moyenne'];
  1193. }
  1194. }
  1195. $html = $this->renderView('classroom/reportcard/quaterly_2024.html.twig', array(
  1196. 'genMean' => $sumAvg / sizeof($quaterAvgArray),
  1197. 'ranks' => $rankArray,
  1198. 'year' => $year,
  1199. 'minAvg' => $minAgv,
  1200. 'maxAvg' => $maxAvg,
  1201. 'quater' => $quater,
  1202. 'mainTeacher'=>$mainTeacher,
  1203. 'dataMarks' => $dataMarks,
  1204. 'dataAbs' => $dataAbs,
  1205. 'std' => $std,
  1206. 'students' => $students,
  1207. 'room' => $room,
  1208. 'fileExists' => $fileExists,
  1209. "headerFontSize" => 0.75*$headerFontSize,
  1210. "lineHeight" => 1.5*$lineHeight,
  1211. "copyright" => $copyright,
  1212. "reverse" => $reverse
  1213. ));
  1214. return new Response(
  1215. $this->pdf->getOutputFromHtml($html),
  1216. 200,
  1217. array(
  1218. 'Content-Type' => 'application/pdf',
  1219. 'Content-Disposition' => 'inline; filename="bull_' . $quater->getId().'_'.$std->getMatricule() . '.pdf"'
  1220. )
  1221. );
  1222. }
  1223. /**
  1224. * Finds and displays a ClassRoom entity.
  1225. *
  1226. * @Route("/{id}/annualavglist", name="admin_avg_list", requirements={"id"="\d+"})
  1227. * @Method("GET")
  1228. * @Template()
  1229. */
  1230. public function annualAvgList(ClassRoom $classroom, Request $request)
  1231. {
  1232. $connection = $this->em->getConnection();
  1233. $year = $this->schoolYearService->sessionYearById();
  1234. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  1235. $sequences = $this->seqRepo->findSequenceThisYear($year);
  1236. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  1237. /*******************************************************************************************************************/
  1238. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1239. /*******************************************************************************************************************/
  1240. $i = 1;
  1241. foreach ($sequences as $seq) {
  1242. // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1243. $this->getViewSeqData($classroom, $seq, $i);
  1244. $i++;
  1245. }
  1246. // CAS DES NOTES TRIMESTRIELLES1
  1247. $statement = $connection->prepare(
  1248. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1249. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1250. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1251. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1252. ORDER BY std , modu"
  1253. );
  1254. $statement->execute();
  1255. // CAS DES NOTES TRIMESTRIELLES2
  1256. $statement = $connection->prepare(
  1257. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1258. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1259. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[2]->getId()." seq1
  1260. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[3]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1261. ORDER BY std , modu"
  1262. );
  1263. $statement->execute();
  1264. // CAS DES NOTES TRIMESTRIELLES3
  1265. $statement = $connection->prepare(
  1266. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1267. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1268. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[4]->getId()." seq1
  1269. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[5]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1270. ORDER BY std , modu"
  1271. );
  1272. $statement->execute();
  1273. $statement = $connection->prepare(
  1274. "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1275. SELECT DISTINCT student.id as idStd , student.matricule as matricule
  1276. student.lastname as lastname, student.firstname as firstname
  1277. course.wording as course, course.coefficient as coef,
  1278. module.name as module,
  1279. user.full_name as teacher,
  1280. quat1.std, quat1.modu,
  1281. quat1.value as value1, quat1.weight as weight1,
  1282. quat2.value as value2, quat2.weight as weight2,
  1283. quat3.value as value3, quat3.weight as weight3,
  1284. greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1285. ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1286. FROM student
  1287. JOIN V_STUDENT_MARK_QUATER_1 quat1 ON student.id = quat1.std
  1288. JOIN V_STUDENT_MARK_QUATER_2 quat2 ON student.id = quat2.std AND quat1.crs = quat2.crs
  1289. JOIN V_STUDENT_MARK_QUATER_3 quat3 ON student.id = quat3.std AND quat2.crs = quat3.crs
  1290. JOIN class_room ON class_room.id = quat1.room
  1291. JOIN course ON course.id = quat1.crs
  1292. JOIN module ON course.module_id = quat1.modu
  1293. JOIN user ON user.full_name = quat1.teacher
  1294. ORDER BY quat1.std, quat1.modu
  1295. "
  1296. );
  1297. $statement->execute();
  1298. $dataYear = $connection->executeQuery("SELECT * FROM ANNUAL_DATA ")->fetchAll();
  1299. // For calculating ranks
  1300. $statement = $connection->prepare(
  1301. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1302. SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1303. FROM ANNUAL_DATA
  1304. GROUP BY idStd
  1305. ORDER BY SUM(value*weight*coef) DESC"
  1306. );
  1307. $statement->execute();
  1308. $annualAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  1309. $annualAvgArray = [];
  1310. $sumAvg = 0;
  1311. $rank = 0;
  1312. $rankArray = [];
  1313. foreach ($annualAvg as $avg) {
  1314. $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1315. $rankArray[$avg['idStd']] = ++$rank;
  1316. $sumAvg += $avg['moyenne'];
  1317. }
  1318. $html = $this->renderView('classroom/avglist.html.twig', array(
  1319. 'year' => $year,
  1320. 'room' => $classroom,
  1321. 'students' => $studentEnrolled,
  1322. 'ranks' => $rankArray,
  1323. 'means' => $annualAvgArray,
  1324. 'genMean' => $sumAvg / sizeof($annualAvgArray),
  1325. ));
  1326. return new Response(
  1327. $this->snappy->getOutputFromHtml($html, [
  1328. 'page-size' => 'A4',
  1329. ]),
  1330. 200,
  1331. array(
  1332. 'Content-Type' => 'application/pdf',
  1333. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $classroom->getName() . '.pdf"',
  1334. )
  1335. );
  1336. }
  1337. /**
  1338. * Finds and displays a ClassRoom entity.
  1339. *
  1340. * @Route("/{id}/reportCards3ApcYearApc", name="admin_class_reportcards_3_apc_year", requirements={"id"="\d+"})
  1341. * @Method("GET")
  1342. * @Template()
  1343. */
  1344. public function reportCards3YearAction(ClassRoom $classroom, Request $request)
  1345. {
  1346. $headerFontSize = $request->request->get('header_font_size');
  1347. $lineHeight = $request->request->get('line_height');
  1348. $copyright = $request->request->get('copyright')=="on";
  1349. $reverse = $request->request->get('reverse')=="on";
  1350. $connection = $this->em->getConnection();
  1351. $year = $this->schoolYearService->sessionYearById();
  1352. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  1353. $sequences = $this->seqRepo->findSequenceThisYear($year);
  1354. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYearInClass($classroom, $year);
  1355. // Existance des photos d'eleves
  1356. $fileExists = [];
  1357. foreach ($studentEnrolled as $std) {
  1358. $filename = "assets/images/student/" . $std->getMatricule() . ".jpg";
  1359. $fileExists[$std->getId()] = file_exists($filename);
  1360. }
  1361. /*******************************************************************************************************************/
  1362. /***************CREATION DE la VIEW DES NOTES SEQUENTIELLES, TRIMESTRIELLES DE LA CLASSE, AINSI QUE DE LA VIEW DES ABSCENCES**************/
  1363. /*******************************************************************************************************************/
  1364. $i = 1;
  1365. foreach ($sequences as $seq) {
  1366. // CAS DES NOTES et ABSCENCES SEQUENTIELLES
  1367. $this->getViewSeqData($classroom, $seq, $i);
  1368. $i++;
  1369. }
  1370. // CAS DES NOTES TRIMESTRIELLES1
  1371. $statement = $connection->prepare(
  1372. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_1 AS
  1373. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1374. FROM V_STUDENT_MARK_SEQ1 seq1
  1375. JOIN V_STUDENT_MARK_SEQ2 seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1376. ORDER BY std , modu"
  1377. );
  1378. $statement->execute();
  1379. // CAS DES ABSCENCES TRIMESTRIELLES1
  1380. $statement = $connection->prepare(
  1381. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_1 AS
  1382. SELECT DISTINCT seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1383. FROM V_STUDENT_ABSCENCE_SEQ1 seq1
  1384. JOIN V_STUDENT_ABSCENCE_SEQ2 seq2 ON (seq1.std = seq2.std )
  1385. ORDER BY std "
  1386. );
  1387. $statement->execute();
  1388. // CAS DES NOTES TRIMESTRIELLES2
  1389. $statement = $connection->prepare(
  1390. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_2 AS
  1391. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1392. FROM V_STUDENT_MARK_SEQ3 seq1
  1393. JOIN V_STUDENT_MARK_SEQ4 seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1394. ORDER BY std , modu"
  1395. );
  1396. $statement->execute();
  1397. // CAS DES ABSCENCES TRIMESTRIELLES2
  1398. $statement = $connection->prepare(
  1399. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_2 AS
  1400. SELECT DISTINCT seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1401. FROM V_STUDENT_ABSCENCE_SEQ3 seq1
  1402. JOIN V_STUDENT_ABSCENCE_SEQ4 seq2 ON (seq1.std = seq2.std )
  1403. ORDER BY std "
  1404. );
  1405. $statement->execute();
  1406. // CAS DES NOTES TRIMESTRIELLES3
  1407. $statement = $connection->prepare(
  1408. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER_3 AS
  1409. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight , seq1.teacher as teacher, seq1.module as modu, seq1.room as room
  1410. FROM V_STUDENT_MARK_SEQ5 seq1
  1411. JOIN V_STUDENT_MARK_SEQ6 seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1412. ORDER BY std , modu"
  1413. );
  1414. $statement->execute();
  1415. // CAS DES ABSCENCES TRIMESTRIELLES3
  1416. $statement = $connection->prepare(
  1417. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_QUATER_3 AS
  1418. SELECT DISTINCT seq1.std as std , seq1.total_hours + seq2.total_hours as abscences
  1419. FROM V_STUDENT_ABSCENCE_SEQ5 seq1
  1420. JOIN V_STUDENT_ABSCENCE_SEQ6 seq2 ON (seq1.std = seq2.std )
  1421. ORDER BY std "
  1422. );
  1423. $statement->execute();
  1424. set_time_limit(600);
  1425. $statement = $connection->prepare(
  1426. "CREATE OR REPLACE VIEW ANNUAL_DATA AS
  1427. SELECT DISTINCT student.id as idStd , student.matricule as matricule , student.image_name as profileImagePath,
  1428. student.lastname as lastname, student.firstname as firstname, student.birthday as birthday,
  1429. student.gender as gender,student.birthplace as birthplace ,
  1430. class_room.name as room_name,
  1431. course.wording as course, course.coefficient as coef,
  1432. module.name as module,
  1433. user.full_name as teacher,
  1434. quat1.std, quat1.modu,
  1435. quat1.value as value1, quat1.weight as weight1,
  1436. quat2.value as value2, quat2.weight as weight2,
  1437. quat3.value as value3, quat3.weight as weight3,
  1438. greatest(quat1.weight , quat2.weight, quat3.weight ) as weight,
  1439. ( quat1.value*quat1.weight+ quat2.value*quat2.weight + quat3.value*quat3.weight) /(quat1.weight+quat2.weight+quat3.weight) as value
  1440. FROM student
  1441. JOIN V_STUDENT_MARK_QUATER_1 quat1 ON student.id = quat1.std
  1442. JOIN V_STUDENT_MARK_QUATER_2 quat2 ON student.id = quat2.std AND quat1.crs = quat2.crs
  1443. JOIN V_STUDENT_MARK_QUATER_3 quat3 ON student.id = quat3.std AND quat2.crs = quat3.crs
  1444. JOIN class_room ON class_room.id = quat1.room
  1445. JOIN course ON course.id = quat1.crs
  1446. JOIN module ON course.module_id = quat1.modu
  1447. JOIN user ON user.full_name = quat1.teacher
  1448. ORDER BY quat1.std, quat1.modu
  1449. "
  1450. );
  1451. $statement->execute();
  1452. $dataYear = $connection->executeQuery("SELECT * FROM ANNUAL_DATA ")->fetchAll();
  1453. // For calculating ranks
  1454. $statement = $connection->prepare(
  1455. " CREATE OR REPLACE VIEW V_STUDENT_RANKS AS
  1456. SELECT DISTINCT idStd , CAST( SUM(value*weight*coef) / sum(weight*coef) AS decimal(4,2)) as moyenne, sum(weight*coef) as totalCoef
  1457. FROM ANNUAL_DATA
  1458. GROUP BY idStd
  1459. ORDER BY SUM(value*weight*coef) DESC"
  1460. );
  1461. $statement->execute();
  1462. $annualAvg = $connection->executeQuery("SELECT * FROM V_STUDENT_RANKS ")->fetchAll();
  1463. $annualAvgArray = [];
  1464. $sumAvg = 0;
  1465. $rank = 0;
  1466. $rankArray = [];
  1467. foreach ($annualAvg as $avg) {
  1468. $annualAvgArray[$avg['idStd']] = $avg['moyenne'];
  1469. $rankArray[$avg['idStd']] = ++$rank;
  1470. $sumAvg += $avg['moyenne'];
  1471. }
  1472. // CAS DES ABSCENCES ANNUELLES
  1473. $statement = $connection->prepare(
  1474. " CREATE OR REPLACE VIEW V_STUDENT_ABSCENCE_ANNUAL AS
  1475. SELECT DISTINCT q1.std as std , q1.abscences + q2.abscences + q3.abscences as abscences
  1476. FROM V_STUDENT_ABSCENCE_QUATER_1 q1
  1477. JOIN V_STUDENT_ABSCENCE_QUATER_2 q2 ON (q1.std = q2.std )
  1478. JOIN V_STUDENT_ABSCENCE_QUATER_3 q3 ON (q1.std = q3.std )
  1479. ORDER BY std "
  1480. );
  1481. $statement->execute();
  1482. // Traitement des abscences
  1483. $absences = $connection->executeQuery("SELECT * FROM V_STUDENT_ABSCENCE_ANNUAL ")->fetchAll();
  1484. $absencesArray = [];
  1485. foreach ($absences as $abs) {
  1486. $absencesArray[$abs['std']] = $abs['abscences'];
  1487. }
  1488. $html = $this->renderView('classroom/reportcard/annual.html.twig', array(
  1489. "headerFontSize" => $headerFontSize,
  1490. "lineHeight" => $lineHeight,
  1491. "copyright" => $copyright,
  1492. "reverse" => $reverse,
  1493. 'year' => $year,
  1494. 'data' => $dataYear,
  1495. 'room' => $classroom,
  1496. 'students' => $studentEnrolled,
  1497. 'abscences' => $absencesArray,
  1498. 'ranks' => $rankArray,
  1499. 'means' => $annualAvgArray,
  1500. 'genMean' => $sumAvg / sizeof($annualAvgArray),
  1501. 'fileExists'=> $fileExists
  1502. ));
  1503. return new Response(
  1504. $this->snappy->getOutputFromHtml($html, [
  1505. 'page-size' => 'A4',
  1506. ]),
  1507. 200,
  1508. array(
  1509. 'Content-Type' => 'application/pdf',
  1510. 'Content-Disposition' => 'attachment; filename="BUL_ANN_' . $classroom->getName() . '.pdf"',
  1511. )
  1512. );
  1513. }
  1514. public function getStudentQuaterMark(Array $std,Course $crs){
  1515. foreach ($this->quaterData as $data) {
  1516. if($std["id"] == $data["std"] && $crs->getId() == $data["crs"] ){
  1517. return ["seq1"=>$data["value1"], "weight1"=>$data["weight1"], "seq2"=>$data["value2"],"weight2"=>$data["weight2"],"coef"=>$data["coef"] ];
  1518. }
  1519. }
  1520. return null;
  1521. }
  1522. public function getViewQuaterData2024(ClassRoom $room,Quater $quater){
  1523. $em = $this->getDoctrine()->getManager();
  1524. $year = $this->schoolYearService->sessionYearById();
  1525. $connection = $this->em->getConnection();
  1526. $sequences = $this->seqRepo->findBy(array("quater" => $quater));
  1527. foreach ($sequences as $seq) {
  1528. $this->getViewSeqData2024($room,$seq );
  1529. }
  1530. $query =
  1531. " CREATE OR REPLACE VIEW V_STUDENT_MARK_QUATER AS
  1532. SELECT DISTINCT seq1.std as std , seq1.crs as crs , seq1.coef as coef, seq1.value as value1, seq1.weight as weight1,seq2.value as value2, seq2.weight as weight2, (seq1.value*seq1.weight + seq2.value*seq2.weight)/(seq1.weight+seq2.weight) as value, greatest(seq1.weight , seq2.weight ) as weight
  1533. FROM V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[0]->getId()." seq1
  1534. JOIN V_STUDENT_MARK_SEQ".$room->getId()."_".$sequences[1]->getId()." seq2 ON (seq1.std = seq2.std AND seq1.crs = seq2.crs )
  1535. ORDER BY std ";
  1536. $connection->executeQuery($query);
  1537. $query = "SELECT * FROM V_STUDENT_MARK_QUATER";
  1538. $this->quaterData = $connection->fetchAllAssociative($query);
  1539. }
  1540. /**
  1541. * Finds and displays a ClassRoom entity.
  1542. *
  1543. * @Route("/{id}/recapitulatiftrim", name="admin_classrooms_recapitulatif_trim", requirements={"id"="\d+"})
  1544. * @Method("GET")
  1545. * @Template()
  1546. */
  1547. public function recapTrimAction(ClassRoom $room, Request $request)
  1548. {
  1549. $checkedValues = $request->request->get('selected_courses');
  1550. set_time_limit(600);
  1551. $em = $this->getDoctrine()->getManager();
  1552. $year = $this->schoolYearService->sessionYearById();
  1553. $connection = $this->em->getConnection();
  1554. $quater = $this->qtRepo->findOneBy(array("activated" => true));
  1555. $studentEnrolled = $this->stdRepo->findEnrolledStudentsThisYear($room, $year->getId());
  1556. $this->getViewQuaterData2024($room, $quater);
  1557. $result = [];
  1558. foreach ($studentEnrolled as $std) { // Parcourir les étudiants inscrits
  1559. $result[$std["id"]] = []; // Initialiser un sous-tableau pour chaque étudiant
  1560. foreach ($room->getModules() as $module) { // Parcourir les modules de la salle
  1561. foreach ($module->getCourses() as $crs) {
  1562. if(in_array($crs->getId(), $checkedValues))
  1563. {
  1564. // Collecter les note de chaque combinaison étudiant/module
  1565. $result[$std["id"]][$crs->getId()] = $this->getStudentQuaterMark($std, $crs); // Remplacer 'null' par la donnée que vous voulez associer
  1566. }
  1567. }
  1568. }
  1569. }
  1570. $mainTeacher = $this->mainTeacherRepo->findOneBy(array("classRoom" => $room, "schoolYear" => $year))-> getTeacher();
  1571. $options = [
  1572. 'orientation' => 'Landscape', // Spécifie l'orientation paysage
  1573. 'page-size' => 'A4', // Taille de page A4
  1574. 'margin-top' => '10mm', // Marges pour personnaliser l'apparence
  1575. 'margin-bottom' => '10mm',
  1576. 'margin-left' => '10mm',
  1577. 'margin-right' => '10mm'
  1578. ];
  1579. $html = $this->renderView('classroom/recapitulatiftrimWithMoy.html.twig', array(
  1580. 'year' => $year,
  1581. 'datas' => $result,
  1582. 'room' => $room,
  1583. 'quater' => $quater,
  1584. 'checkedValues'=>$checkedValues,
  1585. 'students' => $studentEnrolled,
  1586. 'mainTeacher' => $mainTeacher
  1587. ));
  1588. return new Response(
  1589. $this->pdf->getOutputFromHtml($html, $options),
  1590. 200,
  1591. array(
  1592. 'Content-Type' => 'application/pdf',
  1593. 'Content-Disposition' => 'inline; filename="recap_trim' . $quater->getId().'_'.$room->getName() . '.pdf"'
  1594. )
  1595. );
  1596. }
  1597. public function officialExam()
  1598. {
  1599. // Retrieve student categories from the corresponding repository
  1600. $categoriesStudent = $this->getDoctrine()->getRepository(CategStudent::class)->findAll();
  1601. // Initialize arrays for student categories, mentions, and counters
  1602. $studentCategories = [];
  1603. $mentionCategories = [];
  1604. $studentCountCategories = [];
  1605. $mentionCountCategories = [];
  1606. // Fill the arrays with data from student categories
  1607. foreach ($categoriesStudent as $category) {
  1608. $studentCategories[] = $category->getName();
  1609. $mentionCategories[] = $category->getMention();
  1610. $studentCountCategories[] = $category->getCountStudent();
  1611. $mentionCountCategories[] = $category->getCountMention();
  1612. }
  1613. // Render the Twig template and pass the data in JSON format
  1614. return $this->render('admin/class_room/show.html.twig', [
  1615. 'studentCategories' => json_encode($studentCategories),
  1616. 'mentionCategories' => json_encode($mentionCategories),
  1617. 'studentCountCategories' => json_encode($studentCountCategories),
  1618. 'mentionCountCategories' => json_encode($mentionCountCategories),
  1619. ]);
  1620. }
  1621. /**
  1622. * @Route("/classroom/insolvents", name="admin_classroom_insolvents")
  1623. */
  1624. public function listInsolventStudents(): Response
  1625. {
  1626. $year = $this->schoolYearService->sessionYearById();
  1627. $paymentPlan = $year->getPaymentPlan();
  1628. // List of student subscriptions for the class
  1629. $subscriptions = $this->subRepo->findBy(array("schoolYear" => $year), array("classRoom"=>"ASC"));
  1630. $insolventSub = [];
  1631. foreach($subscriptions as $sub){
  1632. if($year->paymentThresholdAmount($sub->getClassRoom()) > $sub->getStudent()->getPaymentsSum($year) ){
  1633. $insolventSub[] = $sub;
  1634. }
  1635. }
  1636. $html = $this->render('school_year/templating/insolvent_students_list.html.twig', [
  1637. 'students' => $insolventSub,
  1638. 'year' => $year,
  1639. ]);
  1640. return new Response(
  1641. $this->pdf->getOutputFromHtml($html),
  1642. 200,
  1643. array(
  1644. 'Content-Type' => 'application/pdf',
  1645. 'Content-Disposition' => 'inline; filename="insolvent_student_' . $year->getCode() . '.pdf"'
  1646. )
  1647. );
  1648. }
  1649. /**
  1650. * @Route("/classroom/{id}", name="class_room_stats")
  1651. */
  1652. public function showClassRoomStats(ClassRoomRepository $classRoomRepository, ClassRoom $room): Response
  1653. {
  1654. $classRoom = $classRoomRepository->find($id);
  1655. $successfulCount = $classRoomRepository->countSuccessfulStudentsForClass($classRoom);
  1656. $unsuccessfulCount = $classRoomRepository->countUnsuccessfulStudentsForClass($classRoom);
  1657. $mentionStatistics = $classRoomRepository->getMentionStatisticsForClass($classRoom);
  1658. return $this->render('class_room/stats.html.twig', [
  1659. 'classRoom' => $classRoom,
  1660. 'successfulCount' => $successfulCount,
  1661. 'unsuccessfulCount' => $unsuccessfulCount,
  1662. 'mentionStatistics' => $mentionStatistics,
  1663. ]);
  1664. }
  1665. /**
  1666. * @Route("/classroom/{id}/insolvent", name="admin_classroom_insolvent")
  1667. */
  1668. public function listInsolventStudentsByRoom(ClassRoom $room): Response
  1669. {
  1670. $year = $this->schoolYearService->sessionYearById();
  1671. $paymentPlan = $year->getPaymentPlan();
  1672. // List of student subscriptions for the class
  1673. $subscriptions = $this->subRepo->findBy(array("schoolYear" => $year, "classRoom" => $room));
  1674. $students = [];
  1675. $dueAmounts = [];
  1676. foreach($subscriptions as $sub){
  1677. if($year->paymentThresholdAmount($room) > $sub->getStudent()->getPaymentsSum($year) ){
  1678. $students[] = $sub->getStudent() ;
  1679. $dueAmounts[$sub->getStudent()->getId()] = $year->paymentThresholdAmount($room)-$sub->getStudent()->getPaymentsSum($year);
  1680. }
  1681. }
  1682. $html = $this->render('classroom/templating/insolvent_student_list.html.twig', [
  1683. 'room' => $room,
  1684. 'students' => $students,
  1685. 'year' => $year,
  1686. 'amounts' => $dueAmounts
  1687. ]);
  1688. return new Response(
  1689. $this->pdf->getOutputFromHtml($html),
  1690. 200,
  1691. array(
  1692. 'Content-Type' => 'application/pdf',
  1693. 'Content-Disposition' => 'inline; filename="insolvent_student_' . $room->getName() . '.pdf"'
  1694. )
  1695. );
  1696. }
  1697. /**
  1698. * @Route("/insolventspercentage", name="admin_classroom_insolvents_percentage")
  1699. */
  1700. public function insolventStudentsRate(): Response
  1701. {
  1702. $year = $this->schoolYearService->sessionYearById();
  1703. $paymentPlan = $year->getPaymentPlan();
  1704. $rooms = $this->repo->findAll();
  1705. $rates = [];
  1706. foreach($rooms as $room){
  1707. $subscriptions = $this->subRepo->findBy(array("schoolYear" => $year, "classRoom" => $room));
  1708. $installments = $this->instRepo->findBy(array("classRoom" => $room, "paymentPlan" => $paymentPlan));
  1709. $sum = 0;
  1710. foreach($installments as $installment){
  1711. $sum += $installment->getAmount();
  1712. }
  1713. $ratesByRoom = [];
  1714. foreach($subscriptions as $sub){
  1715. $ratesByRoom[] = 100*$sub->getStudent()->getPaymentsSum($year) / $sum;
  1716. }
  1717. // Calculer la somme des valeurs entières
  1718. $sum = array_sum($ratesByRoom);
  1719. // Calculer la moyenne
  1720. $avg = count($ratesByRoom) > 0 ? $sum / count($ratesByRoom) : 0;
  1721. $rates[$room->getName()] = $avg ;
  1722. }
  1723. $html = $this->render('school_year/templating/recovery_rates_by_room.html.twig', [
  1724. 'rates' => $rates,
  1725. 'year' => $year,
  1726. ]);
  1727. return new Response(
  1728. $this->pdf->getOutputFromHtml($html),
  1729. 200,
  1730. array(
  1731. 'Content-Type' => 'application/pdf',
  1732. 'Content-Disposition' => 'inline; filename="insolvent_student_' . $year->getCode() . '.pdf"'
  1733. )
  1734. );
  1735. }
  1736. }