src/Controller/School/SchoolTeacherController.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Controller\School;
  3. use Knp\Snappy\Pdf;
  4. use App\Entity\User;
  5. use App\Entity\RhSalary;
  6. use App\Entity\SettingRoom;
  7. use App\Entity\SchoolMatter;
  8. use App\Entity\SchoolTeacher;
  9. use App\Entity\SettingClassroom;
  10. use App\Entity\SettingTimeTable;
  11. use App\Entity\SchoolWorkingTime;
  12. use App\Repository\UserRepository;
  13. use App\Entity\SchoolTeacherTimeSheet;
  14. use App\Form\School\SchoolTeacherType;
  15. use App\Repository\RhSalaryRepository;
  16. use App\Repository\SettingRoomRepository;
  17. use App\Repository\SchoolMatterRepository;
  18. use App\Entity\SchoolWorkingTimeHourLesson;
  19. use App\Repository\SchoolTeacherRepository;
  20. use Knp\Component\Pager\PaginatorInterface;
  21. use App\Entity\SchoolTeacherMatterClassroom;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use App\Repository\EquivalentMatterRepository;
  24. use App\Repository\SettingClassroomRepository;
  25. use App\Repository\SettingTimeTableRepository;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use App\Repository\SchoolWorkingTimeRepository;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Doctrine\Common\Collections\ArrayCollection;
  30. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  31. use App\Form\School\SchoolWorkingTimeHourLessonType;
  32. use App\Form\School\SchoolTeacherMatterClassroomType;
  33. use App\Repository\SchoolWorkingTimeHourLessonRepository;
  34. use App\Repository\SchoolTeacherMatterClassroomRepository;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  37. /**
  38.  * @Route("/school/teacher")
  39.  */
  40. class SchoolTeacherController extends AbstractController
  41. {
  42.     /**
  43.      * @Route("/index", name="school_teacher_index", methods={"GET"})
  44.      */
  45.     public function index(Request $requestPaginatorInterface $paginatorSchoolTeacherRepository $schoolTeacherRepository): Response
  46.     {
  47.         /**@var User $user */
  48.         $user $this->getUser();
  49.         $schoolYear $user->getSchoolYear();
  50.         $establishment $this->getUser()->getEstablishment();
  51.         $school_teachers $paginator->paginate(
  52.             $schoolTeacherRepository->createQueryBuilder('entity')
  53.             ->innerJoin('entity.establishment''establishment')
  54.             ->addSelect('establishment')
  55.             ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  56.             ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  57.             ->andWhere('entity.schoolYear = :schoolYear')
  58.             ->setParameter('schoolYear'$schoolYear)
  59.             ->orderBy('entity.id''DESC')
  60.             ->getQuery(),
  61.             $request->query->getInt('page'1),
  62.             1000
  63.         );
  64.         return $this->render('school/school_teacher/index.html.twig', [
  65.             'school_teachers' => $school_teachers,
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/new", name="school_teacher_new", methods={"GET","POST"})
  70.      */
  71.     public function new(Request $requestRhSalaryRepository $rhSalaryRepositorySchoolTeacherRepository $schoolTeacherRepository): Response
  72.     {
  73.         /**@var User $user */
  74.         $user $this->getUser();
  75.         $schoolYear $user->getSchoolYear();
  76.         $establishment $this->getUser()->getEstablishment();
  77.         $salaries $rhSalaryRepository->createQueryBuilder('entity')
  78.         ->innerJoin('entity.establishment''establishment')
  79.         ->addSelect('establishment')
  80.         ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  81.         ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  82.         ->orderBy('entity.last_name''ASC')
  83.         ->getQuery()
  84.         ->getResult();
  85.         $notTeacherSalaries = new ArrayCollection();
  86.         foreach ($salaries as $key => $salarie) {
  87.             //if (count($salarie->getSchoolTeachers()) <= 0 ) {
  88.                 if (!$notTeacherSalaries->contains($salarie)) {
  89.                     $notTeacherSalaries->add($salarie);
  90.                 }
  91.             //}
  92.         }
  93.         $schoolTeacher = new SchoolTeacher();
  94.         $form $this->createForm(SchoolTeacherType::class, $schoolTeacher)
  95.         ->add('salary'EntityType::class, [
  96.             'class' => RhSalary::class,
  97.             'choices' => $notTeacherSalaries
  98.         ]);
  99.         $form->handleRequest($request);
  100.         if ($form->isSubmitted() && $form->isValid()) {
  101.             $teacher $schoolTeacherRepository->findOneBy(['salary' => $schoolTeacher->getSalary(), 'schoolYear' => $schoolYear], []);
  102.             if (null != $teacher) {
  103.                 $this->addFlash('info'"Impossible: Cet enseignant existe déjà.");
  104.                 return $this->redirectToRoute('school_teacher_new');
  105.             }
  106.             $entityManager $this->getDoctrine()->getManager();
  107.             $schoolTeacher->setEstablishment($establishment);
  108.             $schoolTeacher->setSchoolYear($schoolYear);
  109.             $entityManager->persist($schoolTeacher);
  110.             try {
  111.                 $entityManager->flush();
  112.                 $this->addFlash('success'"Une classe à été ajoutée.");
  113.             } catch (\Throwable $th) {
  114.                 $this->addFlash('warning'"Une erreure est survenue lors de l'ajout de la classe.");
  115.                 $this->addFlash('info'$th->getMessage());
  116.                 return $this->redirectToRoute('school_teacher_new');
  117.             }
  118.             return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  119.         }
  120.         return $this->renderForm('school/school_teacher/new.html.twig', [
  121.             'school_teacher' => $schoolTeacher,
  122.             'form' => $form,
  123.         ]);
  124.     }
  125.     /**
  126.      * @Route("/{id}/edit", name="school_teacher_edit", methods={"GET","POST"})
  127.      */
  128.     public function edit(Request $requestSchoolTeacher $schoolTeacherSchoolMatterRepository $schoolMatterRepositorySettingClassroomRepository $settingClassroomRepositoryRhSalaryRepository $rhSalaryRepositorySchoolTeacherMatterClassroomRepository $schoolTeacherMatterClassroomRepositorySchoolTeacherRepository $schoolTeacherRepository): Response
  129.     {
  130.         /**@var User $user */
  131.         $user $this->getUser();
  132.         $schoolYear $user->getSchoolYear();
  133.         $establishment $user->getEstablishment();
  134.         $classrooms $settingClassroomRepository->findBy(['establishment' => $establishment'schoolYear' => $schoolYear], []);
  135.         $matters $schoolMatterRepository->findBy(['establishment' => $establishment], []);
  136.         $matterCollections = new ArrayCollection();
  137.         foreach ($matters as $key => $matter) {
  138.             if ($schoolTeacher->getEquivalentMatters()->contains($matter->getEquivalentMatter())) {
  139.                 $matterCollections->add($matter);
  140.             }
  141.         }
  142.         $notTeacherSalaries $rhSalaryRepository->createQueryBuilder('entity')
  143.             ->innerJoin('entity.establishment''establishment')
  144.             ->addSelect('establishment')
  145.             ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  146.             ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  147.             ->andWhere('entity.last_name = :last_name')
  148.             ->setParameter('last_name'$schoolTeacher->getSalary()->getLastName())
  149.             ->andWhere('entity.first_name = :first_name')
  150.             ->setParameter('first_name'$schoolTeacher->getSalary()->getFirstName())
  151.             ->orderBy('entity.last_name''ASC')
  152.             ->getQuery()
  153.             ->getResult();
  154.         
  155.         //$notTeacherSalaries = $rhSalaryRepository->findBy(['establishment' => $establishment], ['last_name' => 'ASC']);
  156.         if (!$this->isGranted("ROLE_EMPLOI_DU_TEMPS")) {
  157.             $notTeacherSalaries = new ArrayCollection();
  158.             $notTeacherSalaries->add($schoolTeacher->getSalary());
  159.         }
  160.         
  161.         $form $this->createForm(SchoolTeacherType::class, $schoolTeacher)
  162.         ->add('salary'EntityType::class, [
  163.             'class' => RhSalary::class,
  164.             'choices' => $notTeacherSalaries
  165.         ]);
  166.         $form->handleRequest($request);
  167.         if ($form->isSubmitted() && $form->isValid()) {
  168.             $teacher $schoolTeacherRepository->findOneBy(['salary' => $schoolTeacher->getSalary(), 'schoolYear' => $schoolYear], []);
  169.             if (null != $teacher) {
  170.                 if ($teacher != $schoolTeacher) {
  171.                     $this->addFlash('info'"Impossible: Cet enseignant existe déjà.");
  172.                     return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  173.                 }
  174.             }
  175.             try {
  176.                 $this->getDoctrine()->getManager()->flush();
  177.                 $this->addFlash('success'"la classe à été édité.");
  178.             } catch (\Throwable $th) {
  179.                 $this->addFlash('warning'"Une erreure est survenue lors de l'édition de la classe.");
  180.                 $this->addFlash('info'$th->getMessage());
  181.                 return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  182.             }
  183.         }
  184.         $schoolTeacherMatterClassroom = new SchoolTeacherMatterClassroom();
  185.         $schoolTeacherMatterClassroomForm $this->createForm(SchoolTeacherMatterClassroomType::class, $schoolTeacherMatterClassroom)
  186.         ->add('matter'EntityType::class, [
  187.             'class' => SchoolMatter::class,
  188.             'choices' => $matterCollections
  189.         ])
  190.         ->add('classroom'EntityType::class, [
  191.             'class' => SettingClassroom::class,
  192.             'choices' => $classrooms
  193.         ]);
  194.         $schoolTeacherMatterClassroomForm->handleRequest($request);
  195.         if ($schoolTeacherMatterClassroomForm->isSubmitted() && $schoolTeacherMatterClassroomForm->isValid()) {
  196.             $entityManager $this->getDoctrine()->getManager();
  197.             if ($schoolTeacherMatterClassroom->getMatter()->getLevel() != $schoolTeacherMatterClassroom->getClassroom()->getLevel()) {
  198.                 $this->addFlash('warning'"La matière selectionnée doit être dans le même niveau que la classe");
  199.                 return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  200.             }
  201.             $_schoolTeacherMatterClassroom $schoolTeacherMatterClassroomRepository->findOneBy(['classroom' => $schoolTeacherMatterClassroom->getClassroom(), 'matter' => $schoolTeacherMatterClassroom->getMatter(), 'is_disabled' => 0], []);
  202.             if (null != $_schoolTeacherMatterClassroom) {
  203.                 $this->addFlash('warning'"Un enseignant (" .$_schoolTeacherMatterClassroom->getTeacher()->getName(). ") est déjà affecté à cette matière dans cette classe.");
  204.                 return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  205.             }
  206.             $schoolTeacherMatterClassroom->setTeacher($schoolTeacher);
  207.             $schoolTeacherMatterClassroom->setEstablishment($establishment);
  208.             $schoolTeacherMatterClassroom->setSchoolYear($schoolTeacher->getSchoolYear());
  209.             $entityManager->persist($schoolTeacherMatterClassroom);
  210.             try {
  211.                 $this->getDoctrine()->getManager()->flush();
  212.                 $this->addFlash('success'"Enrégistrement effectué avec succès.");
  213.             } catch (\Throwable $th) {
  214.                 $this->addFlash('warning'"Une erreure est survenue lors de l'édition de l'enseignant.");
  215.                 $this->addFlash('info'$th->getMessage());
  216.                 return $this->redirectToRoute('school_teacher_edit', ['id' => $schoolTeacher->getId()]);
  217.             }
  218.         }
  219.         return $this->renderForm('school/school_teacher/edit.html.twig', [
  220.             'school_teacher' => $schoolTeacher,
  221.             'form' => $form,
  222.             'school_teacher_matter_classroom' => $schoolTeacherMatterClassroom,
  223.             'school_teacher_matter_classroom_form' => $schoolTeacherMatterClassroomForm,
  224.         ]);
  225.     }
  226.     /**
  227.      * @Route("/delete-selection", name="school_teachers_selected_delete", methods={"GET"})
  228.     */
  229.     public function deleteSelected(Request $requestSchoolTeacherRepository $entityRepository): Response
  230.     {
  231.         $list $request->get('entities');
  232.         $entityManager $this->getDoctrine()->getManager();
  233.         $errors 0;
  234.         foreach ($list as $key => $id) {
  235.             $entity $entityRepository->findOneBy(['id' => intval($id)], []);
  236.             if ($entity != null) {
  237.                 foreach ($entity->getSchoolTeacherMatterClassrooms() as $key => $schoolTeacherMatterClassroom) {
  238.                     $schoolTeacherMatterClassroom->setIsDisabled(true);
  239.                 }
  240.                 $entity->setIsDisabled(true);
  241.                 //$entityManager->remove($entity);
  242.             }
  243.         }
  244.         try {
  245.             $entityManager->flush();
  246.             $this->addFlash('success'"Traitement effectué");
  247.             return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  248.         } catch (\Throwable $th) {
  249.             //$th->getMessage()
  250.             $this->addFlash('warning'$th->getMessage());
  251.         }
  252.         
  253.         $this->addFlash('warning'"Traitement non effectué");
  254.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  255.     }
  256.     /**
  257.      * @Route("/api/new-get-classroom-matters", name="api_school_teacher_new_get_classroom_matters", methods={"GET"})
  258.     */
  259.     public function apiNewGetClassroomMatters(Request $requestSettingClassroomRepository $settingClassroomRepositorySchoolMatterRepository $schoolMatterRepositorySchoolTeacherRepository $schoolTeacherRepositoryEquivalentMatterRepository $equivalentMatterRepository): Response
  260.     {
  261.         $equivalentMatterList $request->get('equivalentMatters');
  262.         $classroomList $request->get('classrooms');
  263.         $schoolMatters = new ArrayCollection();
  264.         if (count($classroomList) > 0) {
  265.         
  266.             foreach ($classroomList as $key => $id) {
  267.                 $classroom $settingClassroomRepository->findOneBy(['id' => intval($id)], []);
  268.                 if ($classroom != null) {
  269.                     foreach ($equivalentMatterList as $key => $id) {
  270.                         $equivalentMatter $equivalentMatterRepository->findOneBy(['id' => intval($id)], []);
  271.                         if ($equivalentMatter != null) {
  272.                             foreach ($schoolMatterRepository->findBy(['equivalentMatter' => $equivalentMatter'level' => $classroom->getLevel(), 'is_test_matter' => 0], []) as $key => $matter) {
  273.                                 $isTeach false;
  274.                                 foreach ($schoolTeacherRepository->findBy(['establishment' => $classroom->getEstablishment()], []) as $key => $_teacher) {
  275.                                     if ($_teacher->getClassrooms()->contains($classroom) && $_teacher->getMatters()->contains($matter)) {
  276.                                         $isTeach true;
  277.                                         break;
  278.                                     }
  279.                                 }
  280.                                 if (!$isTeach) {
  281.                                     $sMatter = [
  282.                                         'id' => $matter->getId(),
  283.                                         'label' => $matter->getLevel()->getLabel().' '.$matter->getLabel(),
  284.                                     ];
  285.                                     if (!$schoolMatters->contains($sMatter)) {
  286.                                         $schoolMatters->add($sMatter);
  287.                                     }
  288.                                     
  289.                                 }
  290.                             }
  291.                         }
  292.                     }
  293.                 }
  294.             }
  295.         }
  296.         
  297.         return $this->json([
  298.             'code' => 200
  299.             'message' => "found :)"
  300.             'schoolMatters' => $schoolMatters,
  301.             'classrooms' => $classroomList 
  302.         ], 
  303.         200);
  304.         
  305.     }
  306.     /**
  307.      * @Route("/print/list-by-classroom", name="school_teacher_print_list_by_classroom")
  308.     */
  309.     public function print_list_by_classroom(Pdf $knpSnappyPdfSettingClassroomRepository $settingClassroomRepository): Response
  310.     {
  311.         /**@var User $user */
  312.         $user $this->getUser();
  313.         $schoolYear $user->getSchoolYear();
  314.         
  315.         $establishment $this->getUser()->getEstablishment();
  316.         $setting_classrooms $settingClassroomRepository->createQueryBuilder('entity')
  317.             ->andWhere('entity.establishment = :establishment')
  318.             ->setParameter('establishment'$establishment)
  319.             ->andWhere('entity.schoolYear = :schoolYear')
  320.             ->setParameter('schoolYear'$schoolYear)
  321.             ->orderBy('entity.id''DESC')
  322.             ->getQuery()
  323.             ->getResult();
  324.         $html $this->renderView('school/print/list_by_classroom.html.twig', [
  325.             'setting_classrooms' => $setting_classrooms,
  326.             
  327.             'school_year' => $schoolYear,
  328.             'setting' => $establishment,
  329.         ]);
  330.         $file_name "LISTE_ENSEIGNANT_PAR_CLASSE.pdf";
  331.         $footer $this->renderView('print/footer.html.twig', ['setting' => $establishment,]);
  332.         $header $this->renderView('print/header.html.twig', ['setting' => $establishment,]);
  333.         $options = [
  334.             'orientation' => 'Portrait',
  335.             'header-html' => $header
  336.             //'footer-html' => $footer
  337.         ];
  338.         
  339.         $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/rapport/' $file_name$optionstrue);
  340.         return $this->redirectToRoute('preview', [
  341.             'file' => $file_name,
  342.             'dir' => 'rapport',
  343.         ]);
  344.     }
  345.     /**
  346.      * @Route("/print/list-by-teacher", name="school_teacher_print_list_by_teacher")
  347.     */
  348.     public function print_list_by_teacher(Pdf $knpSnappyPdfSchoolTeacherRepository $schoolTeacherRepository): Response
  349.     {
  350.         /**@var User $user */
  351.         $user $this->getUser();
  352.         $schoolYear $user->getSchoolYear();
  353.         $establishment $user->getEstablishment();
  354.         $school_teachers $schoolTeacherRepository->createQueryBuilder('entity')
  355.             ->andWhere('entity.establishment = :establishment')
  356.             ->setParameter('establishment'$establishment)
  357.             ->andWhere('entity.schoolYear = :schoolYear')
  358.             ->setParameter('schoolYear'$schoolYear)
  359.             ->andWhere('entity.is_disabled = :is_disabled')
  360.             ->setParameter('is_disabled'0)
  361.             ->orderBy('entity.id''DESC')
  362.             ->getQuery()
  363.             ->getResult();
  364.         $html $this->renderView('school/print/list_by_teacher.html.twig', [
  365.             'school_teachers' => $school_teachers,
  366.             
  367.             'school_year' => $schoolYear,
  368.             'setting' => $establishment,
  369.         ]);
  370.         $file_name "LISTE_ENSEIGNANT_PAR_CLASSE_ET_MATIERE.pdf";
  371.         $footer $this->renderView('print/footer.html.twig', ['setting' => $establishment,]);
  372.         $header $this->renderView('print/header.html.twig', ['setting' => $establishment,]);
  373.         $options = [
  374.             'orientation' => 'Portrait',
  375.             'header-html' => $header
  376.             //'footer-html' => $footer
  377.         ];
  378.         
  379.         $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/rapport/' $file_name$optionstrue);
  380.         return $this->redirectToRoute('preview', [
  381.             'file' => $file_name,
  382.             'dir' => 'rapport',
  383.         ]);
  384.     }
  385.     /**
  386.      * @Route("/api/edit-get-matters", name="api_school_teacher_edit_get_matters", methods={"GET"})
  387.     */
  388.     public function apiEditMatters(Request $requestSettingClassroomRepository $settingClassroomRepositorySchoolMatterRepository $schoolMatterRepositorySchoolTeacherRepository $schoolTeacherRepository): Response
  389.     {
  390.         $idClassroom $request->get('idClassroom');
  391.         $idTeacher intval($request->get('idTeacher'));
  392.         $teacher $schoolTeacherRepository->findOneBy(['id' => $idTeacher], []);
  393.         $classroom $settingClassroomRepository->findOneBy(['id' => $idClassroom], []);
  394.         $matters = new ArrayCollection();
  395.         $establishment $this->getUser()->getEstablishment();
  396.         
  397.         $schoolMatters $schoolMatterRepository->createQueryBuilder('entity')
  398.         /* ->innerJoin('entity.establishment', 'establishment')
  399.         ->addSelect('establishment')
  400.         ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  401.         ->setParameter('establishmentGroup', $establishment->getEstablishmentGroup()) */
  402.         ->andWhere('entity.establishment = :establishment')
  403.         ->setParameter('establishment'$establishment)
  404.         ->andWhere('entity.level = :level')
  405.         ->setParameter('level'$classroom->getLevel())
  406.         ->andWhere('entity.is_test_matter = :is_test_matter')
  407.         ->setParameter('is_test_matter'0)
  408.         ->orderBy('entity.label''ASC')
  409.         ->getQuery()
  410.         ->getResult(); 
  411.         foreach ($schoolMatters as $key => $matter) {
  412.             if ($teacher->getEquivalentMatters()->contains($matter->getEquivalentMatter())) {
  413.                 $matters->add([
  414.                     'id' => $matter->getId(),
  415.                     'label' => $matter->getLevel()->getLabel().' '.$matter->getLabel(),
  416.                 ]);
  417.                 
  418.             }
  419.         }
  420.         return $this->json([
  421.             'code' => 200
  422.             'message' => "found :)"
  423.             'schoolMatters' => $matters,
  424.         ], 
  425.         200);
  426.     } 
  427.     /**
  428.      * @Route("/{id}/enabled", name="school_teacher_enabled", methods={"GET"})
  429.     */
  430.     public function enabled(SchoolTeacher $entity): Response
  431.     {
  432.         $entityManager $this->getDoctrine()->getManager();
  433.         foreach ($entity->getSchoolTeacherMatterClassrooms() as $key => $schoolTeacherMatterClassroom) {
  434.             $schoolTeacherMatterClassroom->setIsDisabled(false);
  435.         }
  436.         $entity->setIsDisabled(false);
  437.         try {
  438.             $entityManager->flush();
  439.             $this->addFlash('success'"Traitement effectué");
  440.             return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  441.         } catch (\Throwable $th) {
  442.             //$th->getMessage()
  443.             $this->addFlash('warning'$th->getMessage());
  444.         }
  445.         
  446.         $this->addFlash('warning'"Traitement non effectué");
  447.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  448.     }
  449.     /**
  450.      * @Route("/{id}/time-sheet", name="school_teacher_time_sheet", methods={"GET","POST"})
  451.      */
  452.     public function time_sheet(Request $requestSchoolTeacher $schoolTeacherSchoolMatterRepository $schoolMatterRepositorySettingClassroomRepository $settingClassroomRepositorySettingRoomRepository $settingRoomRepositorySettingTimeTableRepository $settingTimeTableRepositorySchoolWorkingTimeRepository $schoolWorkingTimeRepositorySchoolWorkingTimeHourLessonRepository $schoolWorkingTimeHourLessonRepository): Response
  453.     {
  454.         /**@var User $user */
  455.         $user $this->getUser();
  456.         $schoolYear $user->getSchoolYear();
  457.         $establishment $user->getEstablishment();
  458.         $settingClassrooms $settingClassroomRepository->findBy(['establishment' => $establishment'schoolYear' => $schoolYear], []);
  459.         //$schoolMatters = $schoolMatterRepository->findBy(['establishment' => $establishment], []);
  460.         $settingRooms $settingRoomRepository->createQueryBuilder('entity')
  461.         ->innerJoin('entity.establishment''establishment')
  462.         ->addSelect('establishment')
  463.         
  464.         ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  465.         ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  466.         /* ->andWhere('entity.establishment = :establishment')
  467.         ->setParameter('establishment', $establishment) */
  468.         
  469.         ->orderBy('entity.label''ASC')
  470.         ->getQuery()
  471.         ->getResult();
  472.         $settingTimeTables $settingTimeTableRepository->findBy(['establishment' => $establishment'schoolYear' => $schoolYear], []);
  473.         $matterCollections = new ArrayCollection();
  474.         $settingClassroomCollections = new ArrayCollection();
  475.         foreach ($schoolTeacher->getSchoolTeacherMatterClassrooms() as $key => $schoolTeacherMatterClassroom) {
  476.             if ($schoolTeacherMatterClassroom->getMatter()->getEstablishment() == $establishment) {
  477.                 $matterCollections->add($schoolTeacherMatterClassroom->getMatter());
  478.             }
  479.         }
  480.         foreach ($schoolTeacher->getSchoolTeacherMatterClassrooms() as $key => $schoolTeacherMatterClassroom) {
  481.             foreach ($matterCollections as $key => $_schoolMatter) {
  482.                 if (!$settingClassroomCollections->contains($schoolTeacherMatterClassroom->getClassroom())) {
  483.                     if ($schoolTeacherMatterClassroom->getClassroom()->getEstablishment() == $establishment) {
  484.                         $settingClassroomCollections->add($schoolTeacherMatterClassroom->getClassroom());
  485.                     }
  486.                 }
  487.             }
  488.         }
  489.         
  490.         $schoolWorkingTimeHourLesson = new SchoolWorkingTimeHourLesson();
  491.         $form $this->createForm(SchoolWorkingTimeHourLessonType::class, $schoolWorkingTimeHourLesson)
  492.         ->add('schoolMatter'EntityType::class, [
  493.             'class' => SchoolMatter::class,
  494.             'choices' => $matterCollections
  495.         ])
  496.         ->add('settingClassroom'EntityType::class, [
  497.             'class' => SettingClassroom::class,
  498.             'choices' => $settingClassroomCollections
  499.         ])
  500.         ->add('settingRoom'EntityType::class, [
  501.             'class' => SettingRoom::class,
  502.             'choices' => $settingRooms
  503.         ])
  504.         ->add('settingTimeTable'EntityType::class, [
  505.             'class' => SettingTimeTable::class,
  506.             'choices' => $settingTimeTables
  507.         ]);
  508.         $form->handleRequest($request);
  509.         if ($form->isSubmitted() && $form->isValid()) {
  510.             $entityManager $this->getDoctrine()->getManager();
  511.             $settingRoom $settingRoomRepository->findOneBy(['id' => $schoolWorkingTimeHourLesson->getSettingRoom()->getId()], []);
  512.             $schoolMatter $schoolMatterRepository->findOneBy(['id' => $schoolWorkingTimeHourLesson->getSchoolMatter()->getId()], []);
  513.             $settingTimeTable $settingTimeTableRepository->findOneBy(['id' => $schoolWorkingTimeHourLesson->getSettingTimeTable()->getId()], []);
  514.             $settingClassroom $settingClassroomRepository->findOneBy(['id' => $schoolWorkingTimeHourLesson->getSettingClassroom()->getId()], []);
  515.             if (null == $settingTimeTable) {
  516.                 $this->addFlash('warning'"La plage horaire est introuvable.");
  517.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  518.             }
  519.     
  520.             if (null == $settingRoom) {
  521.                 $this->addFlash('warning'"Veuillez selectionner une salle");
  522.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  523.             }
  524.     
  525.             if (null == $schoolMatter) {
  526.                 $this->addFlash('warning'"Veuillez selectionner une matière");
  527.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  528.             }
  529.     
  530.             if (null == $settingClassroom) {
  531.                 $this->addFlash('warning'"Veuillez selectionner une classe");
  532.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  533.             }
  534.             if ($schoolWorkingTimeHourLesson->getSchoolMatter()->getLevel() != $schoolWorkingTimeHourLesson->getSettingClassroom()->getLevel()) {
  535.                 $this->addFlash('warning'"Matière et classe doivent être du même niveau.");
  536.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  537.             }
  538.             $schoolWorkingTime $schoolWorkingTimeRepository->findOneBy(['establishment' => $establishment'schoolYear' => $schoolYear'settingClassroom' => $schoolWorkingTimeHourLesson->getSettingClassroom()], []);
  539.             if (null == $schoolWorkingTime) {
  540.                 $schoolWorkingTime = new SchoolWorkingTime();
  541.                 $schoolWorkingTime->setEstablishment($establishment);
  542.                 $schoolWorkingTime->setSchoolYear($schoolYear);
  543.                 $schoolWorkingTime->setSettingClassroom($schoolWorkingTimeHourLesson->getSettingClassroom());
  544.                 $entityManager->persist($schoolWorkingTime);
  545.             }
  546.             $_schoolWorkingTimeHourLesson $schoolWorkingTimeHourLessonRepository->findOneBy(['schoolWorkingTime' => $schoolWorkingTime'settingTimeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable(), 'day' => $schoolWorkingTimeHourLesson->getDay()], []);
  547.             
  548.             $schoolWorkingTimeHourLesson->setEstablishment($establishment);
  549.             $schoolWorkingTimeHourLesson->setSchoolTeacher($schoolTeacher);
  550.             $schoolWorkingTimeHourLesson->setSchoolYear($schoolYear);
  551.             $schoolWorkingTimeHourLesson->setSchoolWorkingTime($schoolWorkingTime);
  552.             $schoolWorkingTimeHourLesson->setDefautDuration($settingTimeTable->getDefautDuration());
  553.             if (count($schoolWorkingTimeHourLessonRepository->findBy(['schoolTeacher' => $schoolTeacher'settingClassroom' => $schoolWorkingTime->getSettingClassroom(), 'settingTimeTable' => $settingTimeTable'day' => $schoolWorkingTimeHourLesson->getDay()], [])) > 0) {
  554.                 $this->addFlash('warning'"Un enseignant ne peut avoir plus d'un cours le même jour à la même heure avec la même classe.");
  555.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  556.             }
  557.             $_schoolWorkingTimeHourLesson $schoolWorkingTimeHourLessonRepository->findOneBy(['schoolYear' => $schoolYear'settingRoom' => $settingRoom'settingTimeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable(), 'day' => $schoolWorkingTimeHourLesson->getDay()], []);
  558.             //if (count($schoolWorkingTimeHourLessonRepository->findBy(['settingRoom' => $settingRoom, 'settingTimeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable(), 'day' => $schoolWorkingTimeHourLesson->getDay(), 'settingClassroom' => $schoolWorkingTimeHourLesson->getSettingClassroom()], [])) > 0) {
  559.             if (null != $_schoolWorkingTimeHourLesson) {
  560.                 if (!$_schoolWorkingTimeHourLesson->getSettingRoom()->getIsArea()) {
  561.                     $this->addFlash('warning'"Une salle ne peut abriter plus d'un cours le même jour à la même heure. Classe: " .$_schoolWorkingTimeHourLesson->getSettingClassroom()->getLabel().", Enseignant: " .$_schoolWorkingTimeHourLesson->getSchoolTeacher()->__toString().", Jour: " .$_schoolWorkingTimeHourLesson->getDay().", Heure: " .$_schoolWorkingTimeHourLesson->getSettingTimeTable()->getLabel().", Matière: " .$_schoolWorkingTimeHourLesson->getSchoolMatter()->getLabel());
  562.                     return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  563.                 }
  564.             }
  565.             if (count($schoolWorkingTimeHourLessonRepository->findBy(['schoolMatter' => $schoolMatter'settingTimeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable(), 'day' => $schoolWorkingTimeHourLesson->getDay(), 'settingClassroom' => $schoolWorkingTimeHourLesson->getSettingClassroom()], [])) > 0) {
  566.                 $this->addFlash('warning'"Une matière ne peut être enseigner plus d'un fois le même jour à la même heure dans la même classe.");
  567.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  568.             }
  569.             /* if ($schoolWorkingTimeHourLesson->getSchoolMatter()->getHourlyVolumeRestToDispach($schoolYear) < $schoolWorkingTimeHourLesson->getSettingTimeTable()->getDefautDuration()) {
  570.                 $this->addFlash('warning', "Le volume horaire hebdomadaire affecté à cette matière est atteint.");
  571.                 return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  572.             } */
  573.             if (null != $_schoolWorkingTimeHourLesson) {
  574.                 $_schoolWorkingTimeHourLesson->setSchoolMatter($schoolWorkingTimeHourLesson->getSchoolMatter());
  575.                 $_schoolWorkingTimeHourLesson->setSchoolTeacher($schoolTeacher);
  576.                 $_schoolWorkingTimeHourLesson->setSettingRoom($schoolWorkingTimeHourLesson->getSettingRoom());
  577.             }else {
  578.                 $entityManager->persist($schoolWorkingTimeHourLesson);
  579.             }
  580.             try {
  581.                 $entityManager->flush();
  582.                 $this->addFlash('success'"Enrégistrement effectué avec succès.");
  583.             } catch (\Throwable $th) {
  584.                 $this->addFlash('warning'"Une erreure est survenue lors de l'édition de l'enseignant.");
  585.                 $this->addFlash('info'$th->getMessage());
  586.             }
  587.             return $this->redirectToRoute('school_teacher_time_sheet', ['id' => $schoolTeacher->getId()]);
  588.         }
  589.         return $this->renderForm('school/school_teacher/time_sheet.html.twig', [
  590.             'school_teacher' => $schoolTeacher,
  591.             'school_working_time_hour_lesson' => $schoolWorkingTimeHourLesson,
  592.             'form' => $form,
  593.         ]);
  594.     }
  595.     /**
  596.      * @Route("/working-time/{id}/print", name="school_teacher_working_time_print", methods={"GET"})
  597.     */
  598.     public function print_working_time(Pdf $knpSnappyPdfSchoolTeacher $schoolTeacherSettingTimeTableRepository $settingTimeTableRepositorySchoolWorkingTimeHourLessonRepository $schoolWorkingTimeHourLessonRepository)
  599.     {
  600.         /**@var User $user */
  601.         $user $this->getUser();
  602.         $schoolYear $user->getSchoolYear();
  603.         $establishment $user->getEstablishment();
  604.         $template 'school/print/schoolTeacherWorkingTime.html.twig';
  605.         if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  606.             $template 'school/print/schoolTeacherWorkingTime.html.twig';
  607.         }
  608.         $schoolWorkingTimeHourLessons $schoolWorkingTimeHourLessonRepository->findBy(['schoolTeacher' => $schoolTeacher], []);
  609.         
  610.         $html $this->renderView($template, [
  611.             'school_year' => $schoolYear,
  612.             'school_teacher' => $schoolTeacher,
  613.             'schoolWorkingTimeHourLessons' => $schoolWorkingTimeHourLessons,
  614.             'setting_time_tables' => $settingTimeTableRepository->findBy(['establishment' => $establishment'schoolYear' => $schoolYear], ['label' => 'ASC']),
  615.             'week_days' => SchoolWorkingTime::COURS_DAYS,
  616.             'setting' => $establishment,
  617.         ]);
  618.         $footer $this->renderView('print/footer.html.twig', ['setting' => $establishment]);
  619.         $header $this->renderView('print/header.html.twig', ['setting' => $establishment]);
  620.         $options = [
  621.             'orientation' => 'Portrait'
  622.             //'header-html' => $header
  623.             //'footer-html' => $footer
  624.         ];
  625.         $file_name 'EMPLOIE_DU_TEMPS_'.$schoolTeacher->getId()."_.pdf";
  626.         try {
  627.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/working-time/' $file_name$optionstrue);
  628.         } catch (\Throwable $th) {
  629.             $this->addFlash('info'"Effectué");
  630.         }
  631.         return $this->redirectToRoute('preview', [
  632.             'file' => $file_name,
  633.             'dir' => 'working-time',
  634.         ]);
  635.     }
  636.     /**
  637.      * @Route("/reset-password/{id}", name="school_teacher_reset_password", methods={"GET"})
  638.     */
  639.     public function resetPassword(SchoolTeacher $schoolTeacherUserPasswordHasherInterface $userPasswordHasherInterface): Response
  640.     {
  641.         $entityManager $this->getDoctrine()->getManager();
  642.         $user $schoolTeacher->getSalary()->getUser();
  643.         if (null != $user) {
  644.             $user->setIsPasswordChanged(false);
  645.             $user->setIsEnabled(true);
  646.             $user->setPassword(
  647.                 $userPasswordHasherInterface->hashPassword(
  648.                         $user,
  649.                         "central-edu"
  650.                     )
  651.                 );
  652.             try {
  653.                 $entityManager->flush();
  654.                 $this->addFlash('success'"Mot de passe réinitialisé :)".$user->getUserIdentifier());
  655.                 return $this->json(['code' => 200'message' => "Mot de passe réinitialisé :) ".$user->getUserIdentifier()], 200);
  656.             } catch (\Throwable $th) {
  657.                 //$th->getMessage()
  658.                 $this->addFlash('info'$th->getMessage());
  659.                 return $this->json(['code' => 500'message' => $th->getMessage()], 200);
  660.             }
  661.         }
  662.         
  663.         $this->addFlash('warning'"Une erreure s'est produite");
  664.         return $this->json(['code' => 500'message' => "Une erreure s'est produite"], 200);
  665.     }
  666.     /**
  667.      * @Route("/api/get-matters", name="api_school_teacher_matters", methods={"GET"})
  668.     */
  669.     public function api_get_matters(Request $requestSchoolTeacherRepository $entityRepositorySettingClassroomRepository $settingClassroomRepository): Response
  670.     {
  671.         /**@var User $user */
  672.         $user $this->getUser();
  673.         $schoolYear $user->getSchoolYear();
  674.         $establishment $user->getEstablishment();
  675.         $classroom $settingClassroomRepository->findOneBy(['id' => $request->get('classroom')], []);
  676.         $entity $entityRepository->findOneBy(['id' => $request->get('teacher')], []);
  677.         if ($entity != null) {
  678.             
  679.             return $this->json([
  680.                 'code' => 200
  681.                 'message' => "found :)"
  682.                 'schoolMatters' => $entity->getJsonMatterTeachs($classroom$establishment)], 
  683.             200);
  684.         }else{
  685.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  686.         }
  687.     }
  688.     /**
  689.      * @Route("/print/teachers", name="school_teacher_print_teachers", methods={"GET"})
  690.     */
  691.     public function print_teachers(Pdf $knpSnappyPdfUserRepository $userRepository)
  692.     {
  693.         $setting $this->getUser()->getEstablishment();
  694.         $teachers $userRepository->createQueryBuilder('entity')
  695.         ->innerJoin('entity.rhSalary''rhSalary')
  696.         ->addSelect('rhSalary')
  697.         ->innerJoin('rhSalary.schoolTeachers''schoolTeachers')
  698.         ->addSelect('schoolTeachers')
  699.         ->andWhere('entity.establishment = :establishment')
  700.         ->setParameter('establishment'$setting)
  701.         ->andWhere('schoolTeachers.is_disabled = :is_disabled')
  702.         ->setParameter('is_disabled'0)
  703.         ->andWhere('entity.is_enabled = :is_enabled')
  704.         ->setParameter('is_enabled'1)
  705.         ->orderBy('rhSalary.last_name''ASC')
  706.         ->getQuery()
  707.         ->getResult();
  708.         $template 'security/print/teachers.html.twig';
  709.         $html $this->renderView($template, [
  710.             'teachers' => $teachers,
  711.             'setting' => $setting,
  712.         ]);
  713.         $file_name "ENSEIGNANTS_.pdf";
  714.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
  715.         $header $this->renderView('print/header.html.twig', ['setting' => $setting,]);
  716.         $options = [
  717.             'orientation' => 'Portrait',
  718.             'header-html' => $header,
  719.             'footer-html' => $footer
  720.         ];
  721.         try {
  722.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/teachers/' $file_name$optionstrue);
  723.         } catch (\Throwable $th) {
  724.             $this->addFlash('info'"Ce reçu à déjà été imprimé.");
  725.         }
  726.         
  727.         return $this->redirectToRoute('preview', [
  728.             'file' => $file_name,
  729.             'dir' => 'teachers',
  730.         ]);
  731.     }
  732.     /**
  733.      * @Route("/api/get-classrooms", name="api_school_teacher_classrooms", methods={"GET"})
  734.     */
  735.     public function api_get_classrooms(Request $requestSchoolTeacherRepository $entityRepository): Response
  736.     {
  737.         /**@var User $user */
  738.         $user $this->getUser();
  739.         $schoolYear $user->getSchoolYear();
  740.         $establishment $user->getEstablishment();
  741.         $entity $entityRepository->findOneBy(['id' => $request->get('teacher'), 'is_disabled' => 0], []);
  742.         if ($entity != null) {
  743.             
  744.             return $this->json([
  745.                 'code' => 200
  746.                 'message' => "found :)"
  747.                 'settingClassrooms' => $entity->getJsonClassroomTeachs($establishment)], 
  748.             200);
  749.         }else{
  750.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  751.         }
  752.     }
  753.     /**
  754.      * @Route("/api/get-time_tables", name="api_school_teacher_time_tables", methods={"GET"})
  755.     */
  756.     public function api_get_time_tables(Request $requestSchoolTeacherRepository $entityRepositorySettingClassroomRepository $settingClassroomRepository): Response
  757.     {
  758.         /**@var User $user */
  759.         $user $this->getUser();
  760.         $schoolYear $user->getSchoolYear();
  761.         $establishment $user->getEstablishment();
  762.         $classroom $settingClassroomRepository->findOneBy(['id' => $request->get('classroom')], []);
  763.         $entity $entityRepository->findOneBy(['id' => $request->get('teacher'), 'is_disabled' => 0], []);
  764.         if ($entity != null) {
  765.             
  766.             return $this->json([
  767.                 'code' => 200
  768.                 'message' => "found :)"
  769.                 'settingTimeTables' => $entity->getJsonTimeTableTeachs($classroom$establishment)], 
  770.             200);
  771.         }else{
  772.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  773.         }
  774.     }
  775.     /**
  776.      * @Route("/api/get-working-time-hour-lessons", name="api_school_teacher_working_time_hour_lessons", methods={"GET"})
  777.     */
  778.     public function api_get_working_time_hour_lessons(Request $requestSchoolTeacherRepository $entityRepository): Response
  779.     {
  780.         /**@var User $user */
  781.         $user $this->getUser();
  782.         $establishment $user->getEstablishment();
  783.         $entity $entityRepository->findOneBy(['id' => $request->get('teacher'), 'is_disabled' => 0], []);
  784.         if ($entity != null) {
  785.             
  786.             return $this->json([
  787.                 'code' => 200
  788.                 'message' => "found :)"
  789.                 'workingTimeHourLessons' => $entity->getJsonWorkingTimeHourLessons($establishment)], 
  790.             200);
  791.         }else{
  792.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  793.         }
  794.     }
  795.     /**
  796.      * @Route("/{id}/edit-login", name="school_teacher_edit_login", methods={"POST"})
  797.      */
  798.     public function editLogin(Request $requestSchoolTeacher $schoolTeacherUserRepository $userRepositoryUserPasswordHasherInterface $userPasswordHasherInterface): Response
  799.     {
  800.         if (!$this->isGranted('ROLE_DIRECTEUR')) {
  801.             return $this->json(['code' => 403'message' => 'Accès refusé'], 403);
  802.         }
  803.         $newLogin $request->request->get('newLogin');
  804.         $resetPassword $request->request->get('resetPassword') === 'true';
  805.         
  806.         // Validation : au moins une action doit être demandée
  807.         if (empty($newLogin) && !$resetPassword) {
  808.             return $this->json(['code' => 400'message' => 'Veuillez sélectionner au moins une action : modifier le login ou réinitialiser le mot de passe'], 400);
  809.         }
  810.         $user $schoolTeacher->getSalary()->getUser();
  811.         $currentLogin $user->getUsername();
  812.         $messages = [];
  813.         // Traitement de la modification du login
  814.         if (!empty($newLogin)) {
  815.             if ($newLogin === $currentLogin) {
  816.                 return $this->json(['code' => 400'message' => 'Le nouveau login doit être différent de l\'actuel'], 400);
  817.             }
  818.             // Vérifier si le nouveau login existe déjà
  819.             $existingUser $userRepository->findOneBy(['username' => $newLogin]);
  820.             if ($existingUser && $existingUser->getId() !== $user->getId()) {
  821.                 return $this->json(['code' => 400'message' => 'Ce login existe déjà'], 400);
  822.             }
  823.             $user->setUsername($newLogin);
  824.             $messages[] = 'Login modifié';
  825.         }
  826.         // Traitement de la réinitialisation du mot de passe
  827.         if ($resetPassword) {
  828.             $user->setPassword(
  829.                 $userPasswordHasherInterface->hashPassword(
  830.                     $user,
  831.                     "central-edu"
  832.                 )
  833.             );
  834.             $user->setIsPasswordChanged(false);
  835.             $user->setIsEnabled(true);
  836.             $messages[] = 'Mot de passe réinitialisé';
  837.         }
  838.         try {
  839.             $entityManager $this->getDoctrine()->getManager();
  840.             $entityManager->flush();
  841.             $message implode(' et '$messages) . ' avec succès';
  842.             return $this->json(['code' => 200'message' => $message], 200);
  843.         } catch (\Throwable $th) {
  844.             return $this->json(['code' => 500'message' => 'Une erreur est survenue lors des modifications'], 500);
  845.         }
  846.     }
  847. }