src/Controller/EntrepriseController.php line 1280

Open in your IDE?
  1. <?php
  2. // src/Controller/EntrepriseController.php
  3. namespace App\Controller;
  4. use App\Entity\SujetFAQ;
  5. use App\Entity\Article;
  6. use App\Entity\AppUser;
  7. use App\Entity\Product;
  8. use App\Entity\Review;
  9. use App\Entity\Category;
  10. use App\Entity\Commande;
  11. use App\Entity\Service;
  12. use App\Entity\Notification;
  13. use App\Entity\Conversation;
  14. use App\Entity\ProductOrder;
  15. use App\Entity\Entreprise;
  16. use App\Entity\ProductMisDeCote;
  17. use App\Entity\SubCategory;
  18. use App\Entity\AvisUtilisateur;
  19. use App\Form\SujetFAQType;
  20. use App\Form\AvisUtilisateurType;
  21. use App\Form\AvisUtilisateurEditType;
  22. use App\Form\ProductType;
  23. use App\Entity\ShippingMethod;
  24. use App\Entity\RoleBoutique;
  25. use App\Entity\Boutique;
  26. use App\Form\BoutiqueType;
  27. use App\Entity\Plan;
  28. use App\Entity\ValiditeService;
  29. use App\Entity\UserBoutique;
  30. use App\Entity\RequeteAjoutBoutique;
  31. use App\Entity\TVA;
  32. use App\Entity\ExtraSettings;
  33. use App\Entity\Devis;
  34. use App\Form\DevisType;
  35. use App\Form\DevisEditType;
  36. use Spipu\Html2Pdf\Html2Pdf;
  37. use App\Entity\CategorieEntreprise;
  38. use App\Entity\Produit;
  39. use App\Entity\OffreDevis;
  40. use App\Entity\Message;
  41. use App\Entity\EntrepriseEnregistre;
  42. use App\Entity\ReclamerPage;
  43. use App\Form\OffreDevisType;
  44. use App\Form\MessageType;
  45. use App\Form\CompteProfessionnelFormType;
  46. use App\Services\LikaMapService;
  47. use Symfony\Component\HttpFoundation\Response;
  48. use Symfony\Component\HttpFoundation\JsonResponse;
  49. use Symfony\Component\Routing\Annotation\Route;
  50. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  51. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  52. use Symfony\Component\HttpFoundation\Request;
  53. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security as Security;
  54. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  55. use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
  56. use App\Security\LoginFormAuthenticator;
  57. /**
  58.  * @Route("/{_locale}")
  59.  */
  60. class EntrepriseController extends AbstractController
  61. {    
  62.         private $session;
  63.     
  64.     public function __construct(SessionInterface $session)
  65.         {
  66.             $this->session = $session;
  67.         }
  68.     
  69.     
  70.     
  71.     /**
  72.      * @Route("/contact", name="contact")
  73.      */
  74.     public function contactAction()
  75.     {
  76.         
  77.           return $this->render('entreprise/contact.html.twig', [
  78.             
  79.         ]);
  80.     }
  81.     /**
  82.      * @Route("/a_propos", name="a_propos")
  83.      */
  84.     public function aProposAction()
  85.     {
  86.         
  87.           return $this->render('entreprise/a_propos.html.twig', [
  88.             
  89.         ]);
  90.     }
  91.     /**
  92.      * @Route("/terms-helpplace", name="terms_helpplace")
  93.      */
  94.     public function termsHelpplaceAction()
  95.     {
  96.         
  97.           return $this->render('entreprise/terms_helpplace.html.twig', [
  98.             
  99.         ]);
  100.     }
  101.     /**
  102.      * @Route("/nos-services", name="nos_services")
  103.      */
  104.     public function nosServicesAction()
  105.     {
  106.         $em = $this->getDoctrine()
  107.                     ->getManager();
  108.     $categoriesEntreprises = $em->getRepository(CategorieEntreprise::class)
  109.                             ->findBy(
  110.                                 array(
  111.                                     'estSupprime' => false,
  112.                                 ),
  113.                                 array('nom' => 'ASC')
  114.                             );
  115.     $slidesData = array();
  116.     foreach($categoriesEntreprises as $categoriesEntreprise){
  117.         
  118.         if($categoriesEntreprise->getImage() != null){
  119.             $s = array(
  120.             'img' => $categoriesEntreprise->getImage()->getUrl(),
  121.             'title' => $categoriesEntreprise->getNom(),
  122.             'description' => $categoriesEntreprise->getPhraseDAppel()
  123.             );
  124.         }else{
  125.             $s = array(
  126.             'img' => '',
  127.             'title' => $categoriesEntreprise->getNom(),
  128.             'description' => $categoriesEntreprise->getPhraseDAppel()
  129.             );
  130.         }
  131.         
  132.         array_push($slidesData, $s);
  133.     }
  134.           return $this->render('entreprise/nos_services.html.twig', [
  135.             'categoriesEntreprises' => $categoriesEntreprises,
  136.             'slidesData' => json_encode($slidesData)
  137.         ]);
  138.     }
  139.           /**
  140.      * @Route("/cc", name="cc")
  141.      */
  142.     public function ccAction()
  143.     {
  144.         
  145.           return $this->render('entreprise/cc.html.twig', [
  146.             
  147.         ]);
  148.         }
  149.         /**
  150.      * @Route("/search/{paginer}/{pageCourante}", name="search_service")
  151.      * @return \Symfony\Component\HttpFoundation\Response
  152.      */
  153.     public function searchServiceAction(Request $request, $nearest = false, $bestRated = false, $paginer='page', $pageCourante=1)
  154.     {
  155.         $em = $this->getDoctrine()
  156.                     ->getManager();
  157.         $elementParPage = 4;
  158.         $user = $this->getUser();
  159.         $q = $request->query->get('q');
  160.         $nearest = $request->query->get('nearest');
  161.         $bestRated = $request->query->get('bestRated');
  162.         
  163.         $likaMap = new LikaMapService;
  164.         
  165.         
  166.         $boutiques = $em->getRepository(Boutique::class)
  167.             ->searcheBoutique($q, $nearest, $bestRated, $elementParPage, $pageCourante);
  168.         $distances = array();
  169.         $entrepriseNom = array();
  170.         $userGPS = $likaMap->gps();
  171.         $lat_client = $userGPS['lat'];
  172.         $lng_client = $userGPS['long']; 
  173.         foreach($boutiques as $uneBoutique){
  174.             $distance = $likaMap->distance($userGPS['lat'], $userGPS['long'], $uneBoutique->getLatitude(), $uneBoutique->getLongitude(), 'N');
  175.             array_push($distances, floor($distance));
  176.             $ne = array(
  177.                 'lat' => $uneBoutique->getLatitude(),
  178.                 'lng' => $uneBoutique->getLongitude(),
  179.                  'nom_entreprise' => $uneBoutique->getNom(), 
  180.                  'email' => $uneBoutique->getEmail(), 
  181.                  'tel' => $uneBoutique->getPhone(), 
  182.                  'site_web' => $uneBoutique->getSiteWeb(), 
  183.                  'horaire_ouverture' => $uneBoutique->getHoraireDOuverture(),
  184.                  'description' => $uneBoutique->getDescription(), 
  185.                  'nombre_avis' => $uneBoutique->getNombreAvis(), 
  186.                  'moy_avis' => $uneBoutique->getMoyenneAvis(),
  187.                  'logo' => $uneBoutique->getLogo()->getUrl(),
  188.                  'service_entreprise' => $uneBoutique->getCategorieEntreprise()->getNom(), 
  189.                  'adresse3Words' => $uneBoutique->getAdresse3Words(), 
  190.                 'localite' => $uneBoutique->getVille(),
  191.                 'certif' => $uneBoutique->getEstCertifie()
  192.             );
  193.             array_push($entrepriseNom, $ne);
  194.         }
  195.         $entrepriseNom = json_encode($entrepriseNom);
  196.         $nombreDePage = ceil((count($boutiques))/$elementParPage) ;
  197.         if(($pageCourante > $nombreDePage && $nombreDePage >= 1) || $pageCourante <=0){
  198.             throw $this->createNotFoundException('Nombre invalide');
  199.         }
  200.          
  201.         return $this->render('entreprise/search_service.html.twig', [
  202.             'boutiques' =>$boutiques,
  203.             'q'=> $q,
  204.             'distances' => $distances,
  205.             'entrepriseNom' => $entrepriseNom,
  206.             'nombreDePage' => $nombreDePage,
  207.             'pageCourante' => $pageCourante,
  208.             'lat_client' => $lat_client,
  209.             'lng_client' => $lng_client,
  210.             'nearest' => $nearest,
  211.             'bestRated' => $bestRated,
  212.         ]);
  213.     }
  214.     
  215.     /**
  216.      * @Route("/search-temp-result", name="search_temp_result")
  217.      * @return \Symfony\Component\HttpFoundation\Response
  218.      */
  219.     public function searchTempResultAction(Request $request)
  220.     {
  221.         $em = $this->getDoctrine()
  222.                     ->getManager();
  223.         
  224.         $user = $this->getUser();
  225.         
  226.         
  227.         if($request->getMethod() == 'POST'){
  228.             $q  = $request->request->get('q');
  229.             $categorieEntreprises = $em->getRepository(CategorieEntreprise::class)
  230.                                         ->getSearchCategorie($q);
  231.         }
  232.      
  233.         
  234.          
  235.         return $this->render('entreprise/search_temp_result.html.twig', [
  236.             'categorieEntreprises' =>$categorieEntreprises
  237.             
  238.         ]);
  239.     }
  240.     
  241.     
  242.     /**
  243.      * @Route("/entreprise/", name="entreprise.entreprise")
  244.      * @return \Symfony\Component\HttpFoundation\Response
  245.      */
  246.     public function entrepriseAction(Request $request)
  247.     {
  248.         $em = $this->getDoctrine()
  249.                     ->getManager();
  250.     
  251.         $user = $this->getUser();
  252.         $categories = $em->getRepository(CategorieEntreprise::class)
  253.                         ->findBy(
  254.                                 array(
  255.                                     'estSupprime' => false,
  256.                                 ),
  257.                                 array('nom' => 'ASC')
  258.                             );
  259.         return $this->render('entreprise/entreprise.html.twig', [
  260.             'categories' => $categories
  261.         ]);
  262.     }
  263.     
  264.     /**
  265.      * @Route("/lika-business/", name="entreprise.lika_business")
  266.      * @return \Symfony\Component\HttpFoundation\Response
  267.      */
  268.     public function likaBusinessAction(Request $request)
  269.     {
  270.         $em = $this->getDoctrine()
  271.                     ->getManager();
  272.     
  273.         $user = $this->getUser();
  274.         $categories = $em->getRepository(CategorieEntreprise::class)
  275.                         ->findBy(
  276.                                 array(
  277.                                     'estSupprime' => false,
  278.                                 ),
  279.                                 array('nom' => 'ASC')
  280.                             );
  281.         return $this->render('entreprise/lika_business_new.html.twig', [
  282.             'categories' => $categories
  283.         ]);
  284.     }
  285.     
  286.     /**
  287.      * @Route("/entreprise-par-secteur/{slug}", name="entreprise_par_secteur")
  288.      * @return \Symfony\Component\HttpFoundation\Response
  289.      */
  290.     public function entrepriseParSecteurAction(Request $request, CategorieEntreprise $categorieEntreprise)
  291.     {
  292.         $em = $this->getDoctrine()
  293.                     ->getManager();
  294.     
  295.         $user = $this->getUser();
  296.         
  297.         $boutiques = $em->getRepository(Boutique::class)
  298.                         ->entrepriseByCategorieEntreprise($categorieEntreprise);
  299.         return $this->render('entreprise/entreprise_par_secteur.html.twig', [
  300.             'boutiques' => $boutiques
  301.         ]);
  302.     }
  303.     
  304.     /**
  305.      * @Route("/devis", name="devis")
  306.      * @return \Symfony\Component\HttpFoundation\Response
  307.      */
  308.     public function devisAction(Request $request)
  309.     {
  310.         $em = $this->getDoctrine()
  311.                     ->getManager();
  312.     
  313.         $user = $this->getUser();
  314.         $devis = $em->getRepository(Devis::class)
  315.                     ->findBy([], ['laDate' => 'DESC']);
  316.     
  317.         return $this->render('entreprise/devis.html.twig', [
  318.             'devis' => $devis
  319.         ]);
  320.     }
  321.     
  322.     /**
  323.      * @Route("/nouveau-devis/{fromABoutique}/{boutique}", name="nouveau_devis")
  324.      * @return \Symfony\Component\HttpFoundation\Response
  325.      */
  326.     public function nouveauDevisAction(Request $request, $fromABoutique , $boutique)
  327.     {
  328.         $em = $this->getDoctrine()
  329.                     ->getManager();
  330.     
  331.         $user = $this->getUser();
  332.         $devis = new Devis;
  333.         $boutique = $em->getRepository(Boutique::class)
  334.                                         ->findOneById($boutique);
  335.         if($boutique != null){
  336.             $devis->setCategorieEntreprise($boutique->getCategorieEntreprise());
  337.         }                    
  338.         
  339.         $form = $this->createForm(DevisType::class, $devis);
  340.         if($request->getMethod() == 'POST'){
  341.             if(null == $user){
  342.                 return $this->redirectToRoute('security_login');
  343.             }
  344.                $form->handleRequest($request);
  345.                
  346.                     $devis->setUser($user);
  347.                     
  348.                     $categorieEntreprise = (int)$request->request->get('categorieEntreprise');
  349.                     //$devis->setTitre($categorieEntreprise);
  350.                     $em->persist($devis);
  351.                     $em->flush();
  352.                     $boutiqueFourmulaire = (int)$request->request->get('boutique');
  353.                     if($fromABoutique){
  354.                         
  355.                         if($boutique == null){
  356.                             $boutique = $em->getRepository(Boutique::class)
  357.                                         ->findOneById($boutiqueFourmulaire);
  358.                         }
  359.                         
  360.                         $devis->setEstOuvert(false);
  361.                         $devis->setNombreDOffre(1);
  362.                         
  363.                         $offreDevis = new OffreDevis;
  364.                         $offreDevis->setRemporte(true);
  365.                         $offreDevis->setBoutique($boutique);
  366.                         $offreDevis->setDevis($devis);
  367.                         // Une demande directe possède un montant payable uniquement
  368.                         // lorsque son budget est fixe.
  369.                         $budgetMinDirect = is_numeric($devis->getBudgetMin())
  370.                             ? (float) $devis->getBudgetMin() : 0.0;
  371.                         $budgetMaxDirect = is_numeric($devis->getBudgetMax())
  372.                             ? (float) $devis->getBudgetMax() : 0.0;
  373.                         if ($budgetMinDirect > 0 && $budgetMinDirect === $budgetMaxDirect) {
  374.                             $offreDevis->setValeurFinanciere($budgetMinDirect);
  375.                         }
  376.                         $proprietaireBoutique = $em->getRepository(UserBoutique::class)
  377.                             ->findOneBy(['boutique' => $boutique]);
  378.                         if ($proprietaireBoutique) {
  379.                             $offreDevis->setUser($proprietaireBoutique->getUser());
  380.                         }
  381.                         $em->persist($offreDevis);
  382.                         
  383.                         $userBoutiques = $em->getRepository(UserBoutique::class)
  384.                                         ->findBy(
  385.                                             array(
  386.                                             'boutique' => $boutique
  387.                                             )
  388.                                         );
  389.                     foreach($userBoutiques as $userBoutique){
  390.                         $notification = new Notification;
  391.                         $notification->setUser($userBoutique->getUser());
  392.                         $lien =  $this->generateUrl('gestion.proposals', array('slug' => $userBoutique->getBoutique()->getSlug()));
  393.                         $notification->setExtraData($devis->getId());
  394.                         $notification->setLien($lien);
  395.                         $notification->setTypeNotification('devis');
  396.                         $notification->setDescription('Quelqu\'un vous a envoyé un devis sur ' . $userBoutique->getBoutique()->getNom());
  397.         
  398.                         $em->persist($notification);
  399.                     }
  400.                         
  401.                     
  402.                     } else{
  403.                         $devisFromData = $form->getData();
  404.                         $entrepriseDuneCategories = $em->getRepository(Boutique::class)
  405.                                                         ->findByCategorieEntreprise($devisFromData->getCategorieEntreprise());
  406.                         $devis->setEstOuvert(true);
  407.                         foreach($entrepriseDuneCategories as $entreCat){
  408.                             
  409.                             
  410.                             $userBoutiques = $em->getRepository(UserBoutique::class)
  411.                                         ->findBy(
  412.                                             array(
  413.                                             'boutique' => $entreCat
  414.                                             )
  415.                                         );
  416.                                 foreach($userBoutiques as $userBoutique){
  417.                                     $notification = new Notification;
  418.                                     $notification->setUser($userBoutique->getUser());
  419.                                     $lien =  $this->generateUrl('gestion.proposals', array('slug' => $userBoutique->getBoutique()->getSlug()));
  420.                                     $notification->setExtraData($devis->getId());
  421.                                     $notification->setLien($lien);
  422.                                     $notification->setTypeNotification('devis');
  423.                                     $notification->setDescription('Nouveau devis pour ' . $userBoutique->getBoutique()->getNom());
  424.                     
  425.                                     $em->persist($notification);
  426.                                 }
  427.                             
  428.                         }
  429.                     }
  430.                     
  431.                     $em->flush();
  432.                     
  433.                     return $this->redirectToRoute('afficher_devis', array('slug' => $devis->getSlug()));
  434.                 
  435.         }
  436.         return $this->render('entreprise/nouveau_devis.html.twig', [
  437.             'devis' => $devis,
  438.             'form' => $form->createView(),
  439.             'fromABoutique' => $fromABoutique
  440.         ]);
  441.     }
  442.     
  443.     /**
  444.      * @Route("/creer-compte-professionnel", name="entreprise_creer_compte_professionel")
  445.      * @return \Symfony\Component\HttpFoundation\Response
  446.      */
  447.     public function creerCompteProfessionnelAction(Request $request, UserPasswordHasherInterface $passwordHasher, UserAuthenticatorInterface $userAuthenticator, LoginFormAuthenticator $authenticator)
  448.     {
  449.         if(null != $this->getUser()){
  450.             return $this->redirectToRoute('security_login');
  451.         }
  452.         $em = $this->getDoctrine()
  453.                     ->getManager();
  454.     
  455.         $categorieEntreprises = $em->getRepository(CategorieEntreprise::class)
  456.                                 ->findBy(
  457.                                 array(
  458.                                     'estSupprime' => false,
  459.                                 ),
  460.                                 array('nom' => 'ASC')
  461.                             );
  462.             
  463.         $user = new AppUser;
  464.         $user->setTypeCompte('Professionnel');
  465.         $user->setEnabled(true);
  466.         $error = '';
  467.         
  468.         $form = $this->createForm(CompteProfessionnelFormType::class, $user);
  469.         if($request->getMethod() == 'POST'){
  470.             $form->handleRequest($request);
  471.             
  472.             $password1 = $_POST['compte_professionnel_form']['plainPassword']['first'];
  473.             $password2 = $_POST['compte_professionnel_form']['plainPassword']['second'];
  474.             $email = $_POST['compte_professionnel_form']['email'];
  475.             $username = '';
  476.             
  477.             if($password1 != $password2){
  478.                 $error = 'entreprise.password_not_corresponding';
  479.             } else{
  480.                 $emailUser = $em->getRepository(AppUser::class)
  481.                                 ->findOneByEmail($email);
  482.                 if($emailUser != null){
  483.                     $error = 'entreprise.email_already_used';
  484.                 } else{
  485.                     
  486.                     if($form->isValid()){
  487.                         $hashedPassword = $passwordHasher->hashPassword($user, $password1);
  488.                         $user->setPassword($hashedPassword);
  489.                                 
  490.                         $em->persist($user);
  491.                         $em->flush();
  492.                                 
  493.                         return $userAuthenticator->authenticateUser(
  494.                                 $user,
  495.                                         $authenticator, // Pass your specific authenticator instance
  496.                                         $request
  497.                                     );
  498.                                 return $this->redirectToRoute('registration_confirmed', array('username' => $user->getUsername()));
  499.                         } else {
  500.                                 $error =" Veillez corrigez vos erreurs";
  501.                         }
  502.                 }
  503.             }
  504.         }
  505.         return $this->render('entreprise/creer_compte_professionel.html.twig', [
  506.             
  507.             'form' => $form->createView(),
  508.             'error' => $error,
  509.             'categorieEntreprises' => $categorieEntreprises
  510.         ]);
  511.     }
  512.     
  513.     /**
  514.      * @Route("/entreprise-d-une-categorie", name="entreprise_entreprise_d_une_categorie")
  515.      * @return \Symfony\Component\HttpFoundation\Response
  516.      */
  517.     public function entrepriseEntrepriseDUneCategorieAction(Request $request )
  518.     {
  519.         $em = $this->getDoctrine()
  520.                     ->getManager();
  521.         $boutiques = array();
  522.         if($request->getMethod() == 'POST'){
  523.             $categorie = $request->request->get('categorie');
  524.             
  525.             
  526.             $categorieEntreprise = $em->getRepository(CategorieEntreprise::class)
  527.                                 ->findOneBy(
  528.                                     array(
  529.                                         'nom' => $categorie,
  530.                                         'estSupprime' => false
  531.                                     )    
  532.                                 );
  533.                                 
  534.             $boutiques = $em->getRepository(Boutique::class)
  535.                         ->findBy(
  536.                             array(
  537.                                 'categorieEntreprise' => $categorieEntreprise->getId(),
  538.                                 'estSupprime' => false
  539.                             ),
  540.                             array(
  541.                                 'nom' => 'ASC'
  542.                             )
  543.                         );
  544.             
  545.         }
  546.         
  547.         return $this->render('entreprise/entreprise_d_une_categorie.html.twig', [
  548.             'boutiques' => $boutiques
  549.         ]);
  550.     }
  551.     /**
  552.      * @Route("/about", name="about")
  553.      * @return \Symfony\Component\HttpFoundation\Response
  554.      */
  555.     public function aboutAction(Request $request )
  556.     {
  557.         $em = $this->getDoctrine()
  558.                     ->getManager();
  559.         $extraSettings = $em->getRepository(ExtraSettings::class)
  560.                             ->findOneById(1);
  561.         
  562.         
  563.         
  564.         return $this->render('entreprise/about.html.twig', [
  565.             'extraSettings' => $extraSettings
  566.         ]);
  567.     }
  568.     
  569.     /**
  570.      * @Route("/terms", name="terms")
  571.      * @return \Symfony\Component\HttpFoundation\Response
  572.      */
  573.     public function termsAction(Request $request )
  574.     {
  575.         $em = $this->getDoctrine()
  576.                     ->getManager();
  577.                     
  578.         $extraSettings = $em->getRepository(ExtraSettings::class)
  579.                             ->findOneById(1);
  580.         
  581.         
  582.         return $this->render('entreprise/terms.html.twig', [
  583.             'extraSettings' => $extraSettings
  584.         ]);
  585.     }
  586.     
  587.     /**
  588.      * @Route("/privacy", name="privacy")
  589.      * @return \Symfony\Component\HttpFoundation\Response
  590.      */
  591.     public function privacyAction(Request $request )
  592.     {
  593.         $em = $this->getDoctrine()
  594.                     ->getManager();
  595.         $extraSettings = $em->getRepository(ExtraSettings::class)
  596.                             ->findOneById(1);
  597.         
  598.         
  599.         return $this->render('entreprise/privacy.html.twig', [
  600.             'extraSettings'  => $extraSettings
  601.         ]);
  602.     }
  603.     
  604.     
  605.     /**
  606.      * @Route("/afficher-devis/{slug}", name="afficher_devis")
  607.      * @return \Symfony\Component\HttpFoundation\Response
  608.      */
  609.     public function AfficherDevisAction(Request $request, Devis $devis)
  610.     {
  611.         $em = $this->getDoctrine()
  612.                     ->getManager();
  613.         $devis->setNombreDeVue($devis->getNombreDeVue() + 1);
  614.         $offreDevis = $em->getRepository(OffreDevis::class)
  615.                         ->findByDevis($devis);
  616.         $em->flush();
  617.         $user = $this->getUser();
  618.     
  619.         $notifications = $em->getRepository(Notification::class)
  620.                                         ->findBy(
  621.                                             array(
  622.                                             'user' => $user,
  623.                                             'vu'  => false
  624.                                             )
  625.                                         );
  626.         foreach($notifications as $notification){
  627.             $notification->setVu(true);
  628.         }
  629.         $em->flush();
  630.     
  631.         return $this->render('entreprise/afficher_devis.html.twig', [
  632.             'devis' => $devis,
  633.             'offreDevis' => $offreDevis
  634.         ]);
  635.     }
  636.     
  637.     /**
  638.      * @Route("/web-auth/facebook/", name="facebook_web_auth")
  639.      * @return \Symfony\Component\HttpFoundation\Response
  640.      */
  641.     public function faceBookWebAuthAction(Request $request, TokenAuthenticator  $authenticator, GuardAuthenticatorHandler $guardHandler)
  642.     {
  643.         $em = $this->getDoctrine()
  644.                     ->getManager();
  645.         $error = '';
  646.         $errorMessage = '';
  647.         if('POST' == $request->getMethod()){
  648.             $name = $request->request->get('name');
  649.             $picture = $request->request->get('picture');
  650.             $id = $request->request->get('id');
  651.             $accessToken = $request->request->get('access_token');
  652.             $email = $request->request->get('email');
  653.             
  654.             $user = $em->getRepository(AppUser::class)
  655.                         ->findOneByFacebookId($id);
  656.             
  657.             $errors = array();
  658.             $errorMessage = '';
  659.             $error = '';
  660.             if(null == $user){
  661.                 //If this Facebook user has already an account
  662.                 $oldUser = $em->getRepository(AppUser::class)
  663.                             ->findOneByEmail($email);
  664.                 if(null != $oldUser){
  665.                     $errorMessage = 'Il y a déjà un compte avec la même adresse email';
  666.                     $error = 'error';
  667.                 } else{
  668.                     $user = new AppUser;
  669.                     $user->setUsername($name);
  670.                     $user->setPassword($name);
  671.                     $user->setEmail($email);
  672.                     $user->setEnabled(true);
  673.                     $user->setFacebookId($id);
  674.                     $user->setFacebookAccessToken($accessToken);
  675.                     $user->getAvatar()->setUrl($picture);
  676.                     $em->persist($user);
  677.                     $em->flush();
  678.                     $error = 'success';
  679.                     $guardHandler->authenticateUserAndHandleSuccess(
  680.                     $user,          // the User object you just created
  681.                     $request,
  682.                     $authenticator, // authenticator whose onAuthenticationSuccess you want to use
  683.                     'main'          // the name of your firewall in security.yaml
  684.                     );
  685.                     
  686.                 }
  687.             }else{
  688.                 $error = 'success';
  689.                 $guardHandler->authenticateUserAndHandleSuccess(
  690.                 $user,          // the User object you just created
  691.                 $request,
  692.                 $authenticator, // authenticator whose onAuthenticationSuccess you want to use
  693.                 'main'          // the name of your firewall in security.yaml
  694.                 );
  695.             }
  696.         
  697.         }
  698.         $response = new JsonResponse;
  699.         $response->headers->set('Content-Type', 'application/json');
  700.         $response->setStatusCode(200);
  701.         $data = array(
  702.             "error" => $error,
  703.             "errorMessage" => $errorMessage
  704.         );
  705.         $response->setContent(json_encode($data));
  706.         return $response;
  707.     }
  708.     
  709.     /**
  710.      * @Route("/web-auth/google/", name="google_web_auth")
  711.      * @return \Symfony\Component\HttpFoundation\Response
  712.      */
  713.     public function googleWebAuthAction(Request $request, TokenAuthenticator  $authenticator, GuardAuthenticatorHandler $guardHandler)
  714.     {
  715.         $em = $this->getDoctrine()
  716.                     ->getManager();
  717.         $error = '';
  718.         $errorMessage = '';
  719.         if('POST' == $request->getMethod()){
  720.             $name = $request->request->get('name');
  721.             $picture = $request->request->get('picture');
  722.             $id = $request->request->get('id');
  723.             $accessToken = $request->request->get('access_token');
  724.             $email = $request->request->get('email');
  725.             
  726.             $user = $em->getRepository(AppUser::class)
  727.                         ->findOneByGoogleId($id);
  728.             
  729.             $errors = array();
  730.             $errorMessage = '';
  731.             $error = '';
  732.             if(null == $user){
  733.                 //If this Facebook user has already an account
  734.                 $oldUser = $em->getRepository(AppUser::class)
  735.                             ->findOneByEmail($email);
  736.                 if(null != $oldUser){
  737.                     $errorMessage = 'Il y a déjà un compte avec la même adresse email';
  738.                     $error = 'error';
  739.                 } else{
  740.                     $user = new AppUser;
  741.                     $user->setUsername($name);
  742.                     $user->setPassword($name);
  743.                     $user->setEmail($email);
  744.                     $user->setEnabled(true);
  745.                     $user->setGoogleId($id);
  746.                     $user->setGoogleAccessToken($accessToken);
  747.                     $user->getAvatar()->setUrl($picture);
  748.                     $em->persist($user);
  749.                     $em->flush();
  750.                     $error = 'success';
  751.                     $guardHandler->authenticateUserAndHandleSuccess(
  752.                     $user,          // the User object you just created
  753.                     $request,
  754.                     $authenticator, // authenticator whose onAuthenticationSuccess you want to use
  755.                     'main'          // the name of your firewall in security.yaml
  756.                     );
  757.                     
  758.                 }
  759.             }else{
  760.                 $error = 'success';
  761.                 $guardHandler->authenticateUserAndHandleSuccess(
  762.                 $user,          // the User object you just created
  763.                 $request,
  764.                 $authenticator, // authenticator whose onAuthenticationSuccess you want to use
  765.                 'main'          // the name of your firewall in security.yaml
  766.                 );
  767.             }
  768.         
  769.         }
  770.         $response = new JsonResponse;
  771.         $response->headers->set('Content-Type', 'application/json');
  772.         $response->setStatusCode(200);
  773.         $data = array(
  774.             "error" => $error,
  775.             "errorMessage" => $errorMessage
  776.         );
  777.         $response->setContent(json_encode($data));
  778.         return $response;
  779.     }
  780.     
  781.     /**
  782.      * @Route("/choisir-offre/{id}", name="choisir_offre")
  783.      * @return \Symfony\Component\HttpFoundation\Response
  784.      */
  785.     public function choisirOffreAction(Request $request, OffreDevis $offreDevis)
  786.     {
  787.         $em = $this->getDoctrine()
  788.                     ->getManager();
  789.         $offreDevis->setRemporte(true);
  790.         $offreDevis->getDevis()->setEstOuvert(false);
  791.         $em->flush();
  792.         $user = $this->getUser();
  793.         
  794.         $notification = new Notification;
  795.         $notification->setUser($offreDevis->getUser());
  796.         $notification->setTypeNotification('devis');
  797.         $lien =  $this->generateUrl('gestion.proposals', array('slug' => $offreDevis->getBoutique()->getSlug()));
  798.         $notification->setLien($lien);
  799.         $notification->setDescription('votre offre a été choisie');
  800.         $em->persist($notification);
  801.                     
  802.         $em->flush();
  803.        
  804.         return $this->redirectToRoute('afficher_devis', array('slug' => $offreDevis->getDevis()->getSlug()));
  805.     }
  806.     
  807.     /**
  808.      * @Route("/fermer-devis/{id}", name="fermer_devis")
  809.      * @return \Symfony\Component\HttpFoundation\Response
  810.      */
  811.     public function fermerDevisAction(Request $request, Devis $devis)
  812.     {
  813.         $em = $this->getDoctrine()
  814.                     ->getManager();
  815.         $devis->setEstOuvert(false);
  816.         $em->flush();
  817.         
  818.         return $this->redirectToRoute('afficher_devis', array('slug' => $devis->getSlug()));
  819.     }
  820.     
  821.     
  822.     /**
  823.      * @Route("/faire-une-offre/{slug}", name="faire_une_offre")
  824.      * @return \Symfony\Component\HttpFoundation\Response
  825.      */
  826.     public function faireUneOffreAction(Request $request, Devis $devis)
  827.     {
  828.         $em = $this->getDoctrine()
  829.                     ->getManager();
  830.         $devis->setNombreDeVue($devis->getNombreDeVue() + 1);
  831.         $em->flush();
  832.         $user = $this->getUser();
  833.         $userBoutiques = $em->getRepository(UserBoutique::class)
  834.                         ->findByUser($user);
  835.         $offreDevis = new OffreDevis;
  836.         $form = $this->createForm(OffreDevisType::class, $offreDevis);
  837.         if($request->getMethod() == 'POST'){
  838.             if(null == $user){
  839.                 return $this->redirectToRoute('security_login');
  840.             }
  841.                 $boutique = $request->request->get('boutique');
  842.                 $boutique = $em->getRepository(Boutique::class)
  843.                                 ->findOneById($boutique);
  844.                $form->handleRequest($request);
  845.                 if($form->isValid()){
  846.                     $offreDevis->setUser($user);
  847.                     $offreDevis->setDevis($devis);
  848.                     $offreDevis->setBoutique($boutique);
  849.                     $em->persist($offreDevis);
  850.                     $em->flush();
  851.                     
  852.                     $notification = new Notification;
  853.                     $notification->setUser($devis->getUser());
  854.                     $notification->setTypeNotification('devis');
  855.                     $lien =  $this->generateUrl('afficher_devis', array('slug' => $devis->getSlug()));
  856.                     $notification->setLien($lien);
  857.                     $notification->setDescription($boutique->getNom().' vous a fait une proposition ');
  858.                     $em->persist($notification);
  859.                     
  860.                     $em->flush();
  861.                     
  862.                     return $this->redirectToRoute('gestion.proposals', array('slug' => $boutique->getSlug()));
  863.                 } else {
  864.                     $error =" Veillez corrigez vos erreurs";
  865.                 }
  866.         }
  867.         return $this->render('entreprise/faire_une_offre.html.twig', [
  868.             'devis' => $devis,
  869.             'userBoutiques' => $userBoutiques,
  870.             'form' => $form->createView()
  871.         ]);
  872.     }
  873.     
  874.     /**
  875.      * @Route("/new-entreprise/{plan}", name="new_shop")
  876.      * @return \Symfony\Component\HttpFoundation\Response
  877.      */
  878.     public function nouvelleBoutiqueAction(Request $request, $plan)
  879.     {
  880.         if(!$this->isGranted('IS_AUTHENTICATED_FULLY')){
  881.            return $this->redirectToRoute('security_login');
  882.         }
  883.         $em = $this->getDoctrine()
  884.                     ->getManager();
  885.         $plan = $em->getRepository(Plan::class)
  886.                     ->findOneBySlug($plan);
  887.         $user = $this->getUser();
  888.         if(null == $plan){
  889.             return $this->createNotFoundException();
  890.         }
  891.         
  892.         $validiteService = new ValiditeService;
  893.         $today = new \DateTime();
  894.         $today->modify('+10 year');
  895.         $validiteService->setTypeValidite(ValiditeService::TYPE_ESSAI);
  896.             
  897.         
  898.         $boutique = new Boutique;
  899.         $boutique->setUser($user);
  900.         $form = $this->createForm(BoutiqueType::class, $boutique);
  901.         
  902.         $ok_soumission = '';
  903.         $error = '';
  904.         $totalAchat = 12;
  905.         $prix = $plan->getTarif();
  906.         $coupon = '';
  907.         
  908.         
  909.         //$likaMap = new LikaMapService;
  910.     
  911.         $totalAchat *= (float)$plan->getTarif();
  912.         if($request->getMethod() == 'POST'){
  913.             
  914.                $form->handleRequest($request);
  915.                if($form->isValid()){
  916.                        $entrepriseExiste = $em->getRepository(Boutique::class)
  917.                                         ->findOneByNom($form->getData()->getNom());
  918.                    if($entrepriseExiste != null){
  919.                         $error = 'Entreprise existante';
  920.                    } else{
  921.                          $boutique = $form->getData();
  922.                    $adresse3Words = preg_replace('/\/+/', '', $boutique->getAdresse3Words());
  923.                   
  924.                    $boutique->setAdresse3Words($adresse3Words);
  925.                    //$coor = $likaMap->coordinatesToWhat3words($adresse3Words);
  926.                    //$boutique->setLatitude($coor['lat']);
  927.                    //$boutique->setLongitude($coor['lng']);
  928.                   // $boutique->setVille($coor['localite']);
  929.                    
  930.                     if($plan->getNom() == 'Free'){
  931.                         $em->persist($boutique);
  932.                         
  933.                         $service = new Service;
  934.                         $service->setUser($user);
  935.                         $service->setBoutique($boutique);
  936.                         $service->setPlan($plan);
  937.                         $em->persist($service);
  938.                         $em->flush();
  939.                         
  940.                         $em->persist($validiteService);
  941.                         $validiteService->setService($service);
  942.                         $validiteService->setValableJusquAu($today);
  943.                         
  944.                         
  945.                         $userBoutique = new UserBoutique;
  946.                           
  947.                         $userBoutique->setUser($user);
  948.                         $userBoutique->setBoutique($boutique);
  949.                         $userBoutique->setRole(RoleBoutique::ADMIN);
  950.                         $em->persist($userBoutique);
  951.                         $em->flush();
  952.                           
  953.                         return $this->redirectToRoute('gestion_mes_entreprises');
  954.                         $boutique = new Boutique;
  955.                         $user = $this->getUser();
  956.                         $form = $this->createForm(BoutiqueType::class, $boutique);
  957.                         
  958.                         $ok_soumission =" Votre message a été pris en compte";
  959.                             
  960.                         $boutique = new Boutique;
  961.                         
  962.                         $form = $this->createForm(BoutiqueType::class, $boutique);
  963.                     }
  964.                    }
  965.                    
  966.                     
  967.                 } else {
  968.                     $error =" Veillez corrigez vos erreurs";
  969.                 }
  970.         }
  971.     
  972.         return $this->render('entreprise/new_shop.html.twig', [
  973.            'form' => $form->createView(),
  974.            'error' => $error
  975.         ]);
  976.     }
  977.     
  978.     
  979.     
  980.     
  981.     /**
  982.      * @Route("/afficher-entreprise/{slug}", name="afficher_entreprise")
  983.      * @return \Symfony\Component\HttpFoundation\Response
  984.      */
  985.     public function afficherEntrepriseAction(Request $request, Boutique $boutique)
  986.     {
  987.         $em = $this->getDoctrine()
  988.                     ->getManager();
  989.         $user = $this->getUser();
  990.         $error = '';
  991.         
  992.         $produits = $em->getRepository(Produit::class)
  993.                         ->findByBoutique($boutique);
  994.         $entreprises = $em->getRepository(Boutique::class)
  995.                         ->findBy(
  996.                             array(
  997.                                 'estBloque' => false
  998.                             )
  999.                         );
  1000.         $users = $em->getRepository(AppUser::class)
  1001.                         ->findAll();
  1002.         $nombreEntreprise = count($entreprises) + count($users);
  1003.         $avisUtilisateurs =  array(); 
  1004.         $boutique->setNombreDeVisite($boutique->getNombreDeVisite() + 1);
  1005.         $cestMaBoutique = false;
  1006.         $avisUtilisateurs  = $em->getRepository(AvisUtilisateur::class)
  1007.                             ->findBy(
  1008.                                 array(
  1009.                                     'boutique' => $boutique
  1010.                                 )
  1011.                             );
  1012.         
  1013.         
  1014.         $em->flush();
  1015.         $userBoutique = $em->getRepository(UserBoutique::class)
  1016.                             ->findOneBy(
  1017.                                 array(
  1018.                                     'boutique' => $boutique,
  1019.                                     'user'    => $user
  1020.                                 )
  1021.                             );
  1022.         if(null !== $userBoutique){
  1023.             $cestMaBoutique = true;
  1024.         }
  1025.         
  1026.         $nombreAvis = count($avisUtilisateurs);
  1027.         
  1028.         $uneEtoiles = array('moyenne' => 0);
  1029.         $deuxEtoiles = array('moyenne' => 0);
  1030.         $troisEtoiles = array('moyenne' => 0);
  1031.         $quatreEtoiles = array('moyenne' => 0);
  1032.         $cinqEtoiles = array('moyenne' => 0);
  1033.         
  1034.         $uneEtoile  = $em->getRepository(AvisUtilisateur::class)
  1035.                             ->findBy(
  1036.                                 array(
  1037.                                     'user' => $user,
  1038.                                     'boutique' => $boutique,
  1039.                                     'valeurAvis' => 1
  1040.                                 )
  1041.                             );
  1042.         $deuxEtoile  = $em->getRepository(AvisUtilisateur::class)
  1043.                             ->findBy(
  1044.                                 array(
  1045.                                     'user' => $user,
  1046.                                     'boutique' => $boutique,
  1047.                                     'valeurAvis' => 2
  1048.                                 )
  1049.                             );
  1050.                             
  1051.         
  1052.         $troisEtoile  = $em->getRepository(AvisUtilisateur::class)
  1053.                             ->findBy(
  1054.                                 array(
  1055.                                     'user' => $user,
  1056.                                     'boutique' => $boutique,
  1057.                                     'valeurAvis' => 3
  1058.                                 )
  1059.                             );
  1060.         
  1061.         $quatreEtoile  = $em->getRepository(AvisUtilisateur::class)
  1062.                             ->findBy(
  1063.                                 array(
  1064.                                     'user' => $user,
  1065.                                     'boutique' => $boutique,
  1066.                                     'valeurAvis' => 4
  1067.                                 )
  1068.                             );
  1069.     $cinqEtoile  = $em->getRepository(AvisUtilisateur::class)
  1070.                             ->findBy(
  1071.                                 array(
  1072.                                     'user' => $user,
  1073.                                     'boutique' => $boutique,
  1074.                                     'valeurAvis' => 5
  1075.                                 )
  1076.                             );
  1077.                             
  1078.         $uneEtoiles['nombre'] = count($uneEtoile);
  1079.         $deuxEtoiles['nombre'] = count($deuxEtoile);
  1080.         $troisEtoiles['nombre'] = count($troisEtoile);
  1081.         $quatreEtoiles['nombre'] = count($quatreEtoile);
  1082.         $cinqEtoiles['nombre'] = count($cinqEtoile);
  1083.         
  1084.         if($nombreAvis > 0){
  1085.             $uneEtoiles['moyenne'] = count($uneEtoile ) * 100 /$nombreAvis;
  1086.             $deuxEtoiles['moyenne'] = count($deuxEtoile ) * 100 /$nombreAvis;
  1087.             $troisEtoiles['moyenne'] = count($troisEtoile ) * 100 /$nombreAvis;
  1088.             $quatreEtoiles['moyenne'] = count($quatreEtoile ) * 100 /$nombreAvis;
  1089.             $cinqEtoiles['moyenne'] = count($cinqEtoile ) * 100 /$nombreAvis;
  1090.         }
  1091.         
  1092.         $dejaEnregistre = false;
  1093.         if(null != $user){
  1094.             $entrepriseEnregistres = $em->getRepository(EntrepriseEnregistre::class)
  1095.                                     ->findBy(
  1096.                                         array(
  1097.                                         'boutique' => $boutique->getId(),
  1098.                                         'user' => $user->getId()
  1099.                                         )
  1100.                                     );
  1101.             
  1102.             
  1103.             foreach($entrepriseEnregistres as $entrepriseEnregistre){
  1104.                 if($entrepriseEnregistre->getBoutique()->getId() == $boutique->getId()){
  1105.                     $dejaEnregistre = true;
  1106.                 }
  1107.             }
  1108.         }
  1109.         
  1110.         return $this->render('entreprise/afficher_entreprise.html.twig', [
  1111.           'boutique' => $boutique,
  1112.           'produits' => $produits,
  1113.           'nombreEntreprise' => $nombreEntreprise,
  1114.           'avisUtilisateurs' => $avisUtilisateurs,
  1115.           'cestMaBoutique' => $cestMaBoutique,
  1116.           'nombreAvis' => $nombreAvis,
  1117.           'uneEtoiles' => $uneEtoiles,
  1118.           'deuxEtoiles' => $deuxEtoiles,
  1119.           'troisEtoiles' => $troisEtoiles,
  1120.           'quatreEtoiles' => $quatreEtoiles,
  1121.           'cinqEtoiles' => $cinqEtoiles,
  1122.           'dejaEnregistre' => $dejaEnregistre
  1123.         ]);
  1124.     }
  1125.     
  1126.     /**
  1127.      * @Route("/save-entreprise/{slug}", name="save_entreprise")
  1128.      * @return \Symfony\Component\HttpFoundation\Response
  1129.      */
  1130.     public function saveEntrepriseAction(Request $request, Boutique $boutique)
  1131.     {
  1132.         if(!$this->isGranted('IS_AUTHENTICATED_FULLY')){
  1133.            return $this->redirectToRoute('security_login');
  1134.         }
  1135.         $em = $this->getDoctrine()
  1136.                     ->getManager();
  1137.         
  1138.     
  1139.         $user = $this->getUser();
  1140.         $entrepriseEnregistres = $em->getRepository(EntrepriseEnregistre::class)
  1141.                                 ->findBy(
  1142.                                     array(
  1143.                                     'boutique' => $boutique->getId(),
  1144.                                     'user' => $user->getId()
  1145.                                     )
  1146.                                 );
  1147.         $dejaEnregistre = false;
  1148.         foreach($entrepriseEnregistres as $entrepriseEnregistre){
  1149.             if($entrepriseEnregistre->getBoutique()->getId() == $boutique->getId()){
  1150.                 $dejaEnregistre = true;
  1151.             }
  1152.         }
  1153.         
  1154.         if($dejaEnregistre == false){
  1155.             $eenr = new EntrepriseEnregistre;
  1156.             
  1157.             $eenr->setBoutique($boutique);
  1158.             $eenr->setUser($user);
  1159.             $em->persist($eenr);
  1160.             $em->flush();
  1161.         }
  1162.         
  1163.         $this->addFlash('success', 'Enregistrement effectué avec succès');
  1164.         
  1165.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1166.         
  1167.     }
  1168.     
  1169.     /**
  1170.      * @Route("/reclamer-page/{slug}", name="reclamer_page")
  1171.      * @return \Symfony\Component\HttpFoundation\Response
  1172.      */
  1173.     public function reclamerPageAction(Request $request, Boutique $boutique)
  1174.     {
  1175.         $em = $this->getDoctrine()
  1176.                     ->getManager();
  1177.         $user = $this->getUser();
  1178.         $error = '';
  1179.         
  1180.         if($user == null){
  1181.             return $this->redirectToRoute('security_login');
  1182.         }
  1183.         
  1184.         $reclamerPage = new ReclamerPage;
  1185.         $reclamerPage->setBoutique($boutique);
  1186.         $reclamerPage->setEtat('En attente');
  1187.         $reclamerPage->setUser($user);
  1188.         $em->persist($reclamerPage);
  1189.         $em->flush();
  1190.         $this->addFlash('success', 'Enregistrement effectué');
  1191.         $userBoutiques = $em->getRepository(UserBoutique::class)
  1192.                                         ->findBy(
  1193.                                             array(
  1194.                                             'boutique' => $boutique
  1195.                                             )
  1196.                                         );
  1197.         foreach($userBoutiques as $userBoutique){
  1198.             $notification = new Notification;
  1199.             $notification->setUser($userBoutique->getUser());
  1200.             $lien =  $this->generateUrl('gestion.messages', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1201.             $notification->setLien($lien);
  1202.             $notification->setTypeNotification('reclammer_page');
  1203.             $notification->setDescription('Quelqu\'un a reclamé votre page ' . $userBoutique->getBoutique()->getNom());
  1204.             $em->persist($notification);
  1205.         }
  1206.         
  1207.         $notification = new Notification;
  1208.         $notification->setUser($this->getUser());
  1209.         $lien =  $this->generateUrl('management.claiming_pages');
  1210.         $notification->setLien($lien);
  1211.         $notification->setTypeNotification('reclammer_page_admin');
  1212.         $notification->setDescription('Reclammation de page ');
  1213.         $em->persist($notification);
  1214.         $em->flush();
  1215.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1216.     }
  1217.     
  1218.     /**
  1219.      * @Route("/avis-utile/{id}", name="avis_utile")
  1220.      * @return \Symfony\Component\HttpFoundation\Response
  1221.      */
  1222.     public function avisUtileAction(Request $request, AvisUtilisateur $avisUtilisateur)
  1223.     {
  1224.         $em = $this->getDoctrine()
  1225.                     ->getManager();
  1226.         $user = $this->getUser();
  1227.         $error = '';
  1228.         
  1229.         $avisUtilisateur->setAvisUtile($avisUtilisateur->getAvisUtile() + 1);
  1230.         
  1231.         $em->flush();
  1232.         $this->addFlash('success', 'Enregistrement effectué');
  1233.         
  1234.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1235.     }
  1236.     
  1237.     /**
  1238.      * @Route("/avis-inutile/{id}", name="avis_inutile")
  1239.      * @return \Symfony\Component\HttpFoundation\Response
  1240.      */
  1241.     public function avisInutileAction(Request $request, AvisUtilisateur $avisUtilisateur)
  1242.     {
  1243.         $em = $this->getDoctrine()
  1244.                     ->getManager();
  1245.         $user = $this->getUser();
  1246.         $error = '';
  1247.         
  1248.         $avisUtilisateur->setAvisInutile($avisUtilisateur->getAvisInutile() + 1);
  1249.         
  1250.         $em->flush();
  1251.         $this->addFlash('success', 'Enregistrement effectué');
  1252.         
  1253.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1254.     }
  1255.     
  1256.     /**
  1257.      * @Route("/signaler-avis/{id}", name="signaler_avis")
  1258.      * @return \Symfony\Component\HttpFoundation\Response
  1259.      */
  1260.     public function signalerAvisAction(Request $request, AvisUtilisateur $avisUtilisateur)
  1261.     {
  1262.         $em = $this->getDoctrine()
  1263.                     ->getManager();
  1264.         $user = $this->getUser();
  1265.         $error = '';
  1266.         
  1267.         $avisUtilisateur->setSignalerAvis($avisUtilisateur->getSignalerAvis() + 1);
  1268.         
  1269.         $em->flush();
  1270.         $this->addFlash('success', 'Enregistrement effectué');
  1271.         
  1272.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1273.     }
  1274.     
  1275.     
  1276.     /**
  1277.      * @Route("/donner-avis/{slug}", name="donner_avis")
  1278.      * @return \Symfony\Component\HttpFoundation\Response
  1279.      */
  1280.     public function donnerAvisAction(Request $request, Boutique $boutique)
  1281.     {
  1282.         $em = $this->getDoctrine()
  1283.                     ->getManager();
  1284.     
  1285.         
  1286.         $user = $this->getUser();
  1287.         $avisUtilisateur = new AvisUtilisateur;
  1288.         
  1289.         $form = $this->createForm(AvisUtilisateurType::class, $avisUtilisateur);
  1290.         
  1291.         if($request->getMethod() == 'POST'){
  1292.             if(null == $user){
  1293.                 return $this->redirectToRoute('security_login');
  1294.             }
  1295.                $form->handleRequest($request);
  1296.                 if($form->isValid()){
  1297.                     $avisUtilisateur->setUser($user);
  1298.                     $avisUtilisateur->setBoutique($boutique);
  1299.                     $em->persist($avisUtilisateur);
  1300.                     $em->flush();
  1301.                     $tousLesAvis = $em->getRepository(AvisUtilisateur::class)
  1302.                                         ->findByBoutique($boutique);
  1303.                      $this->addFlash('success', 'Envoyé avec succès');
  1304.                     
  1305.                     $moyenne = 0;
  1306.                     $nb = 0;
  1307.                     $note = 0;
  1308.                     foreach($tousLesAvis as $avis){
  1309.                         $note += $avis->getValeurAvis();
  1310.                         $nb++;
  1311.                     }
  1312.                     if($nb >0){
  1313.                         $moyenne = round($note/$nb, 1);
  1314.                     }
  1315.                     $boutique->setMoyenneAvis($moyenne);
  1316.                     $em->flush();
  1317.                     $userBoutiques = $em->getRepository(UserBoutique::class)
  1318.                                         ->findBy(
  1319.                                             array(
  1320.                                             'boutique' => $boutique
  1321.                                             )
  1322.                                         );
  1323.                     foreach($userBoutiques as $userBoutique){
  1324.                         $notification = new Notification;
  1325.                         $notification->setUser($userBoutique->getUser());
  1326.                         $lien =  $this->generateUrl('gestion.reviews', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1327.                         $notification->setLien($lien);
  1328.                         $notification->setTypeNotification('avis');
  1329.                         $notification->setDescription('Quelqu\'un a laissé un avis sur ' . $userBoutique->getBoutique()->getNom());
  1330.         
  1331.                         $em->persist($notification);
  1332.                     }
  1333.                     $em->flush();
  1334.                     return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1335.                 } else {
  1336.                     $error =" Veillez corrigez vos erreurs";
  1337.                 }
  1338.         }
  1339.         
  1340.         
  1341.         return $this->render('entreprise/donner_avis.html.twig', [
  1342.           'form' => $form->createView(),
  1343.           'boutique' => $boutique
  1344.         ]);
  1345.     }
  1346.     
  1347.     
  1348.     /**
  1349.      * @Route("/envoyer-message/{slug}", name="envoyer_message")
  1350.      * @return \Symfony\Component\HttpFoundation\Response
  1351.      */
  1352.     public function envoyerMessageAction(Request $request, Boutique $boutique)
  1353.     {
  1354.         $em = $this->getDoctrine()
  1355.                     ->getManager();
  1356.     
  1357.         $user = $this->getUser();
  1358.         $message = new Message;
  1359.         $error = '';
  1360.         
  1361.         $form = $this->createForm(MessageType::class, $message);
  1362.         
  1363.         if($request->getMethod() == 'POST'){
  1364.             if(null == $user){
  1365.                 return $this->redirectToRoute('security_login');
  1366.             }
  1367.                $form->handleRequest($request);
  1368.                 if($form->isValid()){
  1369.                     
  1370.                     $conversation = $em->getRepository(Conversation::class)
  1371.                                         ->findOneBy(
  1372.                                             array(
  1373.                                             'boutique' => $boutique,
  1374.                                             'user' => $user
  1375.                                             )
  1376.                                         );
  1377.                     if(null === $conversation){
  1378.                         $conversation = new Conversation;
  1379.                         $conversation->setUser($user);
  1380.                         $conversation->setBoutique($boutique);
  1381.                         $em->persist($conversation);
  1382.                         
  1383.                         $em->flush();
  1384.                     }
  1385.                     
  1386.                     $message->setUser($user);
  1387.                     $message->setConversation($conversation);
  1388.                     $em->persist($message);
  1389.                     $conversation->setLastMessage($message->getContenu());
  1390.                     $em->flush();
  1391.                     $this->addFlash('success', 'Envoyé avec succès');
  1392.                     
  1393.                     $userBoutiques = $em->getRepository(UserBoutique::class)
  1394.                                         ->findBy(
  1395.                                             array(
  1396.                                             'boutique' => $boutique
  1397.                                             )
  1398.                                         );
  1399.                     foreach($userBoutiques as $userBoutique){
  1400.                         $notification = new Notification;
  1401.                         $notification->setUser($userBoutique->getUser());
  1402.                         $lien =  $this->generateUrl('gestion.messages', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1403.                         $notification->setExtraData($conversation->getId());
  1404.                         $notification->setLien($lien);
  1405.                         $notification->setTypeNotification('message');
  1406.                         $notification->setDescription('Quelqu\'un vous a envoyé un message sur ' . $userBoutique->getBoutique()->getNom());
  1407.         
  1408.                         $em->persist($notification);
  1409.                     }
  1410.                     
  1411.                     $em->flush();
  1412.                     
  1413.                     
  1414.                     return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1415.                 } else {
  1416.                     $error =" Veillez corrigez vos erreurs";
  1417.                 }
  1418.         }
  1419.         
  1420.         
  1421.         return $this->render('entreprise/envoyer_message.html.twig', [
  1422.           'form' => $form->createView(),
  1423.           'boutique' => $boutique,
  1424.           'error'  => $error
  1425.         ]);
  1426.     }
  1427.     
  1428.     
  1429.     
  1430.     
  1431.     
  1432.     /**
  1433.      * @Route("/payment", name="payment")
  1434.      * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  1435.      * @return \Symfony\Component\HttpFoundation\Response
  1436.      */
  1437.     public function paymentAction(Request $request)
  1438.     {
  1439.         $em = $this->getDoctrine()
  1440.                     ->getManager();
  1441.         $boutique = $this->session->get('boutique');
  1442.         $plan = $this->session->get('plan');
  1443.         $montant = 12;
  1444.         $montant *= $plan->getTarif();
  1445.         
  1446.         $coupon =  $this->session->get('coupon');
  1447.         $remise =  $this->session->get('remise');
  1448.         $mt =  $this->session->get('mt');
  1449.         $total = $plan->getTarif() * 12;
  1450.         if($coupon == 'ABOMOLIE'){
  1451.             $tt = $total;
  1452.             $laRemise = 0;
  1453.             switch($total){
  1454.                 case 120:
  1455.                     $laRemise = (0.2 * $total);
  1456.                     $tt = $total - $laRemise;
  1457.                 break;
  1458.                         
  1459.                 case 300:
  1460.                     $laRemise = (0.3 * $total);
  1461.                     $tt = $total - $laRemise; 
  1462.                 break;
  1463.                         
  1464.                 case 1188:
  1465.                     $laRemise = (0.4 * $total);
  1466.                     $tt = $total - $laRemise; 
  1467.                             
  1468.                 break;
  1469.             }
  1470.             
  1471.             $montant = $tt;
  1472.         }
  1473.         
  1474.         $redirectUrl = $this->generateUrl('save_payment');
  1475.         return $this->render('entreprise/payment.html.twig', [
  1476.            'montant' => $montant, 
  1477.            'redirectUrl' => $redirectUrl
  1478.         ]);
  1479.     }
  1480.     
  1481.     /**
  1482.      * @Route("/save_payment", name="save_payment")
  1483.      * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  1484.      * @return \Symfony\Component\HttpFoundation\Response
  1485.      * 
  1486.      * Faire très attention à cette fonction, car elle doit influencer aussi tous les achats venant
  1487.      * de AppSumo et autre
  1488.      */
  1489.     public function savePaymentAction(Request $request)
  1490.     {
  1491.         $em = $this->getDoctrine()
  1492.                     ->getManager();
  1493.         $plan = $this->session->get('plan');
  1494.         $plan = $em->getRepository(Plan::class)
  1495.                     ->findOneById($plan->getId());
  1496.         $boutique = $this->session->get('boutique');
  1497.         $user = $this->getUser();
  1498.         $em->persist($boutique);
  1499.         $em->flush();
  1500.         $validiteService = new ValiditeService;
  1501.         $today = new \DateTime();
  1502.         $today->modify('+1 year');
  1503.         $validiteService->setTypeValidite(ValiditeService::TYPE_PAYE);
  1504.         
  1505.         
  1506.         $service = new Service;
  1507.         $service->setUser($user);
  1508.         $service->setPlan($plan);
  1509.         $service->setBoutique($boutique);
  1510.         $em->persist($service);
  1511.         $em->flush();
  1512.         
  1513.         $em->persist($validiteService);
  1514.         $validiteService->setService($service);
  1515.         $validiteService->setValableJusquAu($today);
  1516.         $validiteService->setMontantAbonnement($plan->getTarif() * 12);
  1517.         
  1518.     
  1519.         $tva = new TVA;
  1520.         $tva->setValeur(20);
  1521.         $tva->setLibelle('20%');
  1522.         $tva->setBoutique($boutique);
  1523.         $em->persist($tva);
  1524.         $userBoutique = new UserBoutique;
  1525.         $userBoutique->setUser($user);
  1526.         $userBoutique->setBoutique($boutique);
  1527.         $userBoutique->setRole(RoleBoutique::ADMIN);
  1528.         $em->persist($userBoutique);
  1529.         $em->flush();
  1530.         
  1531.         
  1532.         $paymentMethod = 'PayPal';
  1533.         //Générer facture pour le client
  1534.         
  1535.         $pdf = new Html2Pdf('P', 'A4', 'en');
  1536.         $user = $this->getUser();
  1537.         
  1538.         $content = $this->renderView('pdf/facture_client.html.twig', [
  1539.                 'boutique' => $boutique,
  1540.                 'user' => $user,
  1541.                 'plan' => $plan,
  1542.                 'validiteService' => $validiteService,
  1543.                 'paymentMethod' => $paymentMethod,
  1544.                 'domaine' => $this->getDomain()
  1545.             ]);
  1546.         $pdf->writeHTML($content);
  1547.         $name = time().$boutique->getId().rand(1, 10000).'.pdf';
  1548.         $lienPhysique = __DIR__.'/../../public/my-invoices/'.$name;
  1549.     
  1550.         $validiteService->setLienFacture($this->getDomain().'/my-invoices/'.$name);
  1551.         $pdf->output($lienPhysique, 'F');
  1552.         
  1553.         $em->flush();
  1554.         $this->session->set('boutique', '');
  1555.         $this->session->set('plan', '');
  1556.         return $this->redirectToRoute('admin.show_shop', array('slug' => $boutique->getSlug()));
  1557.     
  1558.     }
  1559.     
  1560.     /**
  1561.      * @Route("/choose-paied-plan", name="choose_paied_plan")
  1562.      * @return \Symfony\Component\HttpFoundation\Response
  1563.      */
  1564.     public function choosePaiedPlanAction(Request $request)
  1565.     {
  1566.         $em = $this->getDoctrine()
  1567.                     ->getManager();
  1568.         $plans = $em->getRepository(Plan::class)
  1569.                     ->paidPlan();
  1570.                     
  1571.         return $this->render('entreprise/choose_paied_plan.html.twig', [
  1572.             'plans' => $plans
  1573.         ]);
  1574.     }
  1575.     
  1576.     /**
  1577.      * @Route("/pricing", name="pricing")
  1578.      * @return \Symfony\Component\HttpFoundation\Response
  1579.      */
  1580.     public function pricingAction(Request $request)
  1581.     {
  1582.         $em = $this->getDoctrine()
  1583.                     ->getManager();
  1584.                     
  1585.         $plans = $em->getRepository(Plan::class)
  1586.                     ->paidPlan();
  1587.                     
  1588.         return $this->render('entreprise/pricing.html.twig', [
  1589.             'plans' => $plans
  1590.         ]);
  1591.     }
  1592.     
  1593.     /**
  1594.      * @Route("/sfc", name="cgv")
  1595.      * @return \Symfony\Component\HttpFoundation\Response
  1596.      */
  1597.     public function sfcAction(Request $request)
  1598.     {
  1599.         $locale = $request->getLocale();
  1600.         
  1601.         return $this->render('entreprise/'.$locale.'_sfc.html.twig', [
  1602.         'locale' => $locale
  1603.         ]);
  1604.     }
  1605.     
  1606.     
  1607.     /**
  1608.      * @Route("/chose-plan", name="chose_plan")
  1609.      * @return \Symfony\Component\HttpFoundation\Response
  1610.      */
  1611.     public function chosePlanAction(Request $request)
  1612.     {
  1613.         return $this->render('entreprise/chose_plan.html.twig', [
  1614.         ]);
  1615.     }
  1616.     
  1617.     
  1618.     /**
  1619.      * @Route("/{slug}/renouveller-abonnement", name="renouveller_abonnement")
  1620.      * @return \Symfony\Component\HttpFoundation\Response
  1621.      */
  1622.     public function renouvellerAbonnementAction(Request $request, Boutique $boutique)
  1623.     {
  1624.               
  1625.         $em = $this->getDoctrine()
  1626.                     ->getManager();
  1627.         $derniereValiditeService =  $em->getRepository(ValiditeService::class)
  1628.                         ->derniereValiditeService($boutique->getId());
  1629.         
  1630.         $service = $derniereValiditeService->getService();
  1631.         $planActuel = $service->getPlan();
  1632.         
  1633.         $plans = $em->getRepository(Plan::class)
  1634.                     ->paidPlan();
  1635.         $totalAchat = 12;
  1636.         $prix = $planActuel->getTarif();
  1637.         
  1638.         if($prix <= 0){
  1639.             $prix = 10;
  1640.             foreach($plans as $plan){
  1641.                 if($plan->getTarif() == 10){
  1642.                     $planActuel = $plan;
  1643.                 }
  1644.             }
  1645.         } else{
  1646.             
  1647.         }
  1648.         
  1649.         $totalAchat *= $prix;
  1650.         $redirectUrl = $this->generateUrl('enregistrer_renouvellement_abonnement', array('slug' => $boutique->getSlug()));
  1651.         
  1652.         return $this->render('entreprise/renouveller_abonnement.html.twig', [
  1653.            'boutique' => $boutique,
  1654.            'plans' => $plans,
  1655.            'redirectUrl' => $redirectUrl,
  1656.            'planActuel' => $planActuel,
  1657.            'totalAchat' => $totalAchat,
  1658.            'prix' => $prix
  1659.         ]);
  1660.     }
  1661.     
  1662.     /**
  1663.      * @Route("/{slug}/enregistrer-renouvellement-abonnement/{plan}", name="enregistrer_renouvellement_abonnement")
  1664.      * @return \Symfony\Component\HttpFoundation\Response
  1665.      */
  1666.     public function enregistrerRenouvellementAbonnementAction(Request $request,  $slug, $plan = 0)
  1667.     {
  1668.               
  1669.         $em = $this->getDoctrine()
  1670.                     ->getManager();
  1671.         
  1672.         $derniereValiditeService =  $em->getRepository(ValiditeService::class)
  1673.                         ->derniereValiditeService($boutique->getId());
  1674.         
  1675.         $boutique = $em->getRepository(Boutique::class)
  1676.                         ->findOneBySlug($slug);
  1677.         
  1678.         $service = $derniereValiditeService->getService();
  1679.         
  1680.         $plans = $em->getRepository(Plan::class)
  1681.                     ->paidPlan();
  1682.         $plan = $em->getRepository(Plan::class)
  1683.                         ->findOneById($plan);
  1684.                             
  1685.             if($service->getPlan()->getTarif() == 0 || $service->getPlan()->getId() != $plan->getId()){
  1686.                 $service = new Service;
  1687.                 $service->setUser($user);
  1688.                 $service->setPlan($plan);
  1689.                 $service->setBoutique($boutique);
  1690.                 $em->persist($service);
  1691.                 $em->flush();
  1692.             } else{
  1693.                 
  1694.             }
  1695.             
  1696.             $validiteService = new ValiditeService;
  1697.             $today = new \DateTime();
  1698.             $today->modify('+1 year');
  1699.             $validiteService->setTypeValidite(ValiditeService::TYPE_PAYE);
  1700.         
  1701.             $em->persist($validiteService);
  1702.             $validiteService->setService($service);
  1703.             $validiteService->setValableJusquAu($today);
  1704.             $validiteService->setMontantAbonnement($plan->getTarif() * 12);
  1705.         
  1706.         
  1707.             $paymentMethod = 'PayPal';
  1708.             //Générer facture pour le client
  1709.             
  1710.             $pdf = new Html2Pdf('P', 'A4', 'en');
  1711.             $user = $this->getUser();
  1712.             
  1713.             $content = $this->renderView('pdf/facture_client.html.twig', [
  1714.                     'boutique' => $boutique,
  1715.                     'user' => $user,
  1716.                     'plan' => $plan,
  1717.                     'validiteService' => $validiteService,
  1718.                     'paymentMethod' => $paymentMethod,
  1719.                     'domaine' => $this->getDomain()
  1720.                 ]);
  1721.             $pdf->writeHTML($content);
  1722.             $name = time().$boutique->getId().rand(1, 10000).'.pdf';
  1723.             $lienPhysique = __DIR__.'/../../public/my-invoices/'.$name;
  1724.         
  1725.             $validiteService->setLienFacture($this->getDomain().'/my-invoices/'.$name);
  1726.             $pdf->output($lienPhysique, 'F');
  1727.             
  1728.             $em->flush();
  1729.             return $this->redirectToRoute('admin.show_shop', array('slug' => $boutique->getSlug()));
  1730.     }
  1731.     
  1732.     /**
  1733.      * @Route("/display-product/{slug}", name="display_product")
  1734.      * @return \Symfony\Component\HttpFoundation\Response
  1735.      */
  1736.     public function displayProductAction(Request $request,  Produit $produit)
  1737.     {
  1738.               
  1739.         $em = $this->getDoctrine()
  1740.                     ->getManager();
  1741.         
  1742.         return $this->render('entreprise/display_product.html.twig', [
  1743.            'produit' => $produit
  1744.         ]);
  1745.         
  1746.     }
  1747.     
  1748.     /**
  1749.      * @Route("/notification-to-join-team/{email}", name="notification_requette_ajout_boutique")
  1750.      * @return \Symfony\Component\HttpFoundation\Response
  1751.      */
  1752.     public function notificationRequetteAjoutBoutiqueAction(Request $request,  $email)
  1753.     {
  1754.               
  1755.         $em = $this->getDoctrine()
  1756.                     ->getManager();
  1757.         
  1758.             
  1759.         $requeteBoutiques = $em->getRepository(RequeteAjoutBoutique::class)
  1760.                         ->findBy(
  1761.                             array(
  1762.                                 'email' => $email
  1763.                             )
  1764.                             );
  1765.         $nbRequete = count($requeteBoutiques);
  1766.         
  1767.         return $this->render('entreprise/notification_requette_ajout_boutique.html.twig', [
  1768.            'nbRequete' => $nbRequete
  1769.         ]);
  1770.         
  1771.     }
  1772.     
  1773.     /**
  1774.      * @Route("/notification/{id}", name="nouvelles_notifications")
  1775.      * @return \Symfony\Component\HttpFoundation\Response
  1776.      */
  1777.     public function nouvellesNotificationsAction(Request $request, AppUser $user)
  1778.     {  
  1779.         $em = $this->getDoctrine()
  1780.                     ->getManager();
  1781.         
  1782.             
  1783.         $notifications = $em->getRepository(Notification::class)
  1784.                         ->findBy(
  1785.                             array(
  1786.                                 'user' => $user,
  1787.                                 'vu' => false
  1788.                             )
  1789.                             );
  1790.         $nombreNotification = count($notifications);
  1791.         
  1792.         return $this->render('entreprise/nouvelles_notifications.html.twig', [
  1793.            'nombreNotification' => $nombreNotification,
  1794.            'notifications' => $notifications
  1795.         ]);
  1796.         
  1797.     }
  1798.     
  1799.     /**
  1800.      * @Route("/request-to-join-team/{email}", name="afficher_requette_ajout_boutique")
  1801.      * @return \Symfony\Component\HttpFoundation\Response
  1802.      */
  1803.     public function afficherRequetteAjoutBoutiqueAction(Request $request,  $email)
  1804.     {
  1805.               
  1806.         $em = $this->getDoctrine()
  1807.                     ->getManager();
  1808.             
  1809.         $requeteBoutiques = $em->getRepository(RequeteAjoutBoutique::class)
  1810.                         ->findByEmail($email);
  1811.                         
  1812.         foreach($requeteBoutiques as $requeteBoutique){
  1813.             $requeteBoutique->setVu(true);
  1814.         }
  1815.         
  1816.         $em->flush();
  1817.         
  1818.         return $this->render('entreprise/afficher_requette_ajout_boutique.html.twig', [
  1819.            'requeteBoutiques' => $requeteBoutiques
  1820.         ]);
  1821.         
  1822.     }
  1823.     
  1824.     /**
  1825.      * @Route("/respond-request-to-join-team/{id}/{status}", name="repondre_requette_ajout_boutique")
  1826.      * @return \Symfony\Component\HttpFoundation\Response
  1827.      */
  1828.     public function repondreRequetteAjoutBoutiqueAction(Request $request,  $id, $status)
  1829.     {
  1830.               
  1831.         $em = $this->getDoctrine()
  1832.                     ->getManager();
  1833.             
  1834.         $requeteAjout = $em->getRepository(RequeteAjoutBoutique::class)
  1835.                         ->findOneById($id);
  1836.         $user = $this->getUser();    
  1837.         if($status){
  1838.             $userBoutique = $em->getRepository(UserBoutique::class)
  1839.                                 ->findOneBy(
  1840.                                     array(
  1841.                                         'user' => $user->getId(),
  1842.                                         'boutique' => $requeteAjout->getBoutique()->getId()
  1843.                                     )
  1844.                                 );
  1845.             if(null === $userBoutique){
  1846.                 $userBoutique = new UserBoutique;
  1847.                 $userBoutique->setUser($user);
  1848.                 $userBoutique->setBoutique($requeteAjout->getBoutique());
  1849.                 $userBoutique->setRole($requeteAjout->getRole());
  1850.                 $em->persist($userBoutique);
  1851.             }
  1852.         } 
  1853.         $em->remove($requeteAjout);
  1854.         $em->flush();
  1855.         
  1856.         return $this->redirectToRoute('home');
  1857.         
  1858.     }
  1859.     
  1860.     public function getDomain()
  1861.     {
  1862.         $domaine = $_SERVER['HTTP_HOST'];
  1863.         $protocol = '';
  1864.         if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'){
  1865.             $protocol = 'https://';
  1866.         } else{
  1867.             $protocol = 'http://';
  1868.         }
  1869.         
  1870.         return $protocol.$domaine;
  1871.     }
  1872.     
  1873. }