src/Controller/Front/FrontPersonDegreeController.php line 179

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Activity;
  4. use App\Entity\Candidate;
  5. use App\Entity\Degree;
  6. use App\Entity\JobOffer;
  7. use App\Entity\JobApplied;
  8. use App\Entity\PersonDegree;
  9. use App\Form\CandidateType;
  10. use App\Form\PersonDegreeType;
  11. use App\Entity\School;
  12. use App\Repository\JobOfferRepository;
  13. use App\Repository\JobAppliedRepository;
  14. use App\Repository\UserRepository;
  15. use App\Repository\PersonDegreeRepository;
  16. use App\Repository\CountryRepository;
  17. use App\Repository\RegionRepository;
  18. use App\Services\ActivityService;
  19. use App\Services\CompanyService;
  20. use App\Services\EmailService;
  21. use App\Services\FileUploader;
  22. use App\Services\PersonDegreeService;
  23. use App\Tools\Utils;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  28. use Symfony\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Component\HttpFoundation\RedirectResponse;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\Mailer\MailerInterface;
  33. use Symfony\Component\Routing\Annotation\Route;
  34. use App\Entity\User;
  35. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  36. use Symfony\Contracts\Translation\TranslatorInterface;
  37. #[Route(path'front/persondegree')]
  38. #[IsGranted('ROLE_DIPLOME')]
  39. class FrontPersonDegreeController extends AbstractController {
  40.     private EntityManagerInterface $em;
  41.     private ActivityService $activityService;
  42.     private PersonDegreeService $personDegreeService;
  43.     private JobOfferRepository $jobOfferRepository;
  44.     private JobAppliedRepository $jobAppliedRepository;
  45.     private EmailService $emailService;
  46.     private UserRepository $userRepository;
  47.     private CompanyService $companyService;
  48.     private FileUploader $fileUploader;
  49.     private PersonDegreeRepository $personDegreeRepository;
  50.     private TokenStorageInterface $tokenStorage;
  51.     private CountryRepository $countryRepository;
  52.     private RegionRepository $regionRepository;
  53.     private TranslatorInterface $translator;
  54.     public function __construct(
  55.         EntityManagerInterface $em,
  56.         ActivityService        $activityService,
  57.         PersonDegreeService    $personDegreeService,
  58.         JobOfferRepository     $jobOfferRepository,
  59.         JobAppliedRepository   $jobAppliedRepository,
  60.         EmailService           $emailService,
  61.         UserRepository         $userRepository,
  62.         CompanyService         $companyService,
  63.         FileUploader           $fileUploader,
  64.         PersonDegreeRepository $personDegreeRepository,
  65.         TokenStorageInterface  $tokenStorage,
  66.         CountryRepository      $countryRepository,
  67.         RegionRepository       $regionRepository,
  68.         TranslatorInterface    $translator
  69.     ) {
  70.         $this->em $em;
  71.         $this->activityService $activityService;
  72.         $this->personDegreeService $personDegreeService;
  73.         $this->jobOfferRepository $jobOfferRepository;
  74.         $this->jobAppliedRepository $jobAppliedRepository;
  75.         $this->emailService $emailService;
  76.         $this->userRepository $userRepository;
  77.         $this->companyService $companyService;
  78.         $this->fileUploader $fileUploader;
  79.         $this->personDegreeRepository $personDegreeRepository;
  80.         $this->tokenStorage $tokenStorage;
  81.         $this->countryRepository $countryRepository;
  82.         $this->regionRepository $regionRepository;
  83.         $this->translator $translator;
  84.     }
  85.     #[Route(path'/new'name'front_persondegree_new'methods: ['GET''POST'])]
  86.     public function newAction(Request $request): RedirectResponse|Response {
  87.         $personDegree = new Persondegree();
  88.         /** @var User $user */
  89.         $user $this->getUser();
  90.         $personDegree->setPhoneMobile1($user->getPhone());
  91.         $personDegree->setCountry($user->getCountry());
  92.         $personDegree->setLocationMode(true);
  93.         $residenceCountryPhoneCode null;
  94.         $selectedCountry $this->getUser()->getCountry();
  95.         if($this->getUser()->getResidenceCountry()) {
  96.             $residenceCountryPhoneCode $this->getUser()->getResidenceCountry()->getPhoneCode();
  97.         }
  98.         $personDegree->setDiaspora($user->isDiaspora());
  99.         $personDegree->setResidenceCountry($user->getResidenceCountry());
  100.         //adaptation dbta
  101.         $selectedRegion null;
  102.         if ($_ENV['STRUCT_PROVINCE_COUNTRY_CITY'] == 'true') {
  103.             if($user->getCountry()?->getId() != $user->getRegion()->getCountry()?->getId()) {
  104.                 $user->setCountry($user->getRegion()->getCountry());
  105.                 $this->em->persist($user);
  106.                 $this->em->flush();
  107.             }
  108.             $personDegree->setRegion($user->getRegion());
  109.             $personDegree->setCountry($user->getRegion()->getCountry());
  110.             $personDegree->setResidenceRegion($user->getResidenceRegion());
  111.             $selectedRegion $personDegree->getRegion();
  112.         }
  113.         $form $this->createForm(PersonDegreeType::class, $personDegree, [
  114.             'selectedCountry' => $selectedCountry->getId()
  115.             ]);
  116.         $form->handleRequest($request);
  117.         $otherCountries $this->countryRepository->getNameAndIndicatif($selectedCountry->getId());
  118.         if ($_ENV['STRUCT_PROVINCE_COUNTRY_CITY'] == 'true') {
  119.             $otherCountries $this->regionRepository->getNameAndIndicatif($selectedCountry->getId());
  120.         }
  121.         if ($form->isSubmitted() && $form->isValid()) {
  122.             $agreeRgpd $form->get('agreeRgpd')->getData();
  123.             if ($agreeRgpd) {
  124.                 $user->setEmail($personDegree->getEmail());
  125.                 $user->setDiaspora($personDegree->isDiaspora());
  126.                 $user->setResidenceCountry($personDegree->getResidenceCountry());
  127.                 $personDegree->setUser($user);
  128.                 $personDegree->setCreatedDate(new \DateTime());
  129.                 $personDegree->setUpdatedDate(new \DateTime());
  130.                 $personDegree->setPhoneMobile1($user->getPhone());
  131.                 $personDegree->setUnlocked(false);
  132.                 $this->em->persist($user);
  133.                 $this->em->persist($personDegree);
  134.                 $this->em->flush();
  135.                 return $this->redirectToRoute('front_persondegree_satisfaction_new');
  136.             }
  137.         }
  138.         return $this->render('persondegree/new.html.twig', [
  139.             'personDegree' => $personDegree,
  140.             'form' => $form->createView(),
  141.             'allActivities' => $this->activityService->getAllActivities(),
  142.             'selectedCountry' => $selectedCountry,
  143.             'selectedRegion' => $selectedRegion,
  144.             'residenceCountryPhoneCode' => $residenceCountryPhoneCode,
  145.             'otherCountries' => $otherCountries,
  146.         ]);
  147.     }
  148.     #[Route(path'/'name'front_persondegree_show'methods: ['GET'])]
  149.     public function showAction(): Response {
  150.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () {
  151.             $personDegree $this->personDegreeService->getPersonDegree();
  152.             if (!$personDegree) return $this->redirectToRoute('front_persondegree_new');
  153.             return $this->render('persondegree/show.html.twig', [
  154.                 'personDegree' => $personDegree,
  155.             ]);
  156.         });
  157.     }
  158.     #[Route(path'/edit'name'front_persondegree_edit'methods: ['GET''POST'])]
  159.     public function editAction(Request $request): RedirectResponse|Response {
  160.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  161.             $personDegree $this->personDegreeService->getPersonDegree();
  162.             $user $this->getUser();
  163.             // var_dump($user->getCountry());die();
  164.             //adaptation for DBTA
  165.             $selectedRegion null;
  166.             if ($_ENV['STRUCT_PROVINCE_COUNTRY_CITY'] == 'true') {
  167.                 if(!$user->getRegion()) {
  168.                     if($personDegree->getRegion()) {
  169.                         $user->setRegion($personDegree->getRegion());
  170.                     }
  171.                 }
  172.                 // if ((!$user->getCountry()) || ($user->getCountry()->getId() != $user->getRegion()->getCountry()->getId())) {
  173.                 if ($user->getCountry()->getId() != $user->getRegion()->getCountry()->getId()) {
  174.                     $user->setCountry($user->getRegion()->getCountry());
  175.                     $this->em->persist($user);
  176.                     $this->em->flush();
  177.                 }
  178.                 $selectedRegion $user->getRegion();
  179.             }
  180.             if (!$personDegree) {
  181.                 return $this->redirectToRoute('front_persondegree_new');
  182.             }
  183.             $createdDate $personDegree->getCreatedDate();
  184.             $selectedCountry $user->getCountry();
  185.             if (!$selectedCountry) {
  186.                 $selectedCountry $personDegree->getCountry();
  187.             }
  188.             $otherCountries $this->countryRepository->getNameAndIndicatif($selectedCountry->getId());
  189.             $residenceCountryPhoneCode null;
  190.             if ($user->getResidenceCountry()) {
  191.                 $residenceCountryPhoneCode $user->getResidenceCountry()->getPhoneCode();
  192.             }
  193.             if($_ENV['STRUCT_PROVINCE_COUNTRY_CITY'] == 'true') {
  194.                 $otherCountries $this->regionRepository->getNameAndIndicatif($selectedCountry->getId());
  195.                 $residenceCountryPhoneCode $user->getResidenceRegion()?->getPhoneCode();
  196.             }
  197.             $editForm $this->createForm(PersonDegreeType::class, $personDegree, ['selectedCountry' => $selectedCountry->getId()]);
  198.             $editForm->handleRequest($request);
  199.             if ($editForm->isSubmitted() && $editForm->isValid()) {
  200.                 $agreeRgpd $editForm->get('agreeRgpd')->getData();
  201.                 if ($agreeRgpd) {
  202.                     //update diaspora informations
  203.                     $residenceCountryPhoneCode $personDegree->getUser()->getResidenceCountry()?->getPhoneCode();
  204.                     // if($_ENV['STRUCT_PROVINCE_COUNTRY_CITY'] == 'true') {
  205.                     //     $residenceCountryPhoneCode = $personDegree->getUser()->getResidenceRegion()?->getPhoneCode();
  206.                     // }
  207.                     $user->setDiaspora($personDegree->isDiaspora());
  208.                     $user->setResidenceCountry($personDegree->getResidenceCountry());
  209.                     $user->setResidenceRegion($personDegree->getResidenceRegion());
  210.                     $this->em->persist($user);
  211.                     // remove autorization to edit for School during Enrollment
  212.                     if($personDegree->isUnlocked()) {
  213.                         $personDegree->setUnlocked(false);
  214.                     }
  215.                     $personDegree->setUser($user);
  216.                     // Patch if no createdDate found
  217.                     $personDegree->setCreatedDate($createdDate);
  218.                     if ($personDegree->getCreatedDate() == null) {
  219.                         if ($personDegree->getUpdatedDate()) {
  220.                             $personDegree->setCreatedDate($personDegree->getUpdatedDate());
  221.                         } else {
  222.                             $personDegree->setCreatedDate(new \DateTime());
  223.                         }
  224.                     }// end patch
  225.                     $personDegree->setUpdatedDate(new \DateTime());
  226.                     $dnsServer $this->getParameter('dnsServer');
  227.                     if ((php_uname('n') != $dnsServer)&&(php_uname('n') != null))
  228.                         $personDegree->setClientUpdateDate(new \DateTime());
  229.                     $this->em->persist($personDegree);
  230.                     $this->em->flush();
  231.                     return $this->redirectToRoute('front_persondegree_satisfaction_new');
  232.                 } else {
  233.                     return $this->redirectToRoute('user_delete_persondegree', ['id' => $personDegree->getId()]);
  234.                 }
  235.             }
  236.             return $this->render('persondegree/edit.html.twig', [
  237.                 'personDegree' => $personDegree,
  238.                 'edit_form' => $editForm->createView(),
  239.                 'allActivities' => $this->activityService->getAllActivities(),
  240.                 'selectedCountry' => $selectedCountry,
  241.                 'selectedRegion' => $selectedRegion,
  242.                 'residenceCountryPhoneCode' => $residenceCountryPhoneCode,
  243.                 'otherCountries' => $otherCountries
  244.             ]);
  245.         });
  246.     }
  247.     #[Route(path'/jobOffers'name'front_persondegree_joboffers'methods: ['GET'])]
  248.     public function listJobOffersAction(): Response {
  249.         if (!$this->personDegreeService->getPersonDegree()) {
  250.             return $this->redirectToRoute('front_persondegree_new');
  251.         } else {
  252.             return $this->redirectToRoute('jobOffer_index');
  253.         }
  254.     }
  255.     #[Route(path'/{id}/job_offer'name'front_persondegree_jobOffer_show'methods: ['GET'])]
  256.     public function showJobOfferAction(JobOffer $jobOffer): Response {
  257.         return $this->render('jobOffer/show.html.twig', [
  258.             'jobOffer' => $jobOffer
  259.         ]);
  260.     }
  261.     #[Route(path'/{id}/candidate'name'front_persondegree_candidate'methods: ['GET''POST'])]
  262.     public function candidateAction(Request $requestJobOffer $jobOfferMailerInterface $mailer): Response {
  263.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request$jobOffer$mailer) {
  264.             $this->companyService->markJobOfferAsView($jobOffer->getId());
  265.             $candidate = new Candidate();
  266.             $form $this->createForm(CandidateType::class, $candidate);
  267.             $form->handleRequest($request);
  268.             if ($form->isSubmitted() && $form->isValid()) {
  269.                 // Save cv/coverLetter
  270.                 $cvFile $form->get('cv')->getData();
  271.                 $coverLetterFile $form->get('coverLetter')->getData();
  272.                 if ($cvFile) {
  273.                     $cvFileName $this->fileUploader->upload($cvFile);
  274.                     $candidate->setCvFilename($cvFileName);
  275.                 }
  276.                 if ($coverLetterFile) {
  277.                     $coverLetterFileName $this->fileUploader->upload($coverLetterFile);
  278.                     $candidate->setCoverLetterFilename($coverLetterFileName);
  279.                 }
  280.                 $personDegree $this->personDegreeService->getPersonDegree();
  281.                 $candidate->setCandidateName(preg_replace('/ /''_'strtolower($personDegree->getFirstname() . '_' $personDegree->getLastname())));
  282.                 $personDegreeEmail null;
  283.                 if ($personDegree->getEmail()) {
  284.                     $personDegreeEmail $personDegree->getEmail();
  285.                 }
  286.                 // creation du journal
  287.                 $jobApplied $this->jobAppliedRepository->findOneByDateAndOfferAndPersonDegree($jobOffer$personDegree->getUser());
  288.                 if($jobApplied) {
  289.                     if ($jobApplied->isSended()) {
  290.                         $this->addFlash('warning'$this->translator->trans('flashbag.already_sending_application'));
  291.                     } else {
  292.                         $this->addFlash('warning'$this->translator->trans('flashbag.last_application_failed_try_again'));
  293.                     }
  294.                 }
  295.                 $jobApplied = new JobApplied();
  296.                 // $jobApplied->setIdOffer($jobOffer);
  297.                 $jobApplied->setIdOffer($jobOffer->getId());
  298.                 // $jobApplied->setIdUser($personDegree->getUser());
  299.                 $jobApplied->setIdUser($personDegree->getUser()->getId());
  300.                 $jobApplied->setIdCity($jobOffer->getCity()->getId());
  301.                 $jobApplied->setAppliedDate(new \DateTime());
  302.                 $candidateName $personDegree->getLastname()." "$personDegree->getFirstname()." ("$personDegree->getId().") " $personDegree->getPhoneMobile1();
  303.                 $jobSender null;
  304.                 $senderType "null";
  305.                 if ($jobOffer->getCompany()) {
  306.                     $jobSender $jobOffer->getCompany()->getName() . ' (' $jobOffer->getCompany()->getId() . ')';
  307.                     $senderType "company";
  308.                 }
  309.                 if ($jobOffer->getSchool()) {
  310.                     $jobSender $jobOffer->getSchool()->getName() . ' (' $jobOffer->getSchool()->getId() . ')';
  311.                     $senderType "school";
  312.                 }
  313.                 $resumed =
  314.                     "%tag_strong%Application date: %tag_end_strong%" $jobApplied->getAppliedDate()->format(Utils::FORMAT_FR)."  By ""%tag_strong%candidate: %tag_end_strong%" $candidateName "%tag_br%" .
  315.                     "%tag_strong%Offer%tag_end_strong% (" $jobOffer->getId() . ") %tag_strong%update date: %tag_end_strong%" $jobOffer->getUpdatedDate()->format(Utils::FORMAT_FR). "%tag_br%".
  316.                     "%tag_strong%From: %tag_end_strong%" $senderType " " $jobSender "%tag_br%".
  317.                     "    %tag_strong%contract: %tag_end_strong%" $this->translator->trans($jobOffer->getContract())."%tag_br%".
  318.                     "    %tag_strong%localization: %tag_end_strong%" $jobOffer->getCity()->getName() ."%tag_br%" .
  319.                     "%tag_strong%Description: %tag_end_strong%";
  320.                 $contractDescription $this->suppressHtmlTags($jobOffer->getDescription());
  321.                 if(strlen($resumed) + strlen($contractDescription) > 700 ){
  322.                     $contractDescription substr($contractDescription,0700 strlen($resumed)) . "... ";
  323.                 }
  324.                 if ($this->emailService->sendCandidateMail($candidate$jobOffer$personDegreeEmail)) {
  325.                     $this->addFlash('success'$this->translator->trans('flashbag.your_application_is_sent_successfully'));
  326.                     $jobOffer->addCandidateSended($personDegree->getUser()->getId());
  327.                     $this->em->persist($jobOffer);
  328.                     $this->em->flush();
  329.                     $jobApplied->setIsSended(true);
  330.                 } else {
  331.                     $this->addFlash('warning'$this->translator->trans('flashbag.error_sending_application'));
  332.                 }
  333.                 $sent "%tag_strong%Error sent, %tag_end_strong% ";
  334.                 if($jobApplied->isSended()) {
  335.                     $sent "%tag_strong%Sent OK, %tag_end_strong% ";
  336.                 }
  337.                 $jobApplied->setResumedApplied("%tag_p%" $sent $resumed $contractDescription "%tag_end_p%");
  338.                 $this->em->persist($jobApplied);
  339.                 $this->em->flush();
  340.                 return $this->redirectToRoute('jobOffer_index');
  341.             }
  342.             return $this->render('frontPersondegree/candidate.html.twig', [
  343.                 'form' => $form->createView(),
  344.                 'jobOffer' => $jobOffer
  345.             ]);
  346.         });
  347.     }
  348.     /**
  349.      * @param string $type
  350.      * @param ?string $message
  351.      */
  352.     private function notifSatisfaction($type 'success'$message null) {
  353.         if (!$message) {
  354.             $message $this->translator->trans('flashbag.thank_you_for_responding_to_the_survey');
  355.         }
  356.         $this->addFlash($type$message);
  357.     }
  358.     #[Route(path'/user_delete/{id}'name'user_delete_persondegree'methods: ['GET'])]
  359.     public function deleteUserAction(PersonDegree $personDegree): RedirectResponse {
  360.         $user $personDegree->getUser();
  361.         /* suppress relation between user and jobApply (JobApply is kept) */
  362.         $jobApplies $this->jobAppliedRepository->findByIdUser($user->getId());
  363.         foreach ($jobApplies as $jobApply) {
  364.             $jobApply->setIdUser(null);
  365.         }
  366.         if ($user) {
  367.             $this->personDegreeService->removeRelations($user);
  368.             $this->personDegreeService->removeRelations($user);
  369.             $this->tokenStorage->setToken(null);
  370.             $this->em->remove($user);
  371.             $this->em->flush();
  372.             $this->addFlash('success'$this->translator->trans('flashbag.the_deletion_is_done_successfully'));
  373.             return $this->redirectToRoute('logout');
  374.         } else {
  375.             $this->addFlash('warning'$this->translator->trans('flashbag.unable_to_delete_account'));
  376.             return $this->redirectToRoute('front_persondegree_new');
  377.         }
  378.     }
  379.     #[Route(path'/filters/{id}/school'name'front_persondegree_filters_school'methods: ['GET'])]
  380.     public function getFiltersBySchoolAction(School $school): JsonResponse {
  381.         $listDegree = [];
  382.         /** @var Degree $degree */
  383.         foreach ($school->getDegrees() as $degree) {
  384.             $listDegree[] = ['id' => $degree->getId(), 'name' => $degree->getName()];
  385.         }
  386.         $listSectorArea = [];
  387.         $listSectorArea[] = ['id' => $school->getSectorArea1()->getId(), 'name' => $school->getSectorArea1()->getName()];
  388.         if ($school->getSectorArea2())
  389.             $listSectorArea[] = ['id' => $school->getSectorArea2()->getId(), 'name' => $school->getSectorArea2()->getName()];
  390.         if ($school->getSectorArea3())
  391.             $listSectorArea[] = ['id' => $school->getSectorArea3()->getId(), 'name' => $school->getSectorArea3()->getName()];
  392.         if ($school->getSectorArea4())
  393.             $listSectorArea[] = ['id' => $school->getSectorArea4()->getId(), 'name' => $school->getSectorArea4()->getName()];
  394.         if ($school->getSectorArea5())
  395.             $listSectorArea[] = ['id' => $school->getSectorArea5()->getId(), 'name' => $school->getSectorArea5()->getName()];
  396.         if ($school->getSectorArea6())
  397.             $listSectorArea[] = ['id' => $school->getSectorArea6()->getId(), 'name' => $school->getSectorArea6()->getName()];
  398.         $listActivity = [];
  399.         /** @var Activity $activity */
  400.         foreach ($school->getActivities1() as $activity) {
  401.             $listActivity[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  402.         }
  403.         if ($school->getActivities2()) {
  404.             /** @var Activity $activity */
  405.             foreach ($school->getActivities2() as $activity) {
  406.                 $listActivity[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  407.             }
  408.         }
  409.         if ($school->getActivities3()) {
  410.             /** @var Activity $activity */
  411.             foreach ($school->getActivities3() as $activity) {
  412.                 $listActivities[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  413.             }
  414.         }
  415.         if ($school->getActivities4()) {
  416.             /** @var Activity $activity */
  417.             foreach ($school->getActivities4() as $activity) {
  418.                 $listActivity[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  419.             }
  420.         }
  421.         if ($school->getActivities5()) {
  422.             /** @var Activity $activity */
  423.             foreach ($school->getActivities5() as $activity) {
  424.                 $listActivity[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  425.             }
  426.         }
  427.         if ($school->getActivities6()) {
  428.             /** @var Activity $activity */
  429.             foreach ($school->getActivities6() as $activity) {
  430.                 $listActivity[] = ['id' => $activity->getId(), 'name' => $activity->getName()];
  431.             }
  432.         }
  433.         return new JsonResponse([$listDegree$listSectorArea$listActivity]);
  434.     }
  435.     #[Route(path'/check_logout'name'check_logout_persondegree'methods: ['GET'])]
  436.     public function check_logout(TokenStorageInterface $tokenStorage): RedirectResponse {
  437.         $personDegree $this->personDegreeService->getPersonDegree();
  438.         $user $this->getUser();
  439.         if (!$personDegree) {
  440.             if ($user) {
  441.                 $this->personDegreeService->removeRelations($user);
  442.                 $tokenStorage->setToken(null);
  443.                 $this->em->remove($user);
  444.                 $this->em->flush();
  445.                 return $this->redirectToRoute('logout');
  446.             } else {
  447.                 $this->addFlash('warning'$this->translator->trans('flashbag.unable_to_delete_account'));
  448.                 return $this->redirectToRoute('front_persondegree_show');
  449.             }
  450.             // update du numéro de téléphone du compte si différente du profil (Attention change de Login)
  451.         } else if ($user->getPhone() != $personDegree->getPhoneMobile1()) {
  452.             // verification de la non existance du user par ce numéro de téléphone
  453.             $usrexist $this->userRepository->findByPhone($personDegree->getPhoneMobile1());
  454.             if ($usrexist) {
  455.                 $this->addFlash('danger'$this->translator->trans('flashbag.the_login_phone_is_already_used_by_another_account'));
  456.                 return $this->redirectToRoute('front_persondegree_edit');
  457.             }
  458.             // modification du numéro de telephone et sortie
  459.             $this->addFlash('warning'$this->translator->trans('flashbag.the_login_phone_for_your_account_will_be_changed') . '|' $user->getUsername() . '|' $personDegree->getPhoneMobile1());
  460.             $user->setUsername($personDegree->getPhoneMobile1());
  461.             $user->setPhone($personDegree->getPhoneMobile1());
  462.             $this->em->persist($user);
  463.             $this->em->flush();
  464.             //envoi du mail des paramètres de connexion
  465.             if ($user->getEmail()) {
  466.                 if ($this->emailService->sendMailConfirmRegistration($user->getEmail(), $personDegree->getFirstname(),
  467.                     "Paramètres de votre compte InserJeune""Diplômé"$user->getPhone())) {
  468.                     $this->addFlash('success'$this->translator->trans('flashbag.your_connection_parameters_are_sent_by_email'));
  469.                 } else {
  470.                     $this->addFlash('danger'$this->translator->trans('flashbag.error_sending_email'));
  471.                 }
  472.             }
  473.             // update de l'adrese email du compte si différente du profil
  474.         } else if ($user->getEmail() != $personDegree->getEmail()) {
  475.             // verification de la non existance du user par cet email
  476.             $usrexist $this->userRepository->findByEmail($personDegree->getEmail());
  477.             if ($usrexist) {
  478.                 $this->addFlash('danger'"L'adresse mail: " $personDegree->getEmail() . " est déjà utilisé dans un autre compte");
  479.                 return $this->redirectToRoute('front_persondegree_edit');
  480.             }
  481.             // modification de l'email et sortie
  482.             if (!$personDegree->getEmail()) {
  483.                 //n'affiche rien car sortie de session !!
  484.                 $this->addFlash('danger'$this->translator->trans('flashbag.remember_to_create_a_valid_email_address'));
  485.             } else {
  486.                 $user->setEmail($personDegree->getEmail());
  487.                 $this->em->persist($user);
  488.                 $this->em->flush();
  489.             }
  490.             //envoi du mail des paramètres de connexion
  491.             if ($user->getEmail()) {
  492.                 if ($this->emailService->sendMailConfirmRegistration($user->getEmail(), $personDegree->getFirstname(),
  493.                     "Paramètres de votre compte InserJeune""Diplômé"$user->getPhone())) {
  494.                     $this->addFlash('success'$this->translator->trans('flashbag.your_connection_parameters_are_sent_by_email'));
  495.                 } else {
  496.                     $this->addFlash('danger'$this->translator->trans('flashbag.error_sending_email'));
  497.                 }
  498.             }
  499.         }
  500.         return $this->redirectToRoute('logout');
  501.     }
  502.     #[Route(path'/getPersondegreesByCoordinates'name'get_persondegrees_by_coordinates'methods: ['GET'])]
  503.     public function getPersondegreesByCoordinates(Request $request): JsonResponse|Response {
  504.         $currentLatitude floatval($request->get('latitude'));
  505.         $currentLongitude floatval($request->get('longitude'));
  506.         $gap floatval($request->get('gap'));
  507.         $currentPersondegree $this->personDegreeService->getPersonDegree();
  508.         $currentId $currentPersondegree?->getId();
  509.         $newLatitude $currentLatitude;
  510.         $newLongitude $currentLongitude;
  511.         // printf(" current pos = %.7f; %.7f\n", $newLatitude, $newLongitude );
  512.         // recherche en base les coordonnées des diplômés de la ville
  513.         $coordinates $this->personDegreeRepository->getPersondegreesByCityForCoordinates($currentPersondegree->getAddressCity());
  514.         //boucle sur 300 gaps de longitude
  515.         $maxDuplicateLongitude 300;
  516.         $maxDuplicateLatitude 16;
  517.         for ($j 0$j $maxDuplicateLongitude$j++) {
  518.             // printf("\n---$j = %d----------------------------------------------------\n",$j);
  519.             // boucle sur 16 gaps de latitude (s'il existe un acteur dans les 20 gaps, on passe à la longitude supérieure)
  520.             $actorExist = [];
  521.             for ($i 1$i $maxDuplicateLatitude$i++) {
  522.                 // printf("-------$i = %d-------------------------------------------------\n",$i);
  523.                 // echo("current =" .$currentId. ": " .$currentLatitude. ";" .$currentLongitude); printf("\n");
  524.                 $actorExist[$i] = "free";
  525.                 for ($k 0$k count($coordinates); $k++) {
  526.                     $actorId intval($coordinates[$k]['id']);
  527.                     if ($actorId != $currentId) {
  528.                         $actorLatitude floatval($coordinates[$k]['latitude']);
  529.                         $actorLongitude floatval($coordinates[$k]['longitude']);
  530.                         if(($actorLatitude $currentLatitude $gap * ($i-1)) &&
  531.                             ($actorLatitude <= $currentLatitude $gap $i) &&
  532.                             ($actorLongitude >= $currentLongitude $gap * ($j)) &&
  533.                             ($actorLongitude <= $currentLongitude $gap * ($j+1))) {
  534.                             // printf("actor =%s : %.6f; %.6f\n", $actorId, $actorLatitude, $actorLongitude );
  535.                             $actorExist[$i] = "used";
  536.                         }
  537.                     }
  538.                 }
  539.             }
  540.             if (in_array("free"$actorExist)) {
  541.                 // debugg : affiche les cases libres
  542.                 // var_dump("");
  543.                 // for ($i = 1; $i < count($actorExist)+1; $i++) {
  544.                 //     echo $actorExist[$i] . " | ";
  545.                 // }
  546.                 // var_dump("");
  547.                 for ($i 1$i count($actorExist)+1$i++) {
  548.                     if($actorExist[$i] == "free") {
  549.                         // printf('%.7f;%.7f',$gap * $i , $gap * $j);
  550.                         $newLatitude $currentLatitude $gap $i;
  551.                         $newLongitude $currentLongitude $gap $j;
  552.                         $i count($actorExist);
  553.                     }
  554.                 }
  555.                 // printf(" new pos = %.7f; %.7f\n", $newLatitude, $newLongitude );
  556.                 $j $maxDuplicateLongitude;
  557.             }
  558.         }
  559.         $newCoordinates = ['latitude' => $newLatitude'longitude' => $newLongitude];
  560.         $result = ['personDegree_id'=> $currentId'coordinates' => $newCoordinates];
  561.         return new JsonResponse($result);
  562.     }
  563.     private function suppressHtmlTags (string $str) : String {
  564.         $inputs explode('<',$str);
  565.         $result "";
  566.         foreach ($inputs as $input) {
  567.             $inputExplodes explode('>'$input);
  568.             if (count($inputExplodes)>1) {
  569.                 $result .= $inputExplodes[1];
  570.             }
  571.         }
  572.         return $result;
  573.     }
  574. }