src/Controller/SchoolController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ClassRoom;
  4. use App\Repository\UserRepository;
  5. use App\Repository\ClassRoomRepository;
  6. use App\Repository\SchoolYearRepository;
  7. use App\Repository\SubscriptionRepository;
  8. use App\Service\OfficialExamService;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Knp\Component\Pager\PaginatorInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use App\Service\SchoolYearService;
  18. use App\Repository\MainTeacherRepository;
  19. /**
  20. * User controller.
  21. *
  22. * @Route("/")
  23. */
  24. class SchoolController extends AbstractController
  25. {
  26. private $em;
  27. private $userRepo;
  28. private $rmRepo;
  29. private $scRepo;
  30. private $subRepo;
  31. private SchoolYearService $schoolYearService;
  32. private MainTeacherRepository $mainTeacherRepo;
  33. public function __construct(MainTeacherRepository $mainTeacherRepo,SchoolYearService $schoolYearService,EntityManagerInterface $em, UserRepository $userRepo, SchoolYearRepository $scRepo, ClassRoomRepository $rmRepo, SubscriptionRepository $subRepo)
  34. {
  35. $this->em = $em;
  36. $this->userRepo = $userRepo;
  37. $this->scRepo = $scRepo;
  38. $this->rmRepo = $rmRepo;
  39. $this->subRepo = $subRepo;
  40. $this->schoolYearService = $schoolYearService;
  41. $this->mainTeacherRepo = $mainTeacherRepo;
  42. }
  43. /**
  44. * @Route("/", name="app_home")
  45. */
  46. public function index(): Response
  47. {
  48. $rooms = $this->rmRepo->findBy(array("apc" => true), array("level" => "ASC"));
  49. $year_before = $this->scRepo->findOneBy(array("activated" => true));
  50. $year = $this->scRepo->findOneBy(array("id" => $year_before->getId()));
  51. $results = [];
  52. foreach ($rooms as $room) {
  53. $officialExamResults = $this->subRepo->countByMention($year, $room);
  54. $mentionCategories = [];
  55. $mentionCountCategories = [];
  56. foreach ($officialExamResults as $exam) {
  57. switch ($exam["officialExamResult"]) {
  58. case "0":
  59. $mentionCategories[] = "ECHEC";
  60. break;
  61. case "1p":
  62. $mentionCategories[] = "SUCCESS";
  63. break;
  64. case "1a":
  65. $mentionCategories[] = "ASSEZ-BIEN";
  66. break;
  67. case "1b":
  68. $mentionCategories[] = "BIEN";
  69. break;
  70. case "1t":
  71. $mentionCategories[] = "TRES-BIEN";
  72. break;
  73. case "1e":
  74. $mentionCategories[] = "EXCELLENT";
  75. break;
  76. case "A":
  77. $mentionCategories[] = "5 POINTS";
  78. break;
  79. case "B":
  80. $mentionCategories[] = "4 POINTS";
  81. break;
  82. case "C":
  83. $mentionCategories[] = "3 POINTS";
  84. break;
  85. case "D":
  86. $mentionCategories[] = "2 POINTS";
  87. break;
  88. case "E":
  89. $mentionCategories[] = "1 POINT";
  90. break;
  91. }
  92. $mentionCountCategories[] = $exam["count"];
  93. }
  94. $couple["mentionCategories"] = $mentionCategories;
  95. $couple["mentionCountCategories"] = $mentionCountCategories;
  96. $results[str_replace(' ', '', strtolower($room->getName()))] = json_encode($couple);
  97. }
  98. // dd($results);
  99. return $this->render('school/index.html.twig', compact("results"));
  100. }
  101. /**
  102. * HELP.
  103. *
  104. * @Route("/help", name="app_help")
  105. * @Method("GET")
  106. * @Template()
  107. */
  108. public function helpAction()
  109. {
  110. return $this->render('school/help.html.twig');
  111. }
  112. /**
  113. * Lists all User entities.
  114. *
  115. * @Route("/teachers", name="app_teachers")
  116. * @Method("GET")
  117. * @Template()
  118. */
  119. public function teacherListAction()
  120. {
  121. $year = $this->scRepo->findOneBy(array("activated" => true));
  122. $users = $this->userRepo->findAllOfCurrentYear($year);
  123. return $this->render('school/teacher.html.twig', compact("users"));
  124. }
  125. /**
  126. * Lists all User entities.
  127. *
  128. * @Route("/rooms", name="app_rooms")
  129. * @Method("GET")
  130. * @Template()
  131. */
  132. public function roomListAction(PaginatorInterface $paginator, Request $request)
  133. {
  134. $year_before = $this->scRepo->findOneBy(array("activated" => true));
  135. $year = $this->scRepo->findOneBy(array("id" => $year_before->getId() - 1));
  136. $mainTeachers = $this->mainTeacherRepo->findBy(array("schoolYear" => $year));
  137. $mainTeachersMap = array();
  138. foreach($mainTeachers as $mt){
  139. $mainTeachersMap[$mt->getClassRoom()->getId()] = $mt->getTeacher();
  140. }
  141. $entities = $this->rmRepo->findAll();
  142. $subscriptions = $this->subRepo->findEnrollementThisYear($year);
  143. $rooms = $paginator->paginate($entities, $request->query->get('page', 1), ClassRoom::NUM_ITEMS_PER_PAGE);
  144. $rooms->setCustomParameters([
  145. 'position' => 'centered',
  146. 'size' => 'large',
  147. 'rounded' => true,
  148. ]);
  149. return $this->render('school/roomList.html.twig', compact("rooms", "year", "subscriptions", "mainTeachersMap"));
  150. }
  151. /**
  152. * Finds and displays a Section entity.
  153. *
  154. * @Route("/{roomId}/exam", name="official_exam", requirements={"id"="\d+"})
  155. * @Method("GET")
  156. * @Template()
  157. */
  158. public function callOffialExam(int $roomId, OfficialExamService $officialExamService)
  159. {
  160. $rate = $officialExamService->successRate($roomId);
  161. $subscriptions = $officialExamService->subscriptions($roomId);
  162. return $this->render('school/roomList.html.twig', [
  163. 'rate' => $rate,
  164. 'subscriptions' => $subscriptions
  165. ]);
  166. }
  167. /**
  168. * @Route("/staff", name="app_staff")
  169. */
  170. public function staffAction(Request $request)
  171. {
  172. $qb = $this->em->createQueryBuilder();
  173. $qb->select('u')->from('App:User', 'u')->where('u.roles LIKE :roles')->setParameter('roles', '%"' . "ROLE_ADMIN" . '"%');
  174. $users = $qb->getQuery()->getResult();
  175. //$users = $this->userRepo->findByRoles("ROLE_ADMIN");
  176. return $this->render('school/staff.html.twig', compact("users"));
  177. }
  178. /**
  179. * @Route("/update_school_year", name="update_school_year", methods={"POST"})
  180. */
  181. public function updateSessionValue(Request $request)
  182. {
  183. $selectedSchoolYear = $request->request->get('selectedSchoolYear');
  184. // Update session with the selected value
  185. $session = $request->getSession();
  186. $session->set('session_school_year', $selectedSchoolYear);
  187. return new Response('Session updated', 200);
  188. }
  189. }