src/Controller/ClassRoomController.php line 1225

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