src/Controller/CompteController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Form\compteType;
  8. use App\Form\coordonneeType;
  9. use App\Form\optinType;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use App\Form\ChangePasswordType;
  12. use Symfony\Component\Serializer\Encoder\JsonDecode;
  13. use Symfony\Component\Serializer\Serializer;
  14. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. use App\Entity\commande;
  17. use App\Entity\Language;
  18. use App\Entity\Residence;
  19. use App\Entity\Typologie;
  20. use App\Entity\InfosResidence;
  21. use App\Services\iresaService;
  22. use App\Utils\Residences;
  23. /**
  24.  * @Route("/{_locale}/mon-compte", requirements={"_locale": "en|fr"})
  25.  */
  26. class CompteController extends AbstractController
  27. {   
  28.     /**
  29.      * @var EntityManager
  30.      */
  31.     private $em;
  32.     private $iresaService;
  33.     private $translator;
  34.     private $residenceService;
  35.     private $passwordEncoder;
  36.     public function __construct(EntityManagerInterface $emiresaService $iresaServiceTranslatorInterface $translatorResidences $residenceServiceUserPasswordEncoderInterface $passwordEncoder)
  37.     {
  38.         $this->em $em;
  39.         $this->iresaService $iresaService;
  40.         $this->translator $translator;
  41.         $this->residenceService $residenceService;
  42.         $this->passwordEncoder $passwordEncoder;
  43.     }
  44.     /**
  45.      * @Route("/", name="mon_compte")
  46.      */
  47.     public function indexAction(Request $request)
  48.     { 
  49.         $this->denyAccessUnlessGranted('ROLE_CUSTOMER');
  50.         return $this->render('/front/Compte/accueil.html.twig');
  51.     }
  52.     /**
  53.      * @Route("/mes-infos", name="mon_compte_infos")
  54.      */
  55.     public function accountDetailsAction(Request $request)
  56.     { 
  57.         $this->denyAccessUnlessGranted('ROLE_CUSTOMER');
  58.         $user $this->getUser();
  59.         $form $this->createForm(coordonneeType::class, $user);
  60.         $form->handleRequest($request);
  61.         if ($form->isSubmitted() && $form->isValid()) { 
  62.             $this->iresaService->iresaXFT("Create""Customer"$user);
  63.             $this->em->persist($user);
  64.             $this->em->flush();
  65.         }
  66.         return $this->render('/front/Compte/infos.html.twig',[
  67.             'form' => $form->createView(),
  68.         ]);
  69.     }
  70.     
  71.     /**
  72.      * @Route("/reservations", name="mon_compte_reservations_liste")
  73.      */
  74.     public function reservationAction(Request $request)
  75.     { 
  76.         $locale $request->getLocale();
  77.         $lang  $this->em->getRepository(Language::class)->findOneByCode($locale);
  78.         $this->denyAccessUnlessGranted('ROLE_CUSTOMER');
  79.         $commandes $this->em->getRepository(commande::class)->getCurrentStays($this->getUser());
  80.         $currentStays $this->parseOrder($commandes$lang);
  81.         $commandes $this->em->getRepository(commande::class)->findBy(['compte' => $this->getUser(), 'etat' => [146]], ['datecrea'=> 'DESC']);
  82.         $archives $this->parseOrder($commandes$lang);
  83.         
  84.         return $this->render('/front/Compte/sejours.html.twig', [
  85.             'currentStays' => $currentStays,
  86.             'archives' => $archives
  87.         ]);
  88.     }
  89.     /**
  90.      * @Route("/reservations/{id_sejour}", name="mon_compte_reservation_detail")
  91.      */
  92.     public function sejourAction(Request $request$id_sejour)
  93.     {
  94.         $locale $request->getLocale();
  95.         $lang  $this->em->getRepository(Language::class)->findOneByCode($locale);
  96.         $this->residenceService->setLocale($locale);
  97.         $idiresa str_replace("-","/"$id_sejour);
  98.         $vars["idiresa"] = $idiresa;
  99.         $vars["iresaService"] = $this->iresaService;
  100.         
  101.         
  102.         $obj = new \stdClass;
  103.         $obj->idAvailability $idiresa;
  104.         $obj->debug = ['User-agent' => $request->headers->get('User-Agent'), "script" => "CompteController:sejourAction:340"];
  105.         $iresa $this->iresaService->iresaXFT("Get""Booking"$obj);
  106.         
  107.         if(isset($iresa->Booking)) {
  108.             $vars["booking"]  = $iresa->Booking;
  109.         }
  110.        
  111.         $fiche = [];
  112.         $commande $this->em->getRepository(commande::class)->findOneByDossiersIresa($idiresa);
  113.         $vars["commande"] = $commande;
  114.         if($commande) {
  115.             $fiche $this->residenceService->getFicheHebergement($commande->getDetail());
  116.         }
  117.         
  118.         $vars array_merge($vars$fiche);
  119.        
  120.         return $this->render('/front/Compte/sejour.html.twig'$vars);
  121.     }
  122.     /**
  123.      * @Route("/reintitialiser-mot-de-passe", name="mon_compte_changer_motdepasse")
  124.      */
  125.     public function changePasswordAction(Request $request)
  126.     { 
  127.         $session $request->getSession();
  128.         $this->denyAccessUnlessGranted('ROLE_CUSTOMER');
  129.         $user $this->getUser();
  130.         $form $this->createForm(ChangePasswordType::class);
  131.         $form->handleRequest($request);
  132.         if ($form->isSubmitted() && $form->isValid()) {
  133.             $oldPassword $form->getData()['oldPassword'];
  134.             if( password_verify($oldPassword$user->getPassword()) == false ) {
  135.                 $title="";
  136.                
  137.                 $message $this->translator->trans("compte.connexion.reset_password.wrong_old_password" , [], 'app');
  138.                 $session->getFlashBag()->add('warning', ['type' => 'warning''title' => $title'message' => $message]);
  139.                 return $this->redirectToRoute('mon_compte_changer_motdepasse');
  140.             }
  141.             $password $this->passwordEncoder->encodePassword($user$form->getData()['plainPassword']);
  142.             $user->setPassword($password);
  143.             $this->em->persist($user);
  144.             $this->em->flush();
  145.            
  146.             $title="";
  147.             $message $this->translator->trans("compte.connexion.reset_password.change_success" , [], 'app');
  148.             
  149.             $session->getFlashBag()->add('success', ['type' => 'success''title' => $title'message' => $message]);
  150.             return $this->redirectToRoute('mon_compte');
  151.         }
  152.         return $this->render('/security/change_password.html.twig',[
  153.             'form' => $form->createView(),
  154.         ]);
  155.     }
  156.     /**
  157.      * @Route("/newsletter", name="mon_compte_newsletter")
  158.      */
  159.     public function newsletterAction(Request $request)
  160.     { 
  161.         $session $request->getSession();
  162.         $this->denyAccessUnlessGranted('ROLE_CUSTOMER');
  163.         $user $this->getUser();
  164.         $form $this->createForm(optinType::class, $user);
  165.         $form->handleRequest($request);
  166.         if ($form->isSubmitted() && $form->isValid()) {
  167.             $optin $form->getData()->getOptin();
  168.             $user->setOptin($optin);
  169.             $this->em->persist($user);
  170.             $this->em->flush();
  171.             $message =  $optin == 'footer.social.newsletter.inscription_ok' :'footer.social.newsletter.desinscription';
  172.             $message =  $this->translator->trans($message , [], 'app');
  173.             
  174.             $title "";
  175.             $session->getFlashBag()->add('success', ['type' => 'success''title' => $title'message' => $message]);
  176.             return $this->redirectToRoute('mon_compte');
  177.         }
  178.         return $this->render('/front/Compte/newsletter.html.twig',[
  179.             'form' => $form->createView(),
  180.         ]);
  181.     }
  182.     public function logoutAction(Request $request)
  183.     {
  184.         $session $request->getSession();
  185.         $session->remove("compte");
  186.         return $this->redirect($this->generateUrl('ac_platform_homepage'));
  187.     }
  188.     
  189.     private function parseOrder($commandes$lang) {
  190.         $orders = [];
  191.         foreach ($commandes as $commande) {
  192.             $resas json_decode($commande->getDetail(), true);
  193.             $formule null;
  194.             $residence null;
  195.             $typologie null;
  196.             if($resas !== null) {
  197.                 $idPackage array_key_first($resas['reservation']);
  198.                 $resa $resas['reservation'][$idPackage];
  199.                 $residence =  $this->em->getRepository(Residence::class)->find($resas['residence']);
  200.                 $typologie  $this->em->getRepository(Typologie::class)->findOneBy([
  201.                     'lang' => $lang,
  202.                     'idiresa' => $resas['typologie']
  203.                 ]);
  204.                 
  205.                 if ($resas['formule']['className'] != "unknown") {
  206.                     $formule $this->em->getRepository("App\\Entity\\{$resas['formule']['className']}")->findOneBy([
  207.                         'lang' => $lang,
  208.                         'id' => $resas['formule']['idResidence'],
  209.                         'idIresa' => $resas['formule']['idIresa']
  210.                     ]);
  211.                 } 
  212.                 $orders[] = [
  213.                     "dossier_iresa" =>  $commande->getDossiersIresa(),
  214.                     "montant" =>  $commande->getMontant(),
  215.                     "resa" => $resa,
  216.                     "residence" => $residence,
  217.                     "typologie" => $typologie,
  218.                     "formule" => $formule
  219.                 ];
  220.             }
  221.             
  222.         }
  223.         return $orders;
  224.     }
  225. }