src/Controller/ApplicationController.php line 541

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Entity\Operation;
  5. use App\Entity\ProductPurchase;
  6. use App\Entity\Purchase;
  7. use App\Entity\AlbumAudio;
  8. use App\Entity\Contact;
  9. use App\Form\ContactFormType;
  10. use App\Form\UserFormType;
  11. use App\Form\PurchaseFormType;
  12. use App\Form\PurchaseStatusType;
  13. use App\Service\EmailService;
  14. use App\Repository\UserRepository;
  15. use App\Repository\PurchaseRepository;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Uid\Uuid;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  22. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  24. class ApplicationController extends AbstractController
  25. {
  26.   /**
  27.    * @Route("/createuser", name="createuser2")
  28.    */
  29.   public function update(UserPasswordHasherInterface $passwordHasher)
  30.   {
  31.     $email 'contact@operationslunii.fr';
  32.     $plaintextPassword 'dcom@fnR';
  33.     $user = new User();
  34.     $hashedPassword $passwordHasher->hashPassword(
  35.       $user,
  36.       $plaintextPasswordset
  37.     );
  38.     $user->setPassword($hashedPassword);
  39.     $user->setEmail($email);
  40.     $user->setFirstName('Data');
  41.     $user->setCreatedAt(new \DateTime());
  42.     $user->setUpdatedAt(new \DateTime());
  43.     $user->setCivilite(1);
  44.     $user->setPostalCode(92130);
  45.     $user->setLastName('Gest');
  46.     $user->setRoles(array('ROLE_SUPER_ADMIN'));
  47.     $user->setPassword($hashedPassword);
  48.     $em $this->getDoctrine()->getManager();
  49.     $em->persist($user);
  50.     $em->flush();
  51.     return new Response('Successful');
  52.   }
  53.   /**
  54.    * @Route("/", name="home")
  55.    */
  56.   public function index(Request $requestEmailService $emailService)
  57.   {
  58.     $user = new User();
  59.     $form $this->createForm(UserFormType::class, $user);
  60.     $form->handleRequest($request);
  61.     if ($form->isSubmitted() && $form->isValid()) {
  62.       $user->setPassword(rand(10009999));
  63.       $participation = new Purchase();
  64.       $purchaseCode =  "LUN-" rand(100000999999);
  65.       $uuid Uuid::v4();
  66.       $participation->setPurchaseCode($purchaseCode);
  67.       $participation->setUuid($uuid);
  68.       $participation->setAuthor($user);
  69.       $user->addPurchase($participation);
  70.       $em $this->getDoctrine()->getManager();
  71.       $em->persist($user);
  72.       $em->flush();
  73.       $email $user->getEmail();
  74.       $subject 'Bienvenue sur la plateforme Lunii';
  75.       $send $emailService->send(
  76.         $email,
  77.         $subject,
  78.         $this->renderView(
  79.           //'emails/email-company-creation.html.twig',
  80.           'emails/user-create-confirm.html.twig',
  81.           [
  82.             'uuid' => $uuid,
  83.           ]
  84.         )
  85.       );
  86.       $this->addFlash('success'true);
  87.       return $this->redirectToRoute('successful_contact', ['uuid' => $uuid]);
  88.     }
  89.     $operation $this->getDoctrine()
  90.       ->getRepository(Operation::class)
  91.       ->find(1);
  92.     return $this->render('public/home.html.twig', [
  93.       'form' => $form->createView(),
  94.       'user' => $user,
  95.       'operation' => $operation
  96.     ]);
  97.   }
  98.   /**
  99.    * @Route("/operation/{oid}/participant/creer", name="purchase_user_create")
  100.    * 
  101.    */
  102.   public function purchaseUserCreate(Request $requeststring $oidUserRepository $userRepository)
  103.   {
  104.     $operations $this->getDoctrine()
  105.       ->getRepository(Operation::class)
  106.       ->findBy(array('isActive' => 1));
  107.     $user = new User();
  108.     $form $this->createForm(UserFormType::class, $user);
  109.     $form->remove('password');
  110.     $form->remove('userRole');
  111.     $form->remove('birthDate');
  112.     $form->remove('iban');
  113.     $operation $this->getDoctrine()
  114.       ->getRepository(Operation::class)->find($oid);
  115.     $form->handleRequest($request);
  116.     if ($form->isSubmitted() && $form->isValid()) {
  117.       $existingUsers $this->getDoctrine()
  118.         ->getRepository(User::class)
  119.         ->findBy(['email' =>
  120.         $form['email']->getData()]);
  121.       $existingPurchase null;
  122.       foreach ($existingUsers as $existingUser) {
  123.         if ($existingUser) {
  124.           $isBlockedUser $existingUser->getIsBlocked();
  125.           if ($isBlockedUser == 1) {
  126.             $this->addFlash('danger''Vous ne pouvez plus participer aux offres promotionnelles de promobricodeco.com. Pour plus d\'informations, n\'hésitez pas à nous contacter à l\'adresse contact@promobricodeco.com.');
  127.             return $this->render('purchase/purchase_user_create.html.twig', [
  128.               'form' => $form->createView(),
  129.               'operation' => $operation
  130.             ]);
  131.           }
  132.           $existingPurchase $this->getDoctrine()
  133.             ->getRepository(Purchase::class)
  134.             ->findOneBy(['author' => $existingUser'operation' => $oid]);
  135.         }
  136.         if ($existingPurchase !== NULL) {
  137.           $this->addFlash('danger''Désolé. Cette adresse e-mail est déjà utilisée. Veuillez en indiquer une autre.');
  138.           return $this->render('purchase/purchase_user_create.html.twig', [
  139.             'form' => $form->createView(),
  140.             'operation' => $operation
  141.           ]);
  142.         }
  143.       }
  144.       // $user->setPassword(md5(rand(1000, 9999)));
  145.       // $purchase = new Purchase();
  146.       // if ($this->getUser()) {
  147.       //     //$user = $this->getUser();
  148.       //     $purchase->setCreatedBy($this->getUser());
  149.       // }
  150.       // $purchase->setAuthor($user);
  151.       // // Generate a unique operation code to identify the purchase submission
  152.       // $purchaseCode = $operation->getCode() . "-" . rand(100000, 999999);
  153.       // while ($this->getDoctrine()
  154.       //     ->getRepository('App:Purchase')
  155.       //     ->findBy(['purchaseCode' => $purchaseCode])
  156.       // ) {
  157.       //     $purchaseCode = $operation->getCode() . "-" . rand(100000, 999999);
  158.       // }
  159.       // if ($this->getUser()) {
  160.       //     $purchase->setCreatedBy($this->getUser());
  161.       //     // POSSIBILITY TO REGISTER FOR ADMIN WITH NO EMAIL
  162.       //     if ($user->getEmail() === NULL) {
  163.       //         $code = explode('-', $purchaseCode);
  164.       //         $customEmail = $code[count($code) - 1] . '@promobricodeco.com';
  165.       //         $user->setEmail($customEmail);
  166.       //     }
  167.       // }
  168.       // $purchase->setPurchaseCode($purchaseCode);
  169.       // $purchase->setUuid(Uuid::v4());
  170.       // $user->addPurchase($purchase);
  171.       // $operation = $this->getDoctrine()
  172.       //     ->getRepository(Operation::class)
  173.       //     ->findOneBy(['id' =>
  174.       //     $oid]);
  175.       // $purchase->setOperation($operation);
  176.       // if ($user->getIsCgu())
  177.       //     $user->setIsCguDate(new \DateTime());
  178.       // $em = $this->getDoctrine()->getManager();
  179.       // $em->persist($user);
  180.       // $em->flush();
  181.       // //Connected user - admin
  182.       // if ($this->getUser()) {
  183.       //     return $this->redirectToRoute('purchase_receipt_create', [
  184.       //         'uuid' => $purchase->getUuid(),
  185.       //     ]);
  186.       // }
  187.       // /* return $this->redirectToRoute('purchase_user_create_confirm', [
  188.       //     'uuid' => $purchase->getUuid(),
  189.       // ]);*/
  190.       // return $this->redirectToRoute('operations_check_doublons', [
  191.       //     'uuid' => $purchase->getUuid(),
  192.       //     'redirect' => 'purchase_user_create_confirm'
  193.       // ]);
  194.     }
  195.     // $today = strftime(date('Y-m-d'));
  196.     // $currentUser = $this->getUser();
  197.     // if ($currentUser != null) {
  198.     //     $role = $currentUser->getRoles();
  199.     // } else {
  200.     //     $role = NULL;
  201.     // }
  202.     // if ($role == NULL and $operation->getOpenUntil()->format('Y-m-d') < $today) {
  203.     //     return $this->render('application/operation-finished.html.twig', [
  204.     //         'form' => $form->createView(),
  205.     //         'operation' => $operation,
  206.     //         'operations' => $operations,
  207.     //         'privacyText' => $this->privacyText,
  208.     //     ]);
  209.     // } else {
  210.     //     return $this->render('purchase/purchase_user_create.html.twig', [
  211.     //         'form' => $form->createView(),
  212.     //         'operation' => $operation
  213.     //     ]);
  214.     // }
  215.   }
  216.   /**
  217.    * @Route("/connexion", name="connexion")
  218.    */
  219.   public function login(Request $requestAuthenticationUtils $authUtils)
  220.   {
  221.     $error $authUtils->getLastAuthenticationError();
  222.     $lastUsername $authUtils->getLastUsername();
  223.     return $this->render('security/login.html.twig', array(
  224.       'last_username' => $lastUsername,
  225.       'error' => $error,
  226.     ));
  227.   }
  228.   /**
  229.    * @Route("/recapitulatif", name="recapitulatifs")
  230.    */
  231.   public function recapitulatifs(UserRepository $userRepositoryPurchaseRepository $participationRepository)
  232.   {
  233.     $session $this->get('session');
  234.     $idUser $session->get('id');
  235.     $p null;
  236.     // $p = $participationRepository->getUserPurchase($idUser);
  237.     $participation $participationRepository->findAll();
  238.     //$recapitulatifs = $this->getDoctrine()->getRepository(Users::class)->findALl();
  239.     $recapitulatifs null;
  240.     return $this->render('public/recapitulatif.html.twig', [
  241.       'recapitulatifs' => $recapitulatifs,
  242.       'p' => $p,
  243.     ]);
  244.   }
  245.   /**
  246.    * @Route("/enregistre", name="enregistres")
  247.    */
  248.   public function enregistres()
  249.   {
  250.     return $this->render('public/enregistre.html.twig');
  251.   }
  252.   /**
  253.    * @Route("/operation/{oid}/suivi", name="purchase_status")
  254.    * @ParamConverter("operation", options={"mapping"={"oid"="id"}})  
  255.    */
  256.   public function purchaseStatus(Operation $operationRequest $requestPurchaseRepository $purchaseRepository)
  257.   {
  258.     $purchase = [];
  259.     $form $this->createForm(PurchaseStatusType::class);
  260.     $form->handleRequest($request);
  261.     if ($form->isSubmitted() && $form->isValid()) {
  262.       $purchase $purchaseRepository->findOneBy(array('operation' => $operation'purchaseCode' => $form->get('purchaseCode')->getData()));
  263.       /* $purchase = $this->getDoctrine()
  264.                 ->getRepository('App:Purchase')
  265.                 ->findOneBy(['purchaseCode' => $form->get('purchaseCode')->getData()]);*/
  266.       /*if ($purchase) {
  267.                 $status = $purchase->getStatus();
  268.                 switch ($status) {
  269.                         /*case 0:
  270.                         $this->addFlash(
  271.                             'notice',
  272.                             'Nous n\'enregistrons aucun dossier de participation associé à ce numéro.'
  273.                         );
  274.                         break;*/
  275.       /* case $status === self::PURCHASE_SUBMIT_OK: //EN ATTENTE DE VALIDATION
  276.                         $this->addFlash(
  277.                             'info',
  278.                             'Votre dossier de participation a été soumis le ' . $purchase->getCreatedAt()->format('d/m/Y') . '. Votre dossier est en cours de traitement.'
  279.                         );
  280.                         break;
  281.                     case $status === self::PURCHASE_ACCEPTED: //VALIDE
  282.                         $this->addFlash(
  283.                             'success',
  284.                             'Votre dossier de participation a été soumis le ' . $purchase->getCreatedAt()->format('d/m/Y') . '. 
  285.                             Votre dossier a été validé le ' . $purchase->getActionAt()->format('d/m/Y') . '. Vous recevrez votre remboursement sous 8 à 10 semaines.'
  286.                         );
  287.                         break;
  288.                     case $status === self::PURCHASE_DECLINED: //INVALIDE
  289.                         $this->addFlash(
  290.                             'warning',
  291.                             'Votre dossier de participation a été soumis le ' . $purchase->getCreatedAt()->format('d/m/Y') . '. 
  292.                             Malheureusement votre dossier n\'est pas conforme. Pour toute question veuillez nous envoyer un e-mail à contact@promobricodeco.com'
  293.                         );
  294.                         break;
  295.                 }
  296.             } else {
  297.                 $this->addFlash(
  298.                     'notice',
  299.                     'Nous n\'enregistrons aucun dossier de participation associé à ce numéro.'
  300.                 );
  301.             }
  302.         }*/
  303.     }
  304.     return $this->render('public/suivreMonDossier.html.twig', [
  305.       'form' => $form->createView(),
  306.       'purchase' => $purchase,
  307.       'operation' => $operation
  308.     ]);
  309.   }
  310.   /**
  311.    * @Route("/participation-enregistree", name="participation_rules")
  312.    */
  313.   public function operationExplication()
  314.   {
  315.     return $this->render('public/participation-enregistree.html.twig');
  316.   }
  317.   /**
  318.    * @Route("/participation/{uuid}/preuve/creer", name="purchase_receipt_create")
  319.    * @ParamConverter("purchase", options={"mapping"={"uuid"="uuid"}})  
  320.    */
  321.   public function participation(Purchase $participationRequest $requestPurchaseRepository $participationRepositoryUserRepository $userRepositoryEmailService $emailService)
  322.   {
  323.     $user $participation->getAuthor();
  324.     if (count($participation->getProductPurchases()) == 0) {
  325.       $productPurchase = new ProductPurchase();
  326.       $participation->addProductPurchase($productPurchase);
  327.     }
  328.     $formPurchase $this->createForm(PurchaseFormType::class, $participation);
  329.     $formPurchase->handleRequest($request);
  330.     if ($formPurchase->isSubmitted() && $formPurchase->isValid()) {
  331.       if (($formPurchase->getData()->getPurchasedAt() > new \DateTime('2022-06-30')) || ($formPurchase->getData()->getPurchasedAt() < new \DateTime('2022-05-02'))) {
  332.         $this->addFlash(
  333.           'danger',
  334.           "Pour participer à l'opération votre achat doit être effectué entre le 02/05/2022 et le 30/06/2022"
  335.         );
  336.         return $this->redirectToRoute('purchase_receipt_create', [
  337.           'uuid' => $participation->getUuid(),
  338.         ]);
  339.       }
  340.       $participation->setAuthor($user);
  341.       $operation $this->getDoctrine()
  342.         ->getRepository(Operation::class)
  343.         ->find(1);
  344.       $participation->setOperation($operation);
  345.       $participation->setCreatedAt(new \DateTime());
  346.       $em $this->getDoctrine()->getManager();
  347.       $em->persist($participation);
  348.       $em->flush();
  349.       $email $user->getEmail();
  350.       $subject 'Merci pour votre particicipation';
  351.       $send $emailService->send(
  352.         $email,
  353.         $subject,
  354.         $this->renderView(
  355.           'emails/receipt-confirm.html.twig',
  356.           [
  357.             'reference' => $participation->getPurchaseCode(),
  358.             'operation' => $operation
  359.           ]
  360.         )
  361.       );
  362.       $this->addFlash('success'true);
  363.       return $this->redirectToRoute('successful_participation', [
  364.         'uuid' => $participation->getUuid()
  365.       ]);
  366.     }
  367.     $operation $this->getDoctrine()
  368.       ->getRepository(Operation::class)
  369.       ->find(1);
  370.     return $this->render('public/je-participe.html.twig', [
  371.       'formPurchase' => $formPurchase->createView(),
  372.       'operation' => $operation
  373.     ]);
  374.   }
  375.   /**
  376.    * @Route("/reglement", name="rules")
  377.    */
  378.   public function rules()
  379.   {
  380.     return $this->render('public/reglement.html.twig');
  381.   }
  382.   /**
  383.    * @Route("/mentions-legales", name="terms_of_use")
  384.    */
  385.   public function termsOfUse()
  386.   {
  387.     return $this->render('public/mentions-legales.html.twig');
  388.   }
  389.   /**
  390.    * @Route("/cookies-et-confidentialite", name="cookies")
  391.    */
  392.   public function cookiesEtConfidentialite()
  393.   {
  394.     return $this->render('public/cookies-et-confidentialite.html.twig');
  395.   }
  396.   /**
  397.    * @Route("/contact", name="contact")
  398.    */
  399.   public function contact(Request $requestUserRepository $userRepositoryEmailService $emailService)
  400.   {
  401.     $user = new User();
  402.     $form $this->createForm(UserFormType::class);
  403.     $user = new Contact();
  404.     $form $this->createForm(ContactFormType::class);
  405.     $form->remove('gender');
  406.     $form->remove('purchases');
  407.     $form->remove('address');
  408.     $form->remove('address2');
  409.     $form->remove('postalCode');
  410.     $form->remove('city');
  411.     $form->remove('isCgu');
  412.     $form->remove('isPartnerCgu');
  413.     $form->remove('isNewsletter');
  414.     $form->handleRequest($request);
  415.     if ($form->isSubmitted() && $form->isValid()) {
  416.       $user $form->getData();
  417.       // $object = $form->get('contacts')->get('__name__')->get('subject')->getData();
  418.       // $message = $form->get('contacts')->get('__name__')->get('message')->getData();
  419.       $entityManager $this->getDoctrine()->getManager();
  420.       $entityManager->persist($user);
  421.       $entityManager->flush();
  422.       $emailTo 'test@data-gest.fr';
  423.       $subject "Nouvelle question sur Mes Instants Gagnants Pierre Lannier";
  424.       $send $emailService->send(
  425.         $emailTo,
  426.         $subject,
  427.         $this->renderView(
  428.           'emails/new-contact.html.twig',
  429.           [
  430.             'subject' => $form->get('subject')->getData(),
  431.             'lastName' => $form->get('lastName')->getData(),
  432.             'firstName' => $form->get('firstName')->getData(),
  433.             'email' => $form->get('email')->getData(),
  434.             'phoneNumber' => $form->get('phoneNumber')->getData(),
  435.             'message' => $form->get('message')->getData(),
  436.           ]
  437.         )
  438.       );
  439.       return $this->redirectToRoute('successful_msg');
  440.     }
  441.     return $this->render('public/contact.html.twig', ['form' => $form->createView()]);
  442.   }
  443.   /**
  444.    * @Route("/modalites_lastminute", name="modality_last_minute")
  445.    */
  446.   public function modalityLastMinute()
  447.   {
  448.     return $this->render('public/modalities-lastminute.html.twig');
  449.   }
  450.   /**
  451.    * @Route("/participation/{uuid}/preuve/confirmer", name="successful_participation")
  452.    * @ParamConverter("purchase", options={"mapping"={"uuid"="uuid"}}) 
  453.    */
  454.   public function successfulPurchase(Request $requestPurchase $participation)
  455.   {
  456.     $flashbag $this->get('session')->getFlashBag();
  457.     $success $flashbag->get("success");
  458.     
  459.     if(!$success) {
  460.       return $this->redirectToRoute('home');
  461.     }
  462.     $operation $this->getDoctrine()
  463.       ->getRepository(Operation::class)
  464.       ->find(1);
  465.     $reference $participation->getPurchaseCode();
  466.     return $this->render(
  467.       'public/participation_confirmation.html.twig',
  468.       [
  469.         'reference' => $reference,
  470.         'operation' => $operation
  471.       ]
  472.     );
  473.   }
  474.   /**
  475.    * @Route("/participation/{uuid}/participant/confirmer", methods="GET", name="successful_contact")
  476.    */
  477.   public function successful(Request $request)
  478.   {
  479.     $flashbag $this->get('session')->getFlashBag();
  480.     $success $flashbag->get("success");
  481.     
  482.     if(!$success) {
  483.       return $this->redirectToRoute('home');
  484.     }
  485.     $operation $this->getDoctrine()
  486.       ->getRepository(Operation::class)
  487.       ->find(1);
  488.     return $this->render('public/participation-enregistree.html.twig', [
  489.       'operation' => $operation
  490.     ]);
  491.   }
  492.   /**
  493.    * @Route("/contact-success", name="successful_msg")
  494.    */
  495.   public function successfulContact()
  496.   {
  497.     return $this->render('public/contact-enregistree.html.twig');
  498.   }
  499. }