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.             $nextIndex count($registrationStudentPreRegistrationRepository->findBy([], [])) + 1;
  166.             $registrationStudentPreRegistration->setCode('PRE-'.date('Y').'-'.sprintf("%'05s"$nextIndex));
  167.             $registrationStudentPreRegistration->setEstablishment($establishment);
  168.             $registrationStudentPreRegistration->setToxicologicalTestResult('EN COURS');
  169.             $registrationStudentPreRegistration->setPsychologicalTestResult('EN COURS');
  170.             $registrationStudentPreRegistration->setEntryTestResult('EN COURS');
  171.             //$registrationStudentPreRegistration->setSchoolYear($currentYear);
  172.             
  173.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentEntryTestDo() && null == $registrationStudent) {
  174.                 $registrationStudentPreRegistration->setIsSubjectEntryTest(true);
  175.             }
  176.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentPsychologicalTestDo() && null == $registrationStudent) {
  177.                 $registrationStudentPreRegistration->setIsSubjectPsychologicalTest(true);
  178.             }
  179.             if ($registrationStudentPreRegistration->getEntryLevel()->getIsStudentToxicologicalTestDo()) {
  180.                 $registrationStudentPreRegistration->setIsSubjectToxicologicalTest(true);
  181.             }
  182.             /* 28/07/2022 ajout d'une nouvelle condition verifiant que tous les niveaux de l'établissement soient soumis au test */
  183.             if (count($settingLevelRepository->findBy(['establishment' => $registrationStudentPreRegistration->getEstablishment(), 'is_student_toxicological_test_do' =>  1], [])) > 0) {
  184.                 if (!$registrationStudentPreRegistration->getEntryLevel()->getIsStudentToxicologicalTestDo() && $registrationStudentPreRegistration->getIsRedoubling()) {
  185.                     $registrationStudentPreRegistration->setIsSubjectToxicologicalTest(true);
  186.                 }
  187.             }
  188.             $entityManager->persist($registrationStudentPreRegistration);
  189.             $message "";
  190.             $contacts = [];
  191.             $contacts[] = '225'.str_replace(' ''',trim($registrationStudentPreRegistration->getNotificationPhoneNumber()));
  192.             try {
  193.                 if ($registrationStudentPreRegistration->getIsSubjectEntryTest()) {
  194.                     $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";
  195.                 }
  196.     
  197.                 if ($registrationStudentPreRegistration->getIsSubjectPsychologicalTest()) {
  198.                     $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"
  199.                 }
  200.     
  201.                 if ($registrationStudentPreRegistration->getIsSubjectToxicologicalTest()) {
  202.                     $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";
  203.                 }
  204.                 if (!$registrationStudentPreRegistration->getIsSubjectToxicologicalTest() && !$registrationStudentPreRegistration->getIsSubjectPsychologicalTest() && !$registrationStudentPreRegistration->getIsSubjectEntryTest()) {
  205.                     $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";
  206.                 }
  207.                 
  208.                 $entityManager->flush();
  209.                 $registrationStudentPreRegistration->setCode('PRE-'.date('Y').'-'.sprintf("%'05s"$registrationStudentPreRegistration->getId()));
  210.                 $message sprintf($message$registrationStudentPreRegistration->getCode(), $registrationStudentPreRegistration->getEstablishment()->getMobileNumber());
  211.                 $response $smsSender->sendSmsByEstablishment($establishment$message$contacts$smsSender::UNICODE_CHARSET);
  212.                 $entityManager->flush();
  213.                 $this->addFlash('success'$message);
  214.             } catch (\Throwable $th) {
  215.                 $this->addFlash('warning'"Le serveur a rencontré un problème, veuillez rééssayer plus tard.");
  216.                 $this->addFlash('info'$th->getMessage());
  217.                 return $this->redirectToRoute('pre_registration_ets', ['id' => $establishment->getId()]);
  218.             }
  219.             return $this->redirectToRoute('pre_registration_result', ['id' => $registrationStudentPreRegistration->getId()]);
  220.         }
  221.         
  222.         return $this->renderForm($template, [
  223.             'registration_student_pre_pegistration' => $registrationStudentPreRegistration,
  224.             'establishment' => $establishment,
  225.             'form' => $form,
  226.         ]);
  227.     }
  228.     /**
  229.      * @Route("/pre-registration/result/{id}", name="pre_registration_result", methods={"GET"})
  230.      */
  231.     public function preRegistrationResult(RegistrationStudentPreRegistration $registrationStudentPreRegistration): Response
  232.     {
  233.         return $this->renderForm('pre_registration/result.html.twig', [
  234.             'pregistration_student_pre_pegistration' => $registrationStudentPreRegistration,
  235.         ]);
  236.     }
  237.     /**
  238.      * @Route("/pre-registration/{id}/print", name="online_registration_student_pre_registration_print", methods={"GET"})
  239.     */
  240.     public function print(Pdf $knpSnappyPdfRegistrationStudentPreRegistration $registrationStudentPreRegistration)
  241.     {
  242.         /**@var User $user */
  243.         $user $this->getUser();
  244.         //$schoolYear = $user->getSchoolYear();
  245.         $setting $registrationStudentPreRegistration->getEstablishment();
  246.         $template 'registration/print/prePrimaire.html.twig';
  247.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  248.             $template 'registration/print/preSecondaire.html.twig';
  249.         }
  250.         
  251.         $html $this->renderView($template, [
  252.             'registration_student_pre_registration' => $registrationStudentPreRegistration,
  253.             'school_year' => $registrationStudentPreRegistration->getSchoolYear(),
  254.             'setting' => $setting,
  255.         ]);
  256.         $file_name 'PRE_INSCRIPTION_N_'.$registrationStudentPreRegistration->getCode().".pdf";
  257.         return new PdfResponse(
  258.             $knpSnappyPdf->getOutputFromHtml($html),
  259.             $file_name,
  260.             'application/pdf',
  261.             'attachment'
  262.         );
  263.     }
  264. }