src/Controller/Registration/PreRegistrationController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Registration;
  3. use Knp\Snappy\Pdf;
  4. use App\Entity\User;
  5. use App\Service\SMSSender;
  6. use App\Entity\SettingLevel;
  7. use App\Entity\Establishment;
  8. use App\Repository\SettingLevelRepository;
  9. use App\Repository\EstablishmentRepository;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use App\Repository\RegistrationStudentRepository;
  15. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  16. use App\Entity\RegistrationStudentPreRegistration;
  17. use App\Entity\SchoolYear;
  18. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  19. use App\Repository\RegistrationStudentPreRegistrationRepository;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use App\Form\Registration\PrimaireRegistrationStudentPreRegistrationType;
  22. use App\Form\Registration\SecondaireRegistrationStudentPreRegistrationType;
  23. use App\Repository\SchoolYearRepository;
  24. /**
  25.  * @Route("/online")
  26. */
  27. class PreRegistrationController extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/pre-registration", name="pre_registration", methods={"GET","POST"})
  31.     */
  32.     public function index(EstablishmentRepository $establishmentRepository): Response
  33.     {
  34.         return $this->render('pre_registration/index.html.twig', [
  35.             'establishments' => $establishmentRepository->findBy([],['name' => 'ASC']),
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/pre-registration/verification/{id}", name="pre_registration_verification", methods={"GET","POST"})
  40.      */
  41.     public function verification(Establishment $establishment): Response
  42.     {
  43.         $template 'pre_registration/verification.html.twig';
  44.         
  45.         return $this->render($template, [
  46.             'establishment' => $establishment,
  47.         ]);
  48.     }
  49.     /**
  50.      * @Route("/pre-registration/etablissement/{id}", name="pre_registration_ets", methods={"GET","POST"})
  51.      */
  52.     public function preRegistration(Request $requestEstablishment $establishmentRegistrationStudentRepository $registrationStudentRepository,SMSSender $smsSenderRegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepositorySettingLevelRepository $settingLevelRepositorySchoolYearRepository $schoolYearRepository): Response
  53.     {
  54.         /**@var User $user */
  55.         $user $this->getUser();
  56.         //$schoolYear = $user->getSchoolYear();
  57.         $template 'pre_registration/newPrimaire.html.twig';
  58.         if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  59.             $template 'pre_registration/newSecondaire.html.twig';
  60.         }
  61.         $registrationStudent $registrationStudentRepository->findOneBy(['establishment' => $establishment'registration_number' => $request->get('matricule'), 'is_archived' => 0], []);
  62.         if (null == $registrationStudent) {
  63.             $registrationStudent $registrationStudentRepository->findOneBy(['establishment' => $establishment'code' => $request->get('matricule'), 'is_archived' => 0], []);
  64.         }
  65.         
  66.         if ($request->get('type') == 'old' && $registrationStudent == null) {
  67.             $this->addFlash('warning'"Matricule incorrect");
  68.             return $this->redirectToRoute('pre_registration_verification', ['id' => $establishment->getId()]);
  69.         }
  70.         $registrationStudentPreRegistration = new RegistrationStudentPreRegistration();
  71.         
  72.         if ($registrationStudent == null) {
  73.             $registrationStudentPreRegistration->setRegistrationNumber('AUCUN');
  74.             $registrationStudentPreRegistration->setLastSchoolAttended('AUCUN');
  75.         }else {
  76.             $registrationStudentPreRegistration->setHoldStudentId($registrationStudent->getId());
  77.             $registrationStudentPreRegistration->setAccompanyingPersonName($registrationStudent->getAccompanyingPersonName());
  78.             $registrationStudentPreRegistration->setAccompanyingPersonPhoneNumber($registrationStudent->getAccompanyingPersonPhoneNumber());
  79.             $registrationStudentPreRegistration->setFatherAddress($registrationStudent->getFatherAddress());
  80.             $registrationStudentPreRegistration->setFatherEmail($registrationStudent->getFatherEmail());
  81.             $registrationStudentPreRegistration->setFatherFirstName($registrationStudent->getFatherFirstName());
  82.             $registrationStudentPreRegistration->setFatherLastName($registrationStudent->getFatherLastName());
  83.             $registrationStudentPreRegistration->setFatherPhoneNumber($registrationStudent->getFatherPhoneNumber());
  84.             $registrationStudentPreRegistration->setIsFatherCallToEmergency($registrationStudent->getIsFatherCallToEmergency());
  85.             $registrationStudentPreRegistration->setIsParntalAuthorityFather($registrationStudent->getIsParntalAuthorityFather());
  86.             $registrationStudentPreRegistration->setFatherLocation($registrationStudent->getFatherLocation());
  87.             $registrationStudentPreRegistration->setFatherPost($registrationStudent->getFatherPost());
  88.             $registrationStudentPreRegistration->setMotherAddress($registrationStudent->getMotherAddress());
  89.             $registrationStudentPreRegistration->setMotherEmail($registrationStudent->getMotherEmail());
  90.             $registrationStudentPreRegistration->setMotherFirstName($registrationStudent->getMotherFirstName());
  91.             $registrationStudentPreRegistration->setMotherLastName($registrationStudent->getMotherLastName());
  92.             $registrationStudentPreRegistration->setMotherPhoneNumber($registrationStudent->getMotherPhoneNumber());
  93.             $registrationStudentPreRegistration->setIsMotherCallToEmergency($registrationStudent->getIsMotherCallToEmergency());
  94.             $registrationStudentPreRegistration->setIsParntalAuthorityMother($registrationStudent->getIsParntalAuthorityMother());
  95.             $registrationStudentPreRegistration->setMotherLocation($registrationStudent->getMotherLocation());
  96.             $registrationStudentPreRegistration->setMotherPost($registrationStudent->getMotherPost());
  97.             $registrationStudentPreRegistration->setFirstName($registrationStudent->getFirstName());
  98.             $registrationStudentPreRegistration->setLastName($registrationStudent->getLastName());
  99.             $registrationStudentPreRegistration->setImage($registrationStudent->getImage());
  100.             $registrationStudentPreRegistration->setIsAffected($registrationStudent->getIsAffected());
  101.             $registrationStudentPreRegistration->setLocation($registrationStudent->getLocation());
  102.             $registrationStudentPreRegistration->setLv1($registrationStudent->getLv1());
  103.             $registrationStudentPreRegistration->setLv2($registrationStudent->getLv2());
  104.             $registrationStudentPreRegistration->setNationality($registrationStudent->getNationality());
  105.             $registrationStudentPreRegistration->setBirthday($registrationStudent->getBirthday());
  106.             $registrationStudentPreRegistration->setBirthLocation($registrationStudent->getBirthLocation());
  107.             $registrationStudentPreRegistration->setBirthCertificateNumber($registrationStudent->getBirthCertificateNumber());
  108.             $registrationStudentPreRegistration->setRegistrationNumber($registrationStudent->getRegistrationNumber());
  109.             $registrationStudentPreRegistration->setLastSchoolAttended($registrationStudent->getLastSchoolAttended());
  110.             $registrationStudentPreRegistration->setLastSchoolAttendedType($registrationStudent->getLastSchoolAttendedType());         
  111.             
  112.             $registrationStudentPreRegistration->setNotificationWatsappNumber($registrationStudent->getNotificationWatsappNumber());
  113.             $registrationStudentPreRegistration->setNotificationPhoneNumber($registrationStudent->getNotificationPhoneNumber());
  114.             $registrationStudentPreRegistration->setObservation($registrationStudent->getObservation());
  115.             $registrationStudentPreRegistration->setParentStatus($registrationStudent->getParentStatus());
  116.             $registrationStudentPreRegistration->setResponsibleOfSchooling($registrationStudent->getResponsibleOfSchooling());
  117.             $registrationStudentPreRegistration->setResponsibleOfSchoolingAddress($registrationStudent->getResponsibleOfSchoolingAddress());
  118.             $registrationStudentPreRegistration->setResponsibleOfSchoolingFirstName($registrationStudent->getResponsibleOfSchoolingFirstName());
  119.             $registrationStudentPreRegistration->setResponsibleOfSchoolingLastName($registrationStudent->getResponsibleOfSchoolingLastName());
  120.             $registrationStudentPreRegistration->setResponsibleOfSchoolingLocation($registrationStudent->getResponsibleOfSchoolingLocation());
  121.             $registrationStudentPreRegistration->setResponsibleOfSchoolingPhoneNumber($registrationStudent->getResponsibleOfSchoolingPhoneNumber());
  122.             $registrationStudentPreRegistration->setResponsibleOfSchoolingPost($registrationStudent->getResponsibleOfSchoolingPost());
  123.         }
  124.         $entryLevels = new ArrayCollection();
  125.         foreach ($establishment->getSettingLevels() as $key => $level) {
  126.             if (count($level->getSettingClassrooms()) > 0) {
  127.                 $entryLevels->add($level);
  128.             }
  129.         }
  130.         $form $this->createForm(PrimaireRegistrationStudentPreRegistrationType::class, $registrationStudentPreRegistration)
  131.         
  132.         ->add('entryLevel'EntityType::class, [
  133.             'class' => SettingLevel::class,
  134.             'choices' => $entryLevels,
  135.             'required' => true
  136.         ])
  137.         ->add('classJumps'EntityType::class, [
  138.             'class' => SettingLevel::class,
  139.             'choices' => $entryLevels,
  140.             'required' => false,
  141.             'multiple' => true,
  142.         ])
  143.         ->add('schoolYear'EntityType::class, [
  144.             'class' => SchoolYear::class,
  145.             'choices' => $schoolYearRepository->findBy([], ['id' => 'DESC']),
  146.             'required' => true,
  147.         ]);
  148.         
  149.         if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  150.             $form $this->createForm(SecondaireRegistrationStudentPreRegistrationType::class, $registrationStudentPreRegistration)
  151.             ->add('entryLevel'EntityType::class, [
  152.                 'class' => SettingLevel::class,
  153.                 'choices' => $entryLevels,
  154.                 'required' => true
  155.             ])
  156.             ->add('schoolYear'EntityType::class, [
  157.                 'class' => SchoolYear::class,
  158.                 'choices' => $schoolYearRepository->findBy([], ['id' => 'DESC']),
  159.                 'required' => true,
  160.             ]);
  161.         }
  162.         $form->handleRequest($request);
  163.         if ($form->isSubmitted() && $form->isValid()) {
  164.             $entityManager $this->getDoctrine()->getManager();
  165.             
  166.             //le 29/04/2025
  167.             //cette verification a été ajouté pour résoudre le problème des doublon dans les préinscription niveau collège
  168.             //on verifie que le matricule saisi est different de 'AUCUN'
  169.             if ($registrationStudentPreRegistration->getRegistrationNumber() != 'AUCUN') {
  170.                 //on verifie qu' une préinscription avec le matricule en cour n'existe pas déjà pour l'année en cour
  171.                 $old $registrationStudentPreRegistrationRepository->findOneBy(['schoolYear' => $registrationStudentPreRegistration->getSchoolYear(), 'registration_number' => $registrationStudentPreRegistration->getRegistrationNumber()], []);
  172.                 //si une préinscription existe alors la préinscription est réjetté et un message d'erreur est envoyé
  173.                 if (null != $old) {
  174.                     $this->addFlash('warning'"Une demande de préinscription similaire a déjà été effectué, veuillez contacter l'administration de l'établissement pour plus d'info.");
  175.                     return $this->redirectToRoute('pre_registration_ets', ['id' => $establishment->getId()]);
  176.                 }
  177.             }
  178.             $nextIndex count($registrationStudentPreRegistrationRepository->findBy([], [])) + 1;
  179.             $registrationStudentPreRegistration->setCode('PRE-'.date('Y').'-'.sprintf("%'05s"$nextIndex));
  180.             $registrationStudentPreRegistration->setEstablishment($establishment);
  181.             $registrationStudentPreRegistration->setToxicologicalTestResult('EN COURS');
  182.             $registrationStudentPreRegistration->setPsychologicalTestResult('EN COURS');
  183.             $registrationStudentPreRegistration->setEntryTestResult('EN COURS');
  184.             //$registrationStudentPreRegistration->setSchoolYear($currentYear);
  185.             
  186.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentEntryTestDo() && null == $registrationStudent) {
  187.                 $registrationStudentPreRegistration->setIsSubjectEntryTest(true);
  188.             }
  189.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentPsychologicalTestDo() && null == $registrationStudent) {
  190.                 $registrationStudentPreRegistration->setIsSubjectPsychologicalTest(true);
  191.             }
  192.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentToxicologicalTestDo()) {
  193.                 $registrationStudentPreRegistration->setIsSubjectToxicologicalTest(true);
  194.             }
  195.             /* 28/07/2022 ajout d'une nouvelle condition verifiant que tous les niveaux de l'établissement soient soumis au test */
  196.             if (count($settingLevelRepository->findBy(['establishment' => $registrationStudentPreRegistration->getEstablishment(), 'is_student_toxicological_test_do' =>  1], [])) > 0) {
  197.                 if (!$registrationStudentPreRegistration->getEntryLevel()->getIsStudentToxicologicalTestDo() && $registrationStudentPreRegistration->getIsRedoubling()) {
  198.                     $registrationStudentPreRegistration->setIsSubjectToxicologicalTest(true);
  199.                 }
  200.             }
  201.             $entityManager->persist($registrationStudentPreRegistration);
  202.             $message "";
  203.             $contacts = [];
  204.             $contacts[] = '225'.str_replace(' ''',trim($registrationStudentPreRegistration->getNotificationPhoneNumber()));
  205.             try {
  206.                 if ($registrationStudentPreRegistration->getIsSubjectEntryTest()) {
  207.                     $message "BIENVENUE, Votre pre-inscription a été effectuée avec succès, merci de vous présenter pour le test d'entrée avec le code: %s. Contact: %s";
  208.                 }
  209.     
  210.                 if ($registrationStudentPreRegistration->getIsSubjectPsychologicalTest()) {
  211.                     $message "BIENVENUE, Votre pre-inscription a été effectuée avec succès, merci de vous présenter pour le test Psychologique avec le code: %s. Contact: %s"
  212.                 }
  213.     
  214.                 if ($registrationStudentPreRegistration->getIsSubjectToxicologicalTest()) {
  215.                     $message "BIENVENUE, Votre pre-inscription a été effectuée avec succès, merci de vous présenter pour le Test Toxicologique avec le code: %s. Contact: %s";
  216.                 }
  217.                 if (!$registrationStudentPreRegistration->getIsSubjectToxicologicalTest() && !$registrationStudentPreRegistration->getIsSubjectPsychologicalTest() && !$registrationStudentPreRegistration->getIsSubjectEntryTest()) {
  218.                     $message "BIENVENUE, Votre pre-inscription a été effectuée avec succès, merci de vous présenter au Service Accueil avec le code: %s. Contact: %s";
  219.                 }
  220.                 
  221.                 $entityManager->flush();
  222.                 $registrationStudentPreRegistration->setCode('PRE-'.date('Y').'-'.sprintf("%'05s"$registrationStudentPreRegistration->getId()));
  223.                 $message sprintf($message$registrationStudentPreRegistration->getCode(), $registrationStudentPreRegistration->getEstablishment()->getMobileNumber());
  224.                 $response $smsSender->sendSmsByEstablishment($establishment$message$contacts$smsSender::UNICODE_CHARSET);
  225.                 $entityManager->flush();
  226.                 $this->addFlash('success'$message);
  227.             } catch (\Throwable $th) {
  228.                 $this->addFlash('warning'"Le serveur a rencontré un problème, veuillez rééssayer plus tard.");
  229.                 $this->addFlash('info'$th->getMessage());
  230.                 return $this->redirectToRoute('pre_registration_ets', ['id' => $establishment->getId()]);
  231.             }
  232.             return $this->redirectToRoute('pre_registration_result', ['id' => $registrationStudentPreRegistration->getId()]);
  233.         }
  234.         
  235.         return $this->renderForm($template, [
  236.             'registration_student_pre_pegistration' => $registrationStudentPreRegistration,
  237.             'establishment' => $establishment,
  238.             'form' => $form,
  239.         ]);
  240.     }
  241.     /**
  242.      * @Route("/pre-registration/result/{id}", name="pre_registration_result", methods={"GET"})
  243.      */
  244.     public function preRegistrationResult(RegistrationStudentPreRegistration $registrationStudentPreRegistration): Response
  245.     {
  246.         return $this->renderForm('pre_registration/result.html.twig', [
  247.             'pregistration_student_pre_pegistration' => $registrationStudentPreRegistration,
  248.         ]);
  249.     }
  250.     /**
  251.      * @Route("/pre-registration/{id}/print", name="online_registration_student_pre_registration_print", methods={"GET"})
  252.     */
  253.     public function print(Pdf $knpSnappyPdfRegistrationStudentPreRegistration $registrationStudentPreRegistration)
  254.     {
  255.         /**@var User $user */
  256.         $user $this->getUser();
  257.         //$schoolYear = $user->getSchoolYear();
  258.         $setting $registrationStudentPreRegistration->getEstablishment();
  259.         $template 'registration/print/prePrimaire.html.twig';
  260.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  261.             $template 'registration/print/preSecondaire.html.twig';
  262.         }
  263.         
  264.         $html $this->renderView($template, [
  265.             'registration_student_pre_registration' => $registrationStudentPreRegistration,
  266.             'school_year' => $registrationStudentPreRegistration->getSchoolYear(),
  267.             'setting' => $setting,
  268.         ]);
  269.         $file_name 'PRE_INSCRIPTION_N_'.$registrationStudentPreRegistration->getCode().".pdf";
  270.         return new PdfResponse(
  271.             $knpSnappyPdf->getOutputFromHtml($html),
  272.             $file_name,
  273.             'application/pdf',
  274.             'attachment'
  275.         );
  276.     }
  277. }