src/Controller/Front/FrontPersonDegreeSatisfactionController.php line 300

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\SatisfactionCreator;
  4. use App\Entity\SatisfactionSalary;
  5. use App\Entity\SatisfactionSearch;
  6. use App\Form\SatisfactionCreatorType;
  7. use App\Form\SatisfactionSalaryType;
  8. use App\Form\SatisfactionSearchType;
  9. use App\Repository\SatisfactionCreatorRepository;
  10. use App\Repository\SatisfactionSalaryRepository;
  11. use App\Repository\SatisfactionSearchRepository;
  12. use App\Services\PersonDegreeService;
  13. use App\Services\SatisfactionService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\RequestStack;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use App\Tools\Utils;
  24. use Symfony\Contracts\Translation\TranslatorInterface;
  25. #[Route(path'front/persondegree')]
  26. #[IsGranted('ROLE_DIPLOME')]
  27. class FrontPersonDegreeSatisfactionController extends AbstractController {
  28.     private EntityManagerInterface $em;
  29.     private PersonDegreeService $personDegreeService;
  30.     private SatisfactionSalaryRepository $satisfactionSalaryRepository;
  31.     private SatisfactionSearchRepository $searchRepository;
  32.     private SatisfactionCreatorRepository $satisfactionCreatorRepository;
  33.     private SatisfactionService $satisfactionService;
  34.     private RequestStack $requestStack;
  35.     private TranslatorInterface $translator;
  36.     public function __construct(
  37.         EntityManagerInterface        $em,
  38.         PersonDegreeService           $personDegreeService,
  39.         SatisfactionSalaryRepository  $satisfactionSalaryRepository,
  40.         SatisfactionSearchRepository  $searchRepository,
  41.         SatisfactionCreatorRepository $satisfactionCreatorRepository,
  42.         SatisfactionService           $satisfactionService,
  43.         RequestStack                  $requestStack,
  44.         TranslatorInterface $translator
  45.     ) {
  46.         $this->em $em;
  47.         $this->personDegreeService $personDegreeService;
  48.         $this->satisfactionSalaryRepository $satisfactionSalaryRepository;
  49.         $this->searchRepository $searchRepository;
  50.         $this->satisfactionCreatorRepository $satisfactionCreatorRepository;
  51.         $this->satisfactionService $satisfactionService;
  52.         $this->requestStack $requestStack;
  53.         $this->translator $translator;
  54.     }
  55.     #[Route(path'/satisfaction'name'front_persondegree_satisfaction'methods: ['GET''POST'])]
  56.     public function setSatisfaction(Request $request): RedirectResponse|Response {
  57.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  58.             $personDegree $this->personDegreeService->getPersonDegree();
  59.             if (!$personDegree) return $this->redirectToRoute('front_persondegree_new');
  60.             return match ($personDegree->getTypeUtils()) {
  61.                 PersonDegreeService::TYPE_EMPLOYED => $this->redirectToRoute('front_persondegree_satisfactionsalary_index'),
  62.                 PersonDegreeService::TYPE_UNEMPLOYED => $this->redirectToRoute('front_persondegree_satisfaction_search_index'),
  63.                 PersonDegreeService::TYPE_CONTRACTOR => $this->redirectToRoute('front_persondegree_satisfactioncreator_index'),
  64.                 default => $this->redirectToRoute('front_persondegree_show'),
  65.             };
  66.         });
  67.     }
  68.     #[Route(path'/satisfactions'name'front_persondegree_satisfactions_index'methods: ['GET'])]
  69.     public function indexSatisfactionsAction(): Response {
  70.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () {
  71.             $personDegree $this->personDegreeService->getPersonDegree();
  72.             $satisfactionSalaries $this->satisfactionSalaryRepository->getSatisfactionSalaries($personDegree);
  73.             $satisfactionSearchs $this->searchRepository->getSatisfactionSearchs($personDegree);
  74.             $satisfactionCreators $this->satisfactionCreatorRepository->getSatisfactionCreators($personDegree);
  75.             return $this->render('frontPersondegree/satisfactions.html.twig', [
  76.                 'satisfactionSalaries' => $satisfactionSalaries,
  77.                 'satisfactionSearchs' => $satisfactionSearchs,
  78.                 'satisfactionCreators' => $satisfactionCreators,
  79.             ]);
  80.         });
  81.     }
  82.     #[Route(path'/satisfactionsalary'name'front_persondegree_satisfactionsalary_index'methods: ['GET'])]
  83.     public function indexSatisfactionSalaryAction(): Response {
  84.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () {
  85.             $satisfactionSalaries $this
  86.                 ->satisfactionSalaryRepository
  87.                 ->getSatisfactionSalaries($this->personDegreeService->getPersonDegree());
  88.             return $this->render('satisfactionsalary/index.html.twig', [
  89.                 'satisfactionSalaries' => $satisfactionSalaries,
  90.             ]);
  91.         });
  92.     }
  93.     #[Route(path'/satisfactionSearch'name'front_persondegree_satisfaction_search_index'methods: ['GET'])]
  94.     public function indexSatisfactionSearchAction(): Response {
  95.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () {
  96.             $satisfactionSearches $this->searchRepository
  97.                 ->findBy(['personDegree' => $this->personDegreeService->getPersonDegree()]);
  98.             return $this->render('satisfactionSearch/index.html.twig', array(
  99.                 'satisfactionSearches' => $satisfactionSearches,
  100.             ));
  101.         });
  102.     }
  103.     #[Route(path'/satisfactioncreator'name'front_persondegree_satisfactioncreator_index'methods: ['GET'])]
  104.     public function indexSatisfactionCreatorAction(): Response {
  105.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () {
  106.             $satisfactionCreators $this->satisfactionCreatorRepository
  107.                 ->findBy(['personDegree' => $this->personDegreeService->getPersonDegree()]);
  108.             return $this->render('satisfactioncreator/index.html.twig', array(
  109.                 'satisfactionCreators' => $satisfactionCreators,
  110.             ));
  111.         });
  112.     }
  113.     /**
  114.      * Permet au diplomé de remplir une satisfaction selon son type (en emploi, chercheur d'emploi ou créateur d'emploi)
  115.      */
  116.     #[Route(path'/satisfaction/new'name'front_persondegree_satisfaction_new'methods: ['GET''POST'])]
  117.     public function newSatisfactionAction(Request $request): RedirectResponse {
  118.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  119.             $personDegree $this->personDegreeService->getPersonDegree();
  120.             $typePerson $personDegree->getType();
  121.             switch ($typePerson) {
  122.                 case PersonDegreeService::TYPE_SEARCH:
  123.                 case PersonDegreeService::TYPE_STUDY:
  124.                 case PersonDegreeService::TYPE_UNEMPLOYED:
  125.                     {
  126.                         $redirect 'front_persondegree_satisfaction_search';
  127.                         $repository SatisfactionSearch::class;
  128.                     }
  129.                     break;
  130.                 case PersonDegreeService::TYPE_EMPLOYED:
  131.                     {
  132.                         $redirect 'front_persondegree_satisfactionsalary';
  133.                         $repository SatisfactionSalary::class;
  134.                     }
  135.                     break;
  136.                 case PersonDegreeService::TYPE_CONTRACTOR:
  137.                     {
  138.                         $redirect 'front_persondegree_satisfactioncreator';
  139.                         $repository SatisfactionCreator::class;
  140.                     }
  141.                     break;
  142.                 default:
  143.                 {
  144.                     $this->addFlash(Utils::FB_WARNING$this->translator->trans('flashbag.no_survey_available'));
  145.                     return $this->redirectToRoute('front_persondegree_show');
  146.                 }
  147.             }
  148.             // calcul de la date de creation de l'enquête:  0 mois apres l'obstension du diplôme
  149.             $degreeDateStr sprintf('%s-%s-01'$personDegree->getLastDegreeYear(), $personDegree->getLastDegreeMonth());
  150.             $beginDate $this->satisfactionService->createBeginDate(new \DateTime($degreeDateStr), 0);
  151.             // recherche la derniere satisfaction créé en fonction de la situation professionelle du diplômé
  152.             // $satisfaction = $this->getDoctrine()->getRepository($repository)->getLastSatisfaction($personDegree);
  153.             $satisfaction $this->em->getRepository($repository)->getLastSatisfaction($personDegree);
  154.             // calcul de la date de fin d'enquête sur le formulaire: 12 mois apres la date de début
  155.             // $endedUpdateDate = $this->satisfactionService->createEndedUpdateDate(new \DateTime($degreeDateStr), 12);
  156.             if ($satisfaction) {
  157.                 $endedUpdateDate $this->satisfactionService->createEndedUpdateDate(clone ($satisfaction)->getCreatedDate(), 12);
  158.             } else {
  159.                 $endedUpdateDate = (new \DateTime());
  160.             }
  161.             // si la date de l'obstention du diplôme est dépassée, pas d'enquête possible
  162.             if ((!$satisfaction) || strtotime($this->formatUS($endedUpdateDate)) < strtotime($this->now())) {
  163.                 $this->addFlash(Utils::FB_WARNING$this->translator->trans('flashbag.you_have_to_answer_a_new_survey_since_date', ['{date}' => $endedUpdateDate->format(Utils::FORMAT_FR)]));
  164.                 $redirect sprintf('%s_%s'$redirect'new');
  165.                 // si la date est située entre $beginDate et $endedUpdateDate
  166.             } else if (strtotime($this->formatUS($beginDate)) <= strtotime($this->now()) && strtotime($this->formatUS($endedUpdateDate)) > strtotime($this->now())) {
  167.                 // si satisfaction existante et valide : modification possible
  168.                 if ($satisfaction) {
  169.                     $satisfactionDate $satisfaction->getCreatedDate();
  170.                     if (strtotime($this->formatUS($satisfactionDate)) >= strtotime($this->formatUS($beginDate)) && strtotime($this->formatUS($satisfactionDate)) < strtotime($this->formatUS($endedUpdateDate))) {
  171.                         $redirect sprintf('%s_%s'$redirect'edit');
  172.                         $this->addFlash(Utils::FB_WARNING$this->translator->trans('flashbag.you_can_edit_this_survey_until_date', ['{date}' => $endedUpdateDate->format(Utils::FORMAT_FR)]));
  173.                         return $this->redirectToRoute($redirect, ['id' => $satisfaction->getId()]);
  174.                     }
  175.                 }
  176.                 // sinon creation d'une nouvelle
  177.                 $redirect sprintf('%s_%s'$redirect'new');
  178.             } else {
  179.                 $this->addFlash(Utils::FB_WARNING$this->translator->trans('flashbag.you_can_create_a_survey_from_date', ['{date}' => $beginDate->format(Utils::FORMAT_FR)]));
  180.                 $redirect "front_persondegree_show";
  181.             }
  182.             return $this->redirectToRoute($redirect);
  183.         });
  184.     }
  185.     #[Route(path'/satisfactionSalary/new'name'front_persondegree_satisfactionsalary_new'methods: ['GET''POST'])]
  186.     public function newSatisfactionSalaryAction(Request $request): RedirectResponse|bool|Response {
  187.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  188.             $checkRedirection $this->checkRedirection($request);
  189.             if (!$checkRedirection) {
  190.                 return $checkRedirection;
  191.             }
  192.             $personDegree $this->personDegreeService->getPersonDegree();
  193.             $selectedCountry $personDegree->getCountry();
  194.             $satisfactionSalary = new SatisfactionSalary();
  195.             $satisfactionSalary->setPersonDegree($personDegree);
  196.             $satisfactionSalary->setDegreeDate(sprintf('%02d'$personDegree->getLastDegreeMonth()) . '/' $personDegree->getLastDegreeYear());
  197.             $form $this->createForm(SatisfactionSalaryType::class, $satisfactionSalary, ['selectedCountry' => $selectedCountry->getId()]);
  198.             $form->handleRequest($request);
  199.             if ($form->isSubmitted() && $form->isValid()) {
  200.                 $satisfactionSalary->setCreatedDate(new \DateTime());
  201.                 $satisfactionSalary->setUpdatedDate(new \DateTime());
  202.                 $satisfactionSalary->setPersonDegree($personDegree);
  203.                 $this->em->persist($satisfactionSalary);
  204.                 $this->em->flush();
  205.                 $this->notifSatisfaction();
  206.                 return $this->redirectToRoute('front_persondegree_satisfactionsalary_show', ['id' => $satisfactionSalary->getId()]);
  207.             }
  208.             $this->notifSatisfaction(Utils::FB_WARNING"Merci de compléter ce questionnaire d'insertion");
  209.             return $this->render('satisfactionsalary/new.html.twig', [
  210.                 'satisfactionSalary' => $satisfactionSalary,
  211.                 'form' => $form->createView(),
  212.                 'personDegree' => $personDegree,
  213.                 'selectedCountry' => $selectedCountry
  214.             ]);
  215.         });
  216.     }
  217.     #[Route(path'/satisfactionSearch/new'name'front_persondegree_satisfaction_search_new'methods: ['GET''POST'])]
  218.     public function newSatisfactionSearchAction(Request $request): RedirectResponse|bool|Response {
  219.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  220.             $checkRedirection $this->checkRedirection($request);
  221.             if (!$checkRedirection) {
  222.                 return $checkRedirection;
  223.             }
  224.             $personDegree $this->personDegreeService->getPersonDegree();
  225.             $satisfactionSearch = new SatisfactionSearch();
  226.             $satisfactionSearch->setPersonDegree($personDegree);
  227.             $satisfactionSearch->setDegreeDate(sprintf('%02d'$personDegree->getLastDegreeMonth()) . '/' $personDegree->getLastDegreeYear());
  228.             $form $this->createForm(SatisfactionSearchType::class, $satisfactionSearch);
  229.             $form->handleRequest($request);
  230.             if ($form->isSubmitted() && $form->isValid()) {
  231.                 $satisfactionSearch->setCreatedDate(new \DateTime());
  232.                 $satisfactionSearch->setUpdatedDate(new \DateTime());
  233.                 $satisfactionSearch->setPersonDegree($personDegree);
  234.                 $this->em->persist($satisfactionSearch);
  235.                 $this->em->flush();
  236.                 $this->notifSatisfaction();
  237.                 return $this->redirectToRoute('front_persondegree_satisfaction_search_show', ['id' => $satisfactionSearch->getId()]);
  238.             }
  239.             $this->notifSatisfaction(Utils::FB_WARNING"Merci de compléter ce questionnaire d'insertion");
  240.             return $this->render('satisfactionSearch/new.html.twig', [
  241.                 'satisfactionSearch' => $satisfactionSearch,
  242.                 'form' => $form->createView(),
  243.                 'personDegree' => $personDegree
  244.             ]);
  245.         });
  246.     }
  247.     /**
  248.      * Les liens actions ajouter de satisfactions seront par redirection de newSatisfactionAction()
  249.      * @param Request $request
  250.      * @return bool|RedirectResponse
  251.      */
  252.     public function checkRedirection(Request $request): RedirectResponse|bool {
  253.         if (!array_key_exists('HTTP_REFERER'$request->server->all())) {
  254.             $this->addFlash(Utils::FB_WARNING$this->translator->trans('flashbag.please_click_survey_in_progress_to_add_or_modify_a_survey'));
  255.             return $this->redirectToRoute('front_persondegree_show');
  256.         }
  257.         return true;
  258.     }
  259.     #[Route(path'/satisfactionCreator/new'name'front_persondegree_satisfactioncreator_new'methods: ['GET''POST'])]
  260.     public function newSatisfactionCreatorAction(Request $request): RedirectResponse|bool|Response {
  261.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request) {
  262.             $checkRedirection $this->checkRedirection($request);
  263.             if (!$checkRedirection) {
  264.                 return $checkRedirection;
  265.             }
  266.             $personDegree $this->personDegreeService->getPersonDegree();
  267.             $satisfactionCreator = new SatisfactionCreator();
  268.             $satisfactionCreator->setPersonDegree($personDegree);
  269.             $satisfactionCreator->setDegreeDate(sprintf('%02d'$personDegree->getLastDegreeMonth()) . '/' $personDegree->getLastDegreeYear());
  270.             $form $this->createForm(SatisfactionCreatorType::class, $satisfactionCreator);
  271.             $form->handleRequest($request);
  272.             if ($form->isSubmitted() && $form->isValid()) {
  273.                 $satisfactionCreator->setCreatedDate(new \DateTime());
  274.                 $satisfactionCreator->setUpdatedDate(new \DateTime());
  275.                 $satisfactionCreator->setPersonDegree($personDegree);
  276.                 $this->em->persist($satisfactionCreator);
  277.                 $this->em->flush();
  278.                 $this->notifSatisfaction();
  279.                 return $this->redirectToRoute('front_persondegree_satisfactioncreator_show', ['id' => $satisfactionCreator->getId()]);
  280.             }
  281.             $this->notifSatisfaction(Utils::FB_WARNING"Merci de compléter ce questionnaire d'insertion");
  282.             return $this->render('satisfactioncreator/new.html.twig', [
  283.                 'satisfactionCreator' => $satisfactionCreator,
  284.                 'form' => $form->createView(),
  285.                 'personDegree' => $personDegree
  286.             ]);
  287.         });
  288.     }
  289.     #[Route(path'/satisfactioncreator/{id}/show'name'front_persondegree_satisfactioncreator_show'methods: ['GET''POST'])]
  290.     public function showSatisfactionCreatorAction(SatisfactionCreator $satisfactionCreator): Response {
  291.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($satisfactionCreator) {
  292.             $personDegree $this->personDegreeService->getPersonDegree();
  293.             if (!$personDegree) return $this->redirectToRoute('front_persondegree_new');
  294.             return $this->render('satisfactioncreator/show.html.twig', [
  295.                 'persondegree' => $personDegree,
  296.                 'satisfactionCreator' => $satisfactionCreator,
  297.             ]);
  298.         });
  299.     }
  300.     #[Route(path'/satisfactionSearch/{id}/show'name'front_persondegree_satisfaction_search_show'methods: ['GET'])]
  301.     public function showSatisfactionSearchAction(SatisfactionSearch $satisfactionSearch): Response {
  302.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($satisfactionSearch) {
  303.             $personDegree $this->personDegreeService->getPersonDegree();
  304.             if (!$personDegree) return $this->redirectToRoute('front_persondegree_new');
  305.             return $this->render('satisfactionSearch/show.html.twig', [
  306.                 'persondegree' => $personDegree,
  307.                 'satisfactionSearch' => $satisfactionSearch,
  308.             ]);
  309.         });
  310.     }
  311.     #[Route(path'/satisfactionSalary/{id}/show'name'front_persondegree_satisfactionsalary_show'methods: ['GET'])]
  312.     public function showSatisfactionSalaryAction(SatisfactionSalary $satisfactionSalary): Response {
  313.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($satisfactionSalary) {
  314.             $personDegree $this->personDegreeService->getPersonDegree();
  315.             if (!$personDegree) {
  316.                 return $this->redirectToRoute('front_persondegree_new');
  317.             }
  318.             return $this->render('satisfactionsalary/show.html.twig', [
  319.                 'persondegree' => $personDegree,
  320.                 'satisfactionSalary' => $satisfactionSalary,
  321.             ]);
  322.         });
  323.     }
  324.     #[Route(path'/satisfactionSalary/{id}/edit'name'front_persondegree_satisfactionsalary_edit'methods: ['GET''POST'])]
  325.     public function editSatisfactionSalaryAction(Request $requestSatisfactionSalary $satisfactionSalary): RedirectResponse|Response {
  326.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request$satisfactionSalary) {
  327.             $createdDate $satisfactionSalary->getCreatedDate();
  328.             $personDegree $this->personDegreeService->getPersonDegree();
  329.             $selectedCountry $personDegree->getCountry();
  330.             $editForm $this->createForm(SatisfactionSalaryType::class, $satisfactionSalary, ['selectedCountry' => $selectedCountry->getId()]);
  331.             $editForm->handleRequest($request);
  332.             if ($editForm->isSubmitted() && $editForm->isValid()) {
  333.                 $satisfactionSalary->setPersonDegree($personDegree);
  334.                 $satisfactionSalary->setCreatedDate($createdDate);
  335.                 if ($satisfactionSalary->getCreatedDate() == null) {
  336.                     if ($satisfactionSalary->getUpdatedDate()) {
  337.                         $satisfactionSalary->setCreatedDate($satisfactionSalary->getUpdatedDate());
  338.                     } else {
  339.                         $satisfactionSalary->setCreatedDate(new \DateTime());
  340.                     }
  341.                 }
  342.                 $satisfactionSalary->setUpdatedDate(new \DateTime());
  343.                 $this->em->flush();
  344.                 return $this->redirectToRoute('front_persondegree_satisfactionsalary_show', ['id' => $satisfactionSalary->getId()]);
  345.             }
  346.             return $this->render('satisfactionsalary/edit.html.twig', [
  347.                 'satisfactionSalary' => $satisfactionSalary,
  348.                 'edit_form' => $editForm->createView(),
  349.                 'selectedCountry' => $selectedCountry
  350.             ]);
  351.         });
  352.     }
  353.     #[Route(path'/satisfactionCreator/{id}/edit'name'front_persondegree_satisfactioncreator_edit'methods: ['GET''POST'])]
  354.     public function editSatisfactionCreatorAction(Request $requestSatisfactionCreator $satisfactionCreator): RedirectResponse|Response {
  355.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request$satisfactionCreator) {
  356.             $createdDate $satisfactionCreator->getCreatedDate();
  357.             $editForm $this->createForm(SatisfactionCreatorType::class, $satisfactionCreator);
  358.             $editForm->handleRequest($request);
  359.             if ($editForm->isSubmitted() && $editForm->isValid()) {
  360.                 $satisfactionCreator->setPersonDegree($this->personDegreeService->getPersonDegree());
  361.                 $satisfactionCreator->setCreatedDate($createdDate);
  362.                 if ($satisfactionCreator->getCreatedDate() == null) {
  363.                     if ($satisfactionCreator->getUpdatedDate()) {
  364.                         $satisfactionCreator->setCreatedDate($satisfactionCreator->getUpdatedDate());
  365.                     } else {
  366.                         $satisfactionCreator->setCreatedDate(new \DateTime());
  367.                     }
  368.                 }
  369.                 $satisfactionCreator->setUpdatedDate(new \DateTime());
  370.                 $this->em->flush();
  371.                 return $this->redirectToRoute('front_persondegree_satisfactioncreator_show', ['id' => $satisfactionCreator->getId()]);
  372.             }
  373.             return $this->render('satisfactioncreator/edit.html.twig', [
  374.                 'satisfactionCreator' => $satisfactionCreator,
  375.                 'edit_form' => $editForm->createView(),
  376.             ]);
  377.         });
  378.     }
  379.     #[Route(path'/satisfactionSearch/{id}/edit'name'front_persondegree_satisfaction_search_edit'methods: ['GET''POST'])]
  380.     public function editSatisfactionSearchAction(Request $requestSatisfactionSearch $satisfactionSearch): RedirectResponse|Response {
  381.         return $this->personDegreeService->checkUnCompletedAccountBefore(function () use ($request$satisfactionSearch) {
  382.             $createdDate $satisfactionSearch->getCreatedDate();
  383.             $editForm $this->createForm(SatisfactionSearchType::class, $satisfactionSearch);
  384.             $editForm->handleRequest($request);
  385.             if ($editForm->isSubmitted() && $editForm->isValid()) {
  386.                 $satisfactionSearch->setPersonDegree($this->personDegreeService->getPersonDegree());
  387.                 $satisfactionSearch->setCreatedDate($createdDate);
  388.                 if ($satisfactionSearch->getCreatedDate() == null) {
  389.                     if ($satisfactionSearch->getUpdatedDate()) {
  390.                         $satisfactionSearch->setCreatedDate($satisfactionSearch->getUpdatedDate());
  391.                     } else {
  392.                         $satisfactionSearch->setCreatedDate(new \DateTime());
  393.                     }
  394.                 }
  395.                 $satisfactionSearch->setUpdatedDate(new \DateTime());
  396.                 $this->em->flush();
  397.                 return $this->redirectToRoute('front_persondegree_satisfaction_search_show', ['id' => $satisfactionSearch->getId()]);
  398.             }
  399.             return $this->render('satisfactionSearch/edit.html.twig', [
  400.                 'satisfactionSearch' => $satisfactionSearch,
  401.                 'edit_form' => $editForm->createView(),
  402.             ]);
  403.         });
  404.     }
  405.     /**
  406.      * @param string $type
  407.      * @param string $message
  408.      */
  409.     private function notifSatisfaction($type Utils::FB_SUCCESS, ?string $message null) {
  410.         if (!$message) {
  411.             $message $this->translator->trans('flashbag.thank_you_for_responding_to_the_survey');
  412.         }
  413.         $this->addFlash($type$message);
  414.     }
  415.     /**
  416.      * @return string
  417.      * @throws \Exception
  418.      */
  419.     private function now(): string {
  420.         return (new \DateTime())->format(Utils::FORMAT_US);
  421.     }
  422.     /**
  423.      * Get endedUpdateDate
  424.      *
  425.      * @param \DateTime $date
  426.      * @return \DateTime|string|null
  427.      */
  428.     public function formatUS(\DateTime $date): \DateTime|string|null {
  429.         if ($date) {
  430.             return $date->format(Utils::FORMAT_US);
  431.         }
  432.         return null;
  433.     }
  434. }