src/Controller/SchoolController.php line 120

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 $emUserRepository $userRepoSchoolYearRepository $scRepoClassRoomRepository $rmRepoSubscriptionRepository $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.        
  53.         foreach ($rooms as $room) {
  54.             $officialExamResults $this->subRepo->countByMention($year$room);
  55.             $mentionCategories = [];
  56.             $mentionCountCategories = [];
  57.             foreach ($officialExamResults as $exam) {
  58.                 switch ($exam["officialExamResult"]) {
  59.                     case  "0":
  60.                         $mentionCategories[] = "ECHEC";
  61.                         break;
  62.                     case  "1p":
  63.                         $mentionCategories[] = "SUCCESS";
  64.                         break;
  65.                     case  "1a":
  66.                         $mentionCategories[] = "ASSEZ-BIEN";
  67.                         break;
  68.                     case  "1b":
  69.                         $mentionCategories[] = "BIEN";
  70.                         break;
  71.                     case  "1t":
  72.                         $mentionCategories[] = "TRES-BIEN";
  73.                         break;
  74.                     case  "1e":
  75.                         $mentionCategories[] = "EXCELLENT";
  76.                         break;
  77.                     case  "A":
  78.                         $mentionCategories[] = "5 POINTS";
  79.                         break;
  80.                     case  "B":
  81.                         $mentionCategories[] = "4 POINTS";
  82.                         break;
  83.                     case  "C":
  84.                         $mentionCategories[] = "3 POINTS";
  85.                         break;
  86.                     case  "D":
  87.                         $mentionCategories[] = "2 POINTS";
  88.                         break;
  89.                     case  "E":
  90.                         $mentionCategories[] = "1 POINT";
  91.                         break;
  92.                 }
  93.                 $mentionCountCategories[] = $exam["count"];
  94.             }
  95.             $couple["mentionCategories"] = $mentionCategories;
  96.             $couple["mentionCountCategories"] = $mentionCountCategories;
  97.             $results[str_replace(' '''strtolower($room->getName()))] = json_encode($couple);
  98.         }
  99.         // dd($results);
  100.         return $this->render('school/index.html.twig'compact("results"));
  101.     }
  102.     /**
  103.      * HELP.
  104.      *
  105.      * @Route("/help", name="app_help")
  106.      * @Method("GET")
  107.      * @Template()
  108.      */
  109.     public function helpAction()
  110.     {
  111.         return $this->render('school/help.html.twig');
  112.     }
  113.     /**
  114.      * Lists all User entities.
  115.      *
  116.      * @Route("/teachers", name="app_teachers")
  117.      * @Method("GET")
  118.      * @Template()
  119.      */
  120.     public function teacherListAction()
  121.     {
  122.         $year $this->scRepo->findOneBy(array("activated" => true));
  123.         $users $this->userRepo->findAllOfCurrentYear($year);
  124.         return $this->render('school/teacher.html.twig'compact("users"));
  125.     }
  126.     /**
  127.      * Lists all User entities.
  128.      *
  129.      * @Route("/rooms", name="app_rooms")
  130.      * @Method("GET")
  131.      * @Template()
  132.      */
  133.     public function roomListAction(PaginatorInterface $paginator,  Request $request)
  134.     {
  135.         $year_before $this->scRepo->findOneBy(array("activated" => true));
  136.         $year $this->scRepo->findOneBy(array("id" => $year_before->getId() - 1));
  137.         $mainTeachers =  $this->mainTeacherRepo->findBy(array("schoolYear" => $year));
  138.         $mainTeachersMap = array();
  139.         foreach($mainTeachers as $mt){
  140.             $mainTeachersMap[$mt->getClassRoom()->getId()] = $mt->getTeacher();
  141.         }
  142.         $entities $this->rmRepo->findAll();
  143.       
  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 $roomIdOfficialExamService $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. }