src/Controller/SchoolController.php line 135

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. return $this->render('school/index.html.twig', [
  99. 'results' => $results,
  100. 'year' => $year
  101. ]);
  102. }
  103. /**
  104. * HELP.
  105. *
  106. * @Route("/help", name="app_help")
  107. * @Method("GET")
  108. * @Template()
  109. */
  110. public function helpAction()
  111. {
  112. return $this->render('school/help.html.twig');
  113. }
  114. /**
  115. * Lists all User entities.
  116. *
  117. * @Route("/teachers", name="app_teachers")
  118. * @Method("GET")
  119. * @Template()
  120. */
  121. public function teacherListAction()
  122. {
  123. $year = $this->scRepo->findOneBy(array("activated" => true));
  124. $users = $this->userRepo->findAllOfCurrentYear($year);
  125. return $this->render('school/teacher.html.twig', compact("users"));
  126. }
  127. /**
  128. * Lists all User entities.
  129. *
  130. * @Route("/rooms", name="app_rooms")
  131. * @Method("GET")
  132. * @Template()
  133. */
  134. public function roomListAction(PaginatorInterface $paginator, Request $request)
  135. {
  136. $year_before = $this->scRepo->findOneBy(array("activated" => true));
  137. $year = $this->scRepo->findOneBy(array("id" => $year_before->getId() - 1));
  138. $mainTeachers = $this->mainTeacherRepo->findBy(array("schoolYear" => $year));
  139. $mainTeachersMap = array();
  140. foreach($mainTeachers as $mt){
  141. $mainTeachersMap[$mt->getClassRoom()->getId()] = $mt->getTeacher();
  142. }
  143. $entities = $this->rmRepo->findAll();
  144. $subscriptions = $this->subRepo->findEnrollementThisYear($year);
  145. $rooms = $paginator->paginate($entities, $request->query->get('page', 1), ClassRoom::NUM_ITEMS_PER_PAGE);
  146. $rooms->setCustomParameters([
  147. 'position' => 'centered',
  148. 'size' => 'large',
  149. 'rounded' => true,
  150. ]);
  151. return $this->render('school/roomList.html.twig', compact("rooms", "year", "subscriptions", "mainTeachersMap"));
  152. }
  153. /**
  154. * Finds and displays a Section entity.
  155. *
  156. * @Route("/{roomId}/exam", name="official_exam", requirements={"id"="\d+"})
  157. * @Method("GET")
  158. * @Template()
  159. */
  160. public function callOffialExam(int $roomId, OfficialExamService $officialExamService)
  161. {
  162. $rate = $officialExamService->successRate($roomId);
  163. $subscriptions = $officialExamService->subscriptions($roomId);
  164. return $this->render('school/roomList.html.twig', [
  165. 'rate' => $rate,
  166. 'subscriptions' => $subscriptions
  167. ]);
  168. }
  169. /**
  170. * @Route("/staff", name="app_staff")
  171. */
  172. public function staffAction(Request $request)
  173. {
  174. $qb = $this->em->createQueryBuilder();
  175. $qb->select('u')->from('App:User', 'u')->where('u.roles LIKE :roles')->setParameter('roles', '%"' . "ROLE_ADMIN" . '"%');
  176. $users = $qb->getQuery()->getResult();
  177. //$users = $this->userRepo->findByRoles("ROLE_ADMIN");
  178. return $this->render('school/staff.html.twig', compact("users"));
  179. }
  180. /**
  181. * @Route("/update_school_year", name="update_school_year", methods={"POST"})
  182. */
  183. public function updateSessionValue(Request $request)
  184. {
  185. $selectedSchoolYear = $request->request->get('selectedSchoolYear');
  186. // Update session with the selected value
  187. $session = $request->getSession();
  188. $session->set('session_school_year', $selectedSchoolYear);
  189. return new Response('Session updated', 200);
  190. }
  191. }