src/Controller/Registration/StudentDashboardController.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Registration;
  3. use App\Entity\User;
  4. use App\Entity\SettingClassroom;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use App\Repository\SettingClassroomRepository;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use App\Repository\RegistrationStudentRepository;
  10. use App\Repository\RegistrationStudentRegistrationRepository;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. /**
  13.  * @Route("/student/dashboard")
  14.  */
  15. class StudentDashboardController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/index", name="student_dashboard_index")
  19.      */
  20.     public function index(SettingClassroomRepository $settingClassroomRepository): Response
  21.     {
  22.         /**@var User $user */
  23.         $user $this->getUser();
  24.         $schoolYear $user->getSchoolYear();
  25.         $establishment $this->getUser()->getEstablishment();
  26.         $setting_classrooms 
  27.             $settingClassroomRepository->createQueryBuilder('entity')
  28.             ->andWhere('entity.establishment = :establishment')
  29.             ->setParameter('establishment'$establishment)
  30.             ->andWhere('entity.schoolYear = :schoolYear')
  31.             ->setParameter('schoolYear'$schoolYear)
  32.             ->orderBy('entity.id''DESC')
  33.             ->getQuery()
  34.             ->getResult();
  35.         return $this->render('registration/student_dashboard/index.html.twig', [
  36.             'setting_classrooms' => $setting_classrooms,
  37.             'school_year' => $schoolYear
  38.         ]);
  39.     }
  40.     /**
  41.      * @Route("/api/get-count", name="api_student_dashboard_get_count", methods={"GET"})
  42.     */
  43.     public function apiGetCount(SettingClassroomRepository $settingClassroomRepositoryRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
  44.         /**@var User $user */
  45.         $user $this->getUser();
  46.         $schoolYear $user->getSchoolYear();
  47.         $establishment $this->getUser()->getEstablishment();
  48.         $countClassroom count($settingClassroomRepository->createQueryBuilder('entity')
  49.             ->andWhere('entity.establishment = :establishment')
  50.             ->setParameter('establishment'$establishment)
  51.             ->andWhere('entity.schoolYear = :schoolYear')
  52.             ->setParameter('schoolYear'$schoolYear)
  53.             ->orderBy('entity.id''DESC')
  54.             ->getQuery()
  55.             ->getResult());
  56.         $countRegisteredWithoutBirthCertificate count($registrationStudentRegistrationRepository->createQueryBuilder('entity')
  57.             ->andWhere('entity.establishment = :establishment')
  58.             ->setParameter('establishment'$establishment)
  59.             ->innerJoin('entity.student''student')
  60.             ->addSelect('student')
  61.             ->andWhere('entity.schoolYear = :schoolYear')
  62.             ->setParameter('schoolYear'$schoolYear)
  63.             ->andWhere('student.birth_certificate_number is null')
  64.             //->setParameter('birth_certificate_number', 1)
  65.             ->orderBy('entity.id''DESC')
  66.             ->getQuery()
  67.             ->getResult());
  68.         $countRegistered count($registrationStudentRegistrationRepository->createQueryBuilder('entity')
  69.             ->andWhere('entity.establishment = :establishment')
  70.             ->setParameter('establishment'$establishment)
  71.             ->andWhere('entity.schoolYear = :schoolYear')
  72.             ->setParameter('schoolYear'$schoolYear)
  73.             ->orderBy('entity.id''DESC')
  74.             ->getQuery()
  75.             ->getResult());
  76.         return $this->json([
  77.             'code' => 200
  78.             'message' => "found :)",
  79.             'countClassroom' => $countClassroom,
  80.             'countRegistered' => number_format($countRegistered,0,','' '),
  81.             'countRegisteredWithoutBirthCertificate' => number_format($countRegisteredWithoutBirthCertificate,0,','' '),
  82.             ], 
  83.         200);
  84.     }
  85.     /**
  86.      * @Route("/classroom/{id}/registered", name="student_dashboard_registereds_by_classroom", methods={"GET"})
  87.     */
  88.     public function classroomRegistereds(SettingClassroom $settingClassroom): Response
  89.     {
  90.         /**@var User $user */
  91.         $user $this->getUser();
  92.         $schoolYear $user->getSchoolYear();
  93.         $establishment $this->getUser()->getEstablishment();
  94.         $registereds $settingClassroom->getRegistereds($schoolYear);
  95.         return $this->render('registration/student_dashboard/registeredsByClassroom.html.twig', [
  96.             'setting_classroom' => $settingClassroom,
  97.             'registereds' => $registereds,
  98.             'school_year' => $schoolYear
  99.         ]);
  100.     }
  101.     /**
  102.      * @Route("/api/set-birth-certificate_number", name="api_student_birth_certificate_number", methods={"GET"})
  103.     */
  104.     public function api_edit_name(Request $requestRegistrationStudentRepository $registrationStudentRepository){
  105.         $entityManager $this->getDoctrine()->getManager();
  106.         if (strlen($request->get('birthCertificateNumber')) <= 3) {
  107.             return $this->json(['code' => 500'message' => "N° extrait invalide"], 200);
  108.         }
  109.         $registrationStudentRegistration $registrationStudentRepository->findOneBy(['id' => $request->get('id')]);
  110.         if (null != $registrationStudentRegistration) {
  111.             $registrationStudentRegistration->setBirthCertificateNumber($request->get('birthCertificateNumber'));
  112.             
  113.         }
  114.         try {
  115.             $entityManager->flush();
  116.             return $this->json(['code' => 200'message' => "N° extrait modifié."], 200);
  117.         } catch (\Throwable $th) {
  118.             //$th->getMessage()
  119.             //return $this->json(['code' => 500, 'message' => $th->getMessage()], 200);
  120.         }
  121.         return $this->json(['code' => 500'message' => "Une erreur s'est produite lors de la modification du N° extrait."], 200);
  122.     }
  123.     /**
  124.      * @Route("/registereds-without-birth-certificate", name="student_dashboard_registereds_without_birth_certificate", methods={"GET"})
  125.     */
  126.     public function registeredsWithoutBirthCertificate(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  127.     {
  128.         /**@var User $user */
  129.         $user $this->getUser();
  130.         $schoolYear $user->getSchoolYear();
  131.         $establishment $this->getUser()->getEstablishment();
  132.         $registereds $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  133.             ->andWhere('entity.establishment = :establishment')
  134.             ->setParameter('establishment'$establishment)
  135.             ->innerJoin('entity.student''student')
  136.             ->addSelect('student')
  137.             ->andWhere('entity.schoolYear = :schoolYear')
  138.             ->setParameter('schoolYear'$schoolYear)
  139.             ->andWhere('student.birth_certificate_number is null')
  140.             //->setParameter('birth_certificate_number', 1)
  141.             ->orderBy('entity.id''DESC')
  142.             ->getQuery()
  143.             ->getResult();
  144.         return $this->render('registration/student_dashboard/registeredsWithoutBirthCertificate.html.twig', [
  145.             'registereds' => $registereds,
  146.             'school_year' => $schoolYear
  147.         ]);
  148.     }
  149. }