src/Controller/EntrepriseController.php line 603

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($distancesfloor($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 $requestCategorieEntreprise $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.                     ->findAll();
  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.                         $em->persist($offreDevis);
  368.                         
  369.                         $userBoutiques $em->getRepository(UserBoutique::class)
  370.                                         ->findBy(
  371.                                             array(
  372.                                             'boutique' => $boutique
  373.                                             )
  374.                                         );
  375.                     foreach($userBoutiques as $userBoutique){
  376.                         $notification = new Notification;
  377.                         $notification->setUser($userBoutique->getUser());
  378.                         $lien =  $this->generateUrl('gestion.proposals', array('slug' => $userBoutique->getBoutique()->getSlug()));
  379.                         $notification->setExtraData($devis->getId());
  380.                         $notification->setLien($lien);
  381.                         $notification->setTypeNotification('devis');
  382.                         $notification->setDescription('Quelqu\'un vous a envoyé un devis sur ' $userBoutique->getBoutique()->getNom());
  383.         
  384.                         $em->persist($notification);
  385.                     }
  386.                         
  387.                     
  388.                     } else{
  389.                         $devisFromData $form->getData();
  390.                         $entrepriseDuneCategories $em->getRepository(Boutique::class)
  391.                                                         ->findByCategorieEntreprise($devisFromData->getCategorieEntreprise());
  392.                         $devis->setEstOuvert(true);
  393.                         foreach($entrepriseDuneCategories as $entreCat){
  394.                             
  395.                             
  396.                             $userBoutiques $em->getRepository(UserBoutique::class)
  397.                                         ->findBy(
  398.                                             array(
  399.                                             'boutique' => $entreCat
  400.                                             )
  401.                                         );
  402.                                 foreach($userBoutiques as $userBoutique){
  403.                                     $notification = new Notification;
  404.                                     $notification->setUser($userBoutique->getUser());
  405.                                     $lien =  $this->generateUrl('gestion.proposals', array('slug' => $userBoutique->getBoutique()->getSlug()));
  406.                                     $notification->setExtraData($devis->getId());
  407.                                     $notification->setLien($lien);
  408.                                     $notification->setTypeNotification('devis');
  409.                                     $notification->setDescription('Nouveau devis pour ' $userBoutique->getBoutique()->getNom());
  410.                     
  411.                                     $em->persist($notification);
  412.                                 }
  413.                             
  414.                         }
  415.                     }
  416.                     
  417.                     $em->flush();
  418.                     
  419.                     return $this->redirectToRoute('afficher_devis', array('slug' => $devis->getSlug()));
  420.                 
  421.         }
  422.         return $this->render('entreprise/nouveau_devis.html.twig', [
  423.             'devis' => $devis,
  424.             'form' => $form->createView(),
  425.             'fromABoutique' => $fromABoutique
  426.         ]);
  427.     }
  428.     
  429.     /**
  430.      * @Route("/creer-compte-professionnel", name="entreprise_creer_compte_professionel")
  431.      * @return \Symfony\Component\HttpFoundation\Response
  432.      */
  433.     public function creerCompteProfessionnelAction(Request $requestUserPasswordHasherInterface $passwordHasherUserAuthenticatorInterface $userAuthenticatorLoginFormAuthenticator $authenticator)
  434.     {
  435.         if(null != $this->getUser()){
  436.             return $this->redirectToRoute('security_login');
  437.         }
  438.         $em $this->getDoctrine()
  439.                     ->getManager();
  440.     
  441.         $categorieEntreprises $em->getRepository(CategorieEntreprise::class)
  442.                                 ->findBy(
  443.                                 array(
  444.                                     'estSupprime' => false,
  445.                                 ),
  446.                                 array('nom' => 'ASC')
  447.                             );
  448.             
  449.         $user = new AppUser;
  450.         $user->setTypeCompte('Professionnel');
  451.         $user->setEnabled(true);
  452.         $error '';
  453.         
  454.         $form $this->createForm(CompteProfessionnelFormType::class, $user);
  455.         if($request->getMethod() == 'POST'){
  456.             $form->handleRequest($request);
  457.             
  458.             $password1 $_POST['compte_professionnel_form']['plainPassword']['first'];
  459.             $password2 $_POST['compte_professionnel_form']['plainPassword']['second'];
  460.             $email $_POST['compte_professionnel_form']['email'];
  461.             $username '';
  462.             
  463.             if($password1 != $password2){
  464.                 $error 'entreprise.password_not_corresponding';
  465.             } else{
  466.                 $emailUser $em->getRepository(AppUser::class)
  467.                                 ->findOneByEmail($email);
  468.                 if($emailUser != null){
  469.                     $error 'entreprise.email_already_used';
  470.                 } else{
  471.                     
  472.                     if($form->isValid()){
  473.                         $hashedPassword $passwordHasher->hashPassword($user$password1);
  474.                         $user->setPassword($hashedPassword);
  475.                                 
  476.                         $em->persist($user);
  477.                         $em->flush();
  478.                                 
  479.                         return $userAuthenticator->authenticateUser(
  480.                                 $user,
  481.                                         $authenticator// Pass your specific authenticator instance
  482.                                         $request
  483.                                     );
  484.                                 return $this->redirectToRoute('registration_confirmed', array('username' => $user->getUsername()));
  485.                         } else {
  486.                                 $error =" Veillez corrigez vos erreurs";
  487.                         }
  488.                 }
  489.             }
  490.         }
  491.         return $this->render('entreprise/creer_compte_professionel.html.twig', [
  492.             
  493.             'form' => $form->createView(),
  494.             'error' => $error,
  495.             'categorieEntreprises' => $categorieEntreprises
  496.         ]);
  497.     }
  498.     
  499.     /**
  500.      * @Route("/entreprise-d-une-categorie", name="entreprise_entreprise_d_une_categorie")
  501.      * @return \Symfony\Component\HttpFoundation\Response
  502.      */
  503.     public function entrepriseEntrepriseDUneCategorieAction(Request $request )
  504.     {
  505.         $em $this->getDoctrine()
  506.                     ->getManager();
  507.         $boutiques = array();
  508.         if($request->getMethod() == 'POST'){
  509.             $categorie $request->request->get('categorie');
  510.             
  511.             
  512.             $categorieEntreprise $em->getRepository(CategorieEntreprise::class)
  513.                                 ->findOneBy(
  514.                                     array(
  515.                                         'nom' => $categorie,
  516.                                         'estSupprime' => false
  517.                                     )    
  518.                                 );
  519.                                 
  520.             $boutiques $em->getRepository(Boutique::class)
  521.                         ->findBy(
  522.                             array(
  523.                                 'categorieEntreprise' => $categorieEntreprise->getId(),
  524.                                 'estSupprime' => false
  525.                             ),
  526.                             array(
  527.                                 'nom' => 'ASC'
  528.                             )
  529.                         );
  530.             
  531.         }
  532.         
  533.         return $this->render('entreprise/entreprise_d_une_categorie.html.twig', [
  534.             'boutiques' => $boutiques
  535.         ]);
  536.     }
  537.     /**
  538.      * @Route("/about", name="about")
  539.      * @return \Symfony\Component\HttpFoundation\Response
  540.      */
  541.     public function aboutAction(Request $request )
  542.     {
  543.         $em $this->getDoctrine()
  544.                     ->getManager();
  545.         $extraSettings $em->getRepository(ExtraSettings::class)
  546.                             ->findOneById(1);
  547.         
  548.         
  549.         
  550.         return $this->render('entreprise/about.html.twig', [
  551.             'extraSettings' => $extraSettings
  552.         ]);
  553.     }
  554.     
  555.     /**
  556.      * @Route("/terms", name="terms")
  557.      * @return \Symfony\Component\HttpFoundation\Response
  558.      */
  559.     public function termsAction(Request $request )
  560.     {
  561.         $em $this->getDoctrine()
  562.                     ->getManager();
  563.                     
  564.         $extraSettings $em->getRepository(ExtraSettings::class)
  565.                             ->findOneById(1);
  566.         
  567.         
  568.         return $this->render('entreprise/terms.html.twig', [
  569.             'extraSettings' => $extraSettings
  570.         ]);
  571.     }
  572.     
  573.     /**
  574.      * @Route("/privacy", name="privacy")
  575.      * @return \Symfony\Component\HttpFoundation\Response
  576.      */
  577.     public function privacyAction(Request $request )
  578.     {
  579.         $em $this->getDoctrine()
  580.                     ->getManager();
  581.         $extraSettings $em->getRepository(ExtraSettings::class)
  582.                             ->findOneById(1);
  583.         
  584.         
  585.         return $this->render('entreprise/privacy.html.twig', [
  586.             'extraSettings'  => $extraSettings
  587.         ]);
  588.     }
  589.     
  590.     
  591.     /**
  592.      * @Route("/afficher-devis/{slug}", name="afficher_devis")
  593.      * @return \Symfony\Component\HttpFoundation\Response
  594.      */
  595.     public function AfficherDevisAction(Request $requestDevis $devis)
  596.     {
  597.         $em $this->getDoctrine()
  598.                     ->getManager();
  599.         $devis->setNombreDeVue($devis->getNombreDeVue() + 1);
  600.         $offreDevis $em->getRepository(OffreDevis::class)
  601.                         ->findByDevis($devis);
  602.         $em->flush();
  603.         $user $this->getUser();
  604.     
  605.         $notifications $em->getRepository(Notification::class)
  606.                                         ->findBy(
  607.                                             array(
  608.                                             'user' => $user,
  609.                                             'vu'  => false
  610.                                             )
  611.                                         );
  612.         foreach($notifications as $notification){
  613.             $notification->setVu(true);
  614.         }
  615.         $em->flush();
  616.     
  617.         return $this->render('entreprise/afficher_devis.html.twig', [
  618.             'devis' => $devis,
  619.             'offreDevis' => $offreDevis
  620.         ]);
  621.     }
  622.     
  623.     /**
  624.      * @Route("/web-auth/facebook/", name="facebook_web_auth")
  625.      * @return \Symfony\Component\HttpFoundation\Response
  626.      */
  627.     public function faceBookWebAuthAction(Request $requestTokenAuthenticator  $authenticatorGuardAuthenticatorHandler $guardHandler)
  628.     {
  629.         $em $this->getDoctrine()
  630.                     ->getManager();
  631.         $error '';
  632.         $errorMessage '';
  633.         if('POST' == $request->getMethod()){
  634.             $name $request->request->get('name');
  635.             $picture $request->request->get('picture');
  636.             $id $request->request->get('id');
  637.             $accessToken $request->request->get('access_token');
  638.             $email $request->request->get('email');
  639.             
  640.             $user $em->getRepository(AppUser::class)
  641.                         ->findOneByFacebookId($id);
  642.             
  643.             $errors = array();
  644.             $errorMessage '';
  645.             $error '';
  646.             if(null == $user){
  647.                 //If this Facebook user has already an account
  648.                 $oldUser $em->getRepository(AppUser::class)
  649.                             ->findOneByEmail($email);
  650.                 if(null != $oldUser){
  651.                     $errorMessage 'Il y a déjà un compte avec la même adresse email';
  652.                     $error 'error';
  653.                 } else{
  654.                     $user = new AppUser;
  655.                     $user->setUsername($name);
  656.                     $user->setPassword($name);
  657.                     $user->setEmail($email);
  658.                     $user->setEnabled(true);
  659.                     $user->setFacebookId($id);
  660.                     $user->setFacebookAccessToken($accessToken);
  661.                     $user->getAvatar()->setUrl($picture);
  662.                     $em->persist($user);
  663.                     $em->flush();
  664.                     $error 'success';
  665.                     $guardHandler->authenticateUserAndHandleSuccess(
  666.                     $user,          // the User object you just created
  667.                     $request,
  668.                     $authenticator// authenticator whose onAuthenticationSuccess you want to use
  669.                     'main'          // the name of your firewall in security.yaml
  670.                     );
  671.                     
  672.                 }
  673.             }else{
  674.                 $error 'success';
  675.                 $guardHandler->authenticateUserAndHandleSuccess(
  676.                 $user,          // the User object you just created
  677.                 $request,
  678.                 $authenticator// authenticator whose onAuthenticationSuccess you want to use
  679.                 'main'          // the name of your firewall in security.yaml
  680.                 );
  681.             }
  682.         
  683.         }
  684.         $response = new JsonResponse;
  685.         $response->headers->set('Content-Type''application/json');
  686.         $response->setStatusCode(200);
  687.         $data = array(
  688.             "error" => $error,
  689.             "errorMessage" => $errorMessage
  690.         );
  691.         $response->setContent(json_encode($data));
  692.         return $response;
  693.     }
  694.     
  695.     /**
  696.      * @Route("/web-auth/google/", name="google_web_auth")
  697.      * @return \Symfony\Component\HttpFoundation\Response
  698.      */
  699.     public function googleWebAuthAction(Request $requestTokenAuthenticator  $authenticatorGuardAuthenticatorHandler $guardHandler)
  700.     {
  701.         $em $this->getDoctrine()
  702.                     ->getManager();
  703.         $error '';
  704.         $errorMessage '';
  705.         if('POST' == $request->getMethod()){
  706.             $name $request->request->get('name');
  707.             $picture $request->request->get('picture');
  708.             $id $request->request->get('id');
  709.             $accessToken $request->request->get('access_token');
  710.             $email $request->request->get('email');
  711.             
  712.             $user $em->getRepository(AppUser::class)
  713.                         ->findOneByGoogleId($id);
  714.             
  715.             $errors = array();
  716.             $errorMessage '';
  717.             $error '';
  718.             if(null == $user){
  719.                 //If this Facebook user has already an account
  720.                 $oldUser $em->getRepository(AppUser::class)
  721.                             ->findOneByEmail($email);
  722.                 if(null != $oldUser){
  723.                     $errorMessage 'Il y a déjà un compte avec la même adresse email';
  724.                     $error 'error';
  725.                 } else{
  726.                     $user = new AppUser;
  727.                     $user->setUsername($name);
  728.                     $user->setPassword($name);
  729.                     $user->setEmail($email);
  730.                     $user->setEnabled(true);
  731.                     $user->setGoogleId($id);
  732.                     $user->setGoogleAccessToken($accessToken);
  733.                     $user->getAvatar()->setUrl($picture);
  734.                     $em->persist($user);
  735.                     $em->flush();
  736.                     $error 'success';
  737.                     $guardHandler->authenticateUserAndHandleSuccess(
  738.                     $user,          // the User object you just created
  739.                     $request,
  740.                     $authenticator// authenticator whose onAuthenticationSuccess you want to use
  741.                     'main'          // the name of your firewall in security.yaml
  742.                     );
  743.                     
  744.                 }
  745.             }else{
  746.                 $error 'success';
  747.                 $guardHandler->authenticateUserAndHandleSuccess(
  748.                 $user,          // the User object you just created
  749.                 $request,
  750.                 $authenticator// authenticator whose onAuthenticationSuccess you want to use
  751.                 'main'          // the name of your firewall in security.yaml
  752.                 );
  753.             }
  754.         
  755.         }
  756.         $response = new JsonResponse;
  757.         $response->headers->set('Content-Type''application/json');
  758.         $response->setStatusCode(200);
  759.         $data = array(
  760.             "error" => $error,
  761.             "errorMessage" => $errorMessage
  762.         );
  763.         $response->setContent(json_encode($data));
  764.         return $response;
  765.     }
  766.     
  767.     /**
  768.      * @Route("/choisir-offre/{id}", name="choisir_offre")
  769.      * @return \Symfony\Component\HttpFoundation\Response
  770.      */
  771.     public function choisirOffreAction(Request $requestOffreDevis $offreDevis)
  772.     {
  773.         $em $this->getDoctrine()
  774.                     ->getManager();
  775.         $offreDevis->setRemporte(true);
  776.         $offreDevis->getDevis()->setEstOuvert(false);
  777.         $em->flush();
  778.         $user $this->getUser();
  779.         
  780.         $notification = new Notification;
  781.         $notification->setUser($offreDevis->getUser());
  782.         $notification->setTypeNotification('devis');
  783.         $lien =  $this->generateUrl('gestion.proposals', array('slug' => $offreDevis->getBoutique()->getSlug()));
  784.         $notification->setLien($lien);
  785.         $notification->setDescription('votre offre a été choisie');
  786.         $em->persist($notification);
  787.                     
  788.         $em->flush();
  789.        
  790.         return $this->redirectToRoute('afficher_devis', array('slug' => $offreDevis->getDevis()->getSlug()));
  791.     }
  792.     
  793.     /**
  794.      * @Route("/fermer-devis/{id}", name="fermer_devis")
  795.      * @return \Symfony\Component\HttpFoundation\Response
  796.      */
  797.     public function fermerDevisAction(Request $requestDevis $devis)
  798.     {
  799.         $em $this->getDoctrine()
  800.                     ->getManager();
  801.         $devis->setEstOuvert(false);
  802.         $em->flush();
  803.         
  804.         return $this->redirectToRoute('afficher_devis', array('slug' => $devis->getSlug()));
  805.     }
  806.     
  807.     
  808.     /**
  809.      * @Route("/faire-une-offre/{slug}", name="faire_une_offre")
  810.      * @return \Symfony\Component\HttpFoundation\Response
  811.      */
  812.     public function faireUneOffreAction(Request $requestDevis $devis)
  813.     {
  814.         $em $this->getDoctrine()
  815.                     ->getManager();
  816.         $devis->setNombreDeVue($devis->getNombreDeVue() + 1);
  817.         $em->flush();
  818.         $user $this->getUser();
  819.         $userBoutiques $em->getRepository(UserBoutique::class)
  820.                         ->findByUser($user);
  821.         $offreDevis = new OffreDevis;
  822.         $form $this->createForm(OffreDevisType::class, $offreDevis);
  823.         if($request->getMethod() == 'POST'){
  824.             if(null == $user){
  825.                 return $this->redirectToRoute('security_login');
  826.             }
  827.                 $boutique $request->request->get('boutique');
  828.                 $boutique $em->getRepository(Boutique::class)
  829.                                 ->findOneById($boutique);
  830.                $form->handleRequest($request);
  831.                 if($form->isValid()){
  832.                     $offreDevis->setUser($user);
  833.                     $offreDevis->setDevis($devis);
  834.                     $offreDevis->setBoutique($boutique);
  835.                     $em->persist($offreDevis);
  836.                     $em->flush();
  837.                     
  838.                     $notification = new Notification;
  839.                     $notification->setUser($devis->getUser());
  840.                     $notification->setTypeNotification('devis');
  841.                     $lien =  $this->generateUrl('afficher_devis', array('slug' => $devis->getSlug()));
  842.                     $notification->setLien($lien);
  843.                     $notification->setDescription($boutique->getNom().' vous a fait une proposition ');
  844.                     $em->persist($notification);
  845.                     
  846.                     $em->flush();
  847.                     
  848.                     return $this->redirectToRoute('gestion.proposals', array('slug' => $boutique->getSlug()));
  849.                 } else {
  850.                     $error =" Veillez corrigez vos erreurs";
  851.                 }
  852.         }
  853.         return $this->render('entreprise/faire_une_offre.html.twig', [
  854.             'devis' => $devis,
  855.             'userBoutiques' => $userBoutiques,
  856.             'form' => $form->createView()
  857.         ]);
  858.     }
  859.     
  860.     /**
  861.      * @Route("/new-entreprise/{plan}", name="new_shop")
  862.      * @return \Symfony\Component\HttpFoundation\Response
  863.      */
  864.     public function nouvelleBoutiqueAction(Request $request$plan)
  865.     {
  866.         if(!$this->isGranted('IS_AUTHENTICATED_FULLY')){
  867.            return $this->redirectToRoute('security_login');
  868.         }
  869.         $em $this->getDoctrine()
  870.                     ->getManager();
  871.         $plan $em->getRepository(Plan::class)
  872.                     ->findOneBySlug($plan);
  873.         $user $this->getUser();
  874.         if(null == $plan){
  875.             return $this->createNotFoundException();
  876.         }
  877.         
  878.         $validiteService = new ValiditeService;
  879.         $today = new \DateTime();
  880.         $today->modify('+10 year');
  881.         $validiteService->setTypeValidite(ValiditeService::TYPE_ESSAI);
  882.             
  883.         
  884.         $boutique = new Boutique;
  885.         $boutique->setUser($user);
  886.         $form $this->createForm(BoutiqueType::class, $boutique);
  887.         
  888.         $ok_soumission '';
  889.         $error '';
  890.         $totalAchat 12;
  891.         $prix $plan->getTarif();
  892.         $coupon '';
  893.         
  894.         
  895.         //$likaMap = new LikaMapService;
  896.     
  897.         $totalAchat *= (float)$plan->getTarif();
  898.         if($request->getMethod() == 'POST'){
  899.             
  900.                $form->handleRequest($request);
  901.                if($form->isValid()){
  902.                        $entrepriseExiste $em->getRepository(Boutique::class)
  903.                                         ->findOneByNom($form->getData()->getNom());
  904.                    if($entrepriseExiste != null){
  905.                         $error 'Entreprise existante';
  906.                    } else{
  907.                          $boutique $form->getData();
  908.                    $adresse3Words preg_replace('/\/+/'''$boutique->getAdresse3Words());
  909.                   
  910.                    $boutique->setAdresse3Words($adresse3Words);
  911.                    //$coor = $likaMap->coordinatesToWhat3words($adresse3Words);
  912.                    //$boutique->setLatitude($coor['lat']);
  913.                    //$boutique->setLongitude($coor['lng']);
  914.                   // $boutique->setVille($coor['localite']);
  915.                    
  916.                     if($plan->getNom() == 'Free'){
  917.                         $em->persist($boutique);
  918.                         
  919.                         $service = new Service;
  920.                         $service->setUser($user);
  921.                         $service->setBoutique($boutique);
  922.                         $service->setPlan($plan);
  923.                         $em->persist($service);
  924.                         $em->flush();
  925.                         
  926.                         $em->persist($validiteService);
  927.                         $validiteService->setService($service);
  928.                         $validiteService->setValableJusquAu($today);
  929.                         
  930.                         
  931.                         $userBoutique = new UserBoutique;
  932.                           
  933.                         $userBoutique->setUser($user);
  934.                         $userBoutique->setBoutique($boutique);
  935.                         $userBoutique->setRole(RoleBoutique::ADMIN);
  936.                         $em->persist($userBoutique);
  937.                         $em->flush();
  938.                           
  939.                         return $this->redirectToRoute('gestion_mes_entreprises');
  940.                         $boutique = new Boutique;
  941.                         $user $this->getUser();
  942.                         $form $this->createForm(BoutiqueType::class, $boutique);
  943.                         
  944.                         $ok_soumission =" Votre message a été pris en compte";
  945.                             
  946.                         $boutique = new Boutique;
  947.                         
  948.                         $form $this->createForm(BoutiqueType::class, $boutique);
  949.                     }
  950.                    }
  951.                    
  952.                     
  953.                 } else {
  954.                     $error =" Veillez corrigez vos erreurs";
  955.                 }
  956.         }
  957.     
  958.         return $this->render('entreprise/new_shop.html.twig', [
  959.            'form' => $form->createView(),
  960.            'error' => $error
  961.         ]);
  962.     }
  963.     
  964.     
  965.     
  966.     
  967.     /**
  968.      * @Route("/afficher-entreprise/{slug}", name="afficher_entreprise")
  969.      * @return \Symfony\Component\HttpFoundation\Response
  970.      */
  971.     public function afficherEntrepriseAction(Request $requestBoutique $boutique)
  972.     {
  973.         $em $this->getDoctrine()
  974.                     ->getManager();
  975.         $user $this->getUser();
  976.         $error '';
  977.         
  978.         $produits $em->getRepository(Produit::class)
  979.                         ->findByBoutique($boutique);
  980.         $entreprises $em->getRepository(Boutique::class)
  981.                         ->findBy(
  982.                             array(
  983.                                 'estBloque' => false
  984.                             )
  985.                         );
  986.         $users $em->getRepository(AppUser::class)
  987.                         ->findAll();
  988.         $nombreEntreprise count($entreprises) + count($users);
  989.         $avisUtilisateurs =  array(); 
  990.         $boutique->setNombreDeVisite($boutique->getNombreDeVisite() + 1);
  991.         $cestMaBoutique false;
  992.         $avisUtilisateurs  $em->getRepository(AvisUtilisateur::class)
  993.                             ->findBy(
  994.                                 array(
  995.                                     'boutique' => $boutique
  996.                                 )
  997.                             );
  998.         
  999.         
  1000.         $em->flush();
  1001.         $userBoutique $em->getRepository(UserBoutique::class)
  1002.                             ->findOneBy(
  1003.                                 array(
  1004.                                     'boutique' => $boutique,
  1005.                                     'user'    => $user
  1006.                                 )
  1007.                             );
  1008.         if(null !== $userBoutique){
  1009.             $cestMaBoutique true;
  1010.         }
  1011.         
  1012.         $nombreAvis count($avisUtilisateurs);
  1013.         
  1014.         $uneEtoiles = array('moyenne' => 0);
  1015.         $deuxEtoiles = array('moyenne' => 0);
  1016.         $troisEtoiles = array('moyenne' => 0);
  1017.         $quatreEtoiles = array('moyenne' => 0);
  1018.         $cinqEtoiles = array('moyenne' => 0);
  1019.         
  1020.         $uneEtoile  $em->getRepository(AvisUtilisateur::class)
  1021.                             ->findBy(
  1022.                                 array(
  1023.                                     'user' => $user,
  1024.                                     'boutique' => $boutique,
  1025.                                     'valeurAvis' => 1
  1026.                                 )
  1027.                             );
  1028.         $deuxEtoile  $em->getRepository(AvisUtilisateur::class)
  1029.                             ->findBy(
  1030.                                 array(
  1031.                                     'user' => $user,
  1032.                                     'boutique' => $boutique,
  1033.                                     'valeurAvis' => 2
  1034.                                 )
  1035.                             );
  1036.                             
  1037.         
  1038.         $troisEtoile  $em->getRepository(AvisUtilisateur::class)
  1039.                             ->findBy(
  1040.                                 array(
  1041.                                     'user' => $user,
  1042.                                     'boutique' => $boutique,
  1043.                                     'valeurAvis' => 3
  1044.                                 )
  1045.                             );
  1046.         
  1047.         $quatreEtoile  $em->getRepository(AvisUtilisateur::class)
  1048.                             ->findBy(
  1049.                                 array(
  1050.                                     'user' => $user,
  1051.                                     'boutique' => $boutique,
  1052.                                     'valeurAvis' => 4
  1053.                                 )
  1054.                             );
  1055.     $cinqEtoile  $em->getRepository(AvisUtilisateur::class)
  1056.                             ->findBy(
  1057.                                 array(
  1058.                                     'user' => $user,
  1059.                                     'boutique' => $boutique,
  1060.                                     'valeurAvis' => 5
  1061.                                 )
  1062.                             );
  1063.                             
  1064.         $uneEtoiles['nombre'] = count($uneEtoile);
  1065.         $deuxEtoiles['nombre'] = count($deuxEtoile);
  1066.         $troisEtoiles['nombre'] = count($troisEtoile);
  1067.         $quatreEtoiles['nombre'] = count($quatreEtoile);
  1068.         $cinqEtoiles['nombre'] = count($cinqEtoile);
  1069.         
  1070.         if($nombreAvis 0){
  1071.             $uneEtoiles['moyenne'] = count($uneEtoile ) * 100 /$nombreAvis;
  1072.             $deuxEtoiles['moyenne'] = count($deuxEtoile ) * 100 /$nombreAvis;
  1073.             $troisEtoiles['moyenne'] = count($troisEtoile ) * 100 /$nombreAvis;
  1074.             $quatreEtoiles['moyenne'] = count($quatreEtoile ) * 100 /$nombreAvis;
  1075.             $cinqEtoiles['moyenne'] = count($cinqEtoile ) * 100 /$nombreAvis;
  1076.         }
  1077.         
  1078.         $dejaEnregistre false;
  1079.         if(null != $user){
  1080.             $entrepriseEnregistres $em->getRepository(EntrepriseEnregistre::class)
  1081.                                     ->findBy(
  1082.                                         array(
  1083.                                         'boutique' => $boutique->getId(),
  1084.                                         'user' => $user->getId()
  1085.                                         )
  1086.                                     );
  1087.             
  1088.             
  1089.             foreach($entrepriseEnregistres as $entrepriseEnregistre){
  1090.                 if($entrepriseEnregistre->getBoutique()->getId() == $boutique->getId()){
  1091.                     $dejaEnregistre true;
  1092.                 }
  1093.             }
  1094.         }
  1095.         
  1096.         return $this->render('entreprise/afficher_entreprise.html.twig', [
  1097.           'boutique' => $boutique,
  1098.           'produits' => $produits,
  1099.           'nombreEntreprise' => $nombreEntreprise,
  1100.           'avisUtilisateurs' => $avisUtilisateurs,
  1101.           'cestMaBoutique' => $cestMaBoutique,
  1102.           'nombreAvis' => $nombreAvis,
  1103.           'uneEtoiles' => $uneEtoiles,
  1104.           'deuxEtoiles' => $deuxEtoiles,
  1105.           'troisEtoiles' => $troisEtoiles,
  1106.           'quatreEtoiles' => $quatreEtoiles,
  1107.           'cinqEtoiles' => $cinqEtoiles,
  1108.           'dejaEnregistre' => $dejaEnregistre
  1109.         ]);
  1110.     }
  1111.     
  1112.     /**
  1113.      * @Route("/save-entreprise/{slug}", name="save_entreprise")
  1114.      * @return \Symfony\Component\HttpFoundation\Response
  1115.      */
  1116.     public function saveEntrepriseAction(Request $requestBoutique $boutique)
  1117.     {
  1118.         if(!$this->isGranted('IS_AUTHENTICATED_FULLY')){
  1119.            return $this->redirectToRoute('security_login');
  1120.         }
  1121.         $em $this->getDoctrine()
  1122.                     ->getManager();
  1123.         
  1124.     
  1125.         $user $this->getUser();
  1126.         $entrepriseEnregistres $em->getRepository(EntrepriseEnregistre::class)
  1127.                                 ->findBy(
  1128.                                     array(
  1129.                                     'boutique' => $boutique->getId(),
  1130.                                     'user' => $user->getId()
  1131.                                     )
  1132.                                 );
  1133.         $dejaEnregistre false;
  1134.         foreach($entrepriseEnregistres as $entrepriseEnregistre){
  1135.             if($entrepriseEnregistre->getBoutique()->getId() == $boutique->getId()){
  1136.                 $dejaEnregistre true;
  1137.             }
  1138.         }
  1139.         
  1140.         if($dejaEnregistre == false){
  1141.             $eenr = new EntrepriseEnregistre;
  1142.             
  1143.             $eenr->setBoutique($boutique);
  1144.             $eenr->setUser($user);
  1145.             $em->persist($eenr);
  1146.             $em->flush();
  1147.         }
  1148.         
  1149.         $this->addFlash('success''Enregistrement effectué avec succès');
  1150.         
  1151.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1152.         
  1153.     }
  1154.     
  1155.     /**
  1156.      * @Route("/reclamer-page/{slug}", name="reclamer_page")
  1157.      * @return \Symfony\Component\HttpFoundation\Response
  1158.      */
  1159.     public function reclamerPageAction(Request $requestBoutique $boutique)
  1160.     {
  1161.         $em $this->getDoctrine()
  1162.                     ->getManager();
  1163.         $user $this->getUser();
  1164.         $error '';
  1165.         
  1166.         if($user == null){
  1167.             return $this->redirectToRoute('security_login');
  1168.         }
  1169.         
  1170.         $reclamerPage = new ReclamerPage;
  1171.         $reclamerPage->setBoutique($boutique);
  1172.         $reclamerPage->setEtat('En attente');
  1173.         $reclamerPage->setUser($user);
  1174.         $em->persist($reclamerPage);
  1175.         $em->flush();
  1176.         $this->addFlash('success''Enregistrement effectué');
  1177.         $userBoutiques $em->getRepository(UserBoutique::class)
  1178.                                         ->findBy(
  1179.                                             array(
  1180.                                             'boutique' => $boutique
  1181.                                             )
  1182.                                         );
  1183.         foreach($userBoutiques as $userBoutique){
  1184.             $notification = new Notification;
  1185.             $notification->setUser($userBoutique->getUser());
  1186.             $lien =  $this->generateUrl('gestion.messages', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1187.             $notification->setLien($lien);
  1188.             $notification->setTypeNotification('reclammer_page');
  1189.             $notification->setDescription('Quelqu\'un a reclamé votre page ' $userBoutique->getBoutique()->getNom());
  1190.             $em->persist($notification);
  1191.         }
  1192.         
  1193.         $notification = new Notification;
  1194.         $notification->setUser($this->getUser());
  1195.         $lien =  $this->generateUrl('management.claiming_pages');
  1196.         $notification->setLien($lien);
  1197.         $notification->setTypeNotification('reclammer_page_admin');
  1198.         $notification->setDescription('Reclammation de page ');
  1199.         $em->persist($notification);
  1200.         $em->flush();
  1201.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1202.     }
  1203.     
  1204.     /**
  1205.      * @Route("/avis-utile/{id}", name="avis_utile")
  1206.      * @return \Symfony\Component\HttpFoundation\Response
  1207.      */
  1208.     public function avisUtileAction(Request $requestAvisUtilisateur $avisUtilisateur)
  1209.     {
  1210.         $em $this->getDoctrine()
  1211.                     ->getManager();
  1212.         $user $this->getUser();
  1213.         $error '';
  1214.         
  1215.         $avisUtilisateur->setAvisUtile($avisUtilisateur->getAvisUtile() + 1);
  1216.         
  1217.         $em->flush();
  1218.         $this->addFlash('success''Enregistrement effectué');
  1219.         
  1220.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1221.     }
  1222.     
  1223.     /**
  1224.      * @Route("/avis-inutile/{id}", name="avis_inutile")
  1225.      * @return \Symfony\Component\HttpFoundation\Response
  1226.      */
  1227.     public function avisInutileAction(Request $requestAvisUtilisateur $avisUtilisateur)
  1228.     {
  1229.         $em $this->getDoctrine()
  1230.                     ->getManager();
  1231.         $user $this->getUser();
  1232.         $error '';
  1233.         
  1234.         $avisUtilisateur->setAvisInutile($avisUtilisateur->getAvisInutile() + 1);
  1235.         
  1236.         $em->flush();
  1237.         $this->addFlash('success''Enregistrement effectué');
  1238.         
  1239.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1240.     }
  1241.     
  1242.     /**
  1243.      * @Route("/signaler-avis/{id}", name="signaler_avis")
  1244.      * @return \Symfony\Component\HttpFoundation\Response
  1245.      */
  1246.     public function signalerAvisAction(Request $requestAvisUtilisateur $avisUtilisateur)
  1247.     {
  1248.         $em $this->getDoctrine()
  1249.                     ->getManager();
  1250.         $user $this->getUser();
  1251.         $error '';
  1252.         
  1253.         $avisUtilisateur->setSignalerAvis($avisUtilisateur->getSignalerAvis() + 1);
  1254.         
  1255.         $em->flush();
  1256.         $this->addFlash('success''Enregistrement effectué');
  1257.         
  1258.         return $this->redirectToRoute('afficher_entreprise', array('slug' => $avisUtilisateur->getBoutique()->getSlug()));
  1259.     }
  1260.     
  1261.     
  1262.     /**
  1263.      * @Route("/donner-avis/{slug}", name="donner_avis")
  1264.      * @return \Symfony\Component\HttpFoundation\Response
  1265.      */
  1266.     public function donnerAvisAction(Request $requestBoutique $boutique)
  1267.     {
  1268.         $em $this->getDoctrine()
  1269.                     ->getManager();
  1270.     
  1271.         
  1272.         $user $this->getUser();
  1273.         $avisUtilisateur = new AvisUtilisateur;
  1274.         
  1275.         $form $this->createForm(AvisUtilisateurType::class, $avisUtilisateur);
  1276.         
  1277.         if($request->getMethod() == 'POST'){
  1278.             if(null == $user){
  1279.                 return $this->redirectToRoute('security_login');
  1280.             }
  1281.                $form->handleRequest($request);
  1282.                 if($form->isValid()){
  1283.                     $avisUtilisateur->setUser($user);
  1284.                     $avisUtilisateur->setBoutique($boutique);
  1285.                     $em->persist($avisUtilisateur);
  1286.                     $em->flush();
  1287.                     $tousLesAvis $em->getRepository(AvisUtilisateur::class)
  1288.                                         ->findByBoutique($boutique);
  1289.                      $this->addFlash('success''Envoyé avec succès');
  1290.                     
  1291.                     $moyenne 0;
  1292.                     $nb 0;
  1293.                     $note 0;
  1294.                     foreach($tousLesAvis as $avis){
  1295.                         $note += $avis->getValeurAvis();
  1296.                         $nb++;
  1297.                     }
  1298.                     if($nb >0){
  1299.                         $moyenne round($note/$nb1);
  1300.                     }
  1301.                     $boutique->setMoyenneAvis($moyenne);
  1302.                     $em->flush();
  1303.                     $userBoutiques $em->getRepository(UserBoutique::class)
  1304.                                         ->findBy(
  1305.                                             array(
  1306.                                             'boutique' => $boutique
  1307.                                             )
  1308.                                         );
  1309.                     foreach($userBoutiques as $userBoutique){
  1310.                         $notification = new Notification;
  1311.                         $notification->setUser($userBoutique->getUser());
  1312.                         $lien =  $this->generateUrl('gestion.reviews', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1313.                         $notification->setLien($lien);
  1314.                         $notification->setTypeNotification('avis');
  1315.                         $notification->setDescription('Quelqu\'un a laissé un avis sur ' $userBoutique->getBoutique()->getNom());
  1316.         
  1317.                         $em->persist($notification);
  1318.                     }
  1319.                     $em->flush();
  1320.                     return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1321.                 } else {
  1322.                     $error =" Veillez corrigez vos erreurs";
  1323.                 }
  1324.         }
  1325.         
  1326.         
  1327.         return $this->render('entreprise/donner_avis.html.twig', [
  1328.           'form' => $form->createView(),
  1329.           'boutique' => $boutique
  1330.         ]);
  1331.     }
  1332.     
  1333.     
  1334.     /**
  1335.      * @Route("/envoyer-message/{slug}", name="envoyer_message")
  1336.      * @return \Symfony\Component\HttpFoundation\Response
  1337.      */
  1338.     public function envoyerMessageAction(Request $requestBoutique $boutique)
  1339.     {
  1340.         $em $this->getDoctrine()
  1341.                     ->getManager();
  1342.     
  1343.         $user $this->getUser();
  1344.         $message = new Message;
  1345.         $error '';
  1346.         
  1347.         $form $this->createForm(MessageType::class, $message);
  1348.         
  1349.         if($request->getMethod() == 'POST'){
  1350.             if(null == $user){
  1351.                 return $this->redirectToRoute('security_login');
  1352.             }
  1353.                $form->handleRequest($request);
  1354.                 if($form->isValid()){
  1355.                     
  1356.                     $conversation $em->getRepository(Conversation::class)
  1357.                                         ->findOneBy(
  1358.                                             array(
  1359.                                             'boutique' => $boutique,
  1360.                                             'user' => $user
  1361.                                             )
  1362.                                         );
  1363.                     if(null === $conversation){
  1364.                         $conversation = new Conversation;
  1365.                         $conversation->setUser($user);
  1366.                         $conversation->setBoutique($boutique);
  1367.                         $em->persist($conversation);
  1368.                         
  1369.                         $em->flush();
  1370.                     }
  1371.                     
  1372.                     $message->setUser($user);
  1373.                     $message->setConversation($conversation);
  1374.                     $em->persist($message);
  1375.                     $conversation->setLastMessage($message->getContenu());
  1376.                     $em->flush();
  1377.                     $this->addFlash('success''Envoyé avec succès');
  1378.                     
  1379.                     $userBoutiques $em->getRepository(UserBoutique::class)
  1380.                                         ->findBy(
  1381.                                             array(
  1382.                                             'boutique' => $boutique
  1383.                                             )
  1384.                                         );
  1385.                     foreach($userBoutiques as $userBoutique){
  1386.                         $notification = new Notification;
  1387.                         $notification->setUser($userBoutique->getUser());
  1388.                         $lien =  $this->generateUrl('gestion.messages', array('slug' => $userBoutique->getBoutique()->getSlug()));
  1389.                         $notification->setExtraData($conversation->getId());
  1390.                         $notification->setLien($lien);
  1391.                         $notification->setTypeNotification('message');
  1392.                         $notification->setDescription('Quelqu\'un vous a envoyé un message sur ' $userBoutique->getBoutique()->getNom());
  1393.         
  1394.                         $em->persist($notification);
  1395.                     }
  1396.                     
  1397.                     $em->flush();
  1398.                     
  1399.                     
  1400.                     return $this->redirectToRoute('afficher_entreprise', array('slug' => $boutique->getSlug()));
  1401.                 } else {
  1402.                     $error =" Veillez corrigez vos erreurs";
  1403.                 }
  1404.         }
  1405.         
  1406.         
  1407.         return $this->render('entreprise/envoyer_message.html.twig', [
  1408.           'form' => $form->createView(),
  1409.           'boutique' => $boutique,
  1410.           'error'  => $error
  1411.         ]);
  1412.     }
  1413.     
  1414.     
  1415.     
  1416.     
  1417.     
  1418.     /**
  1419.      * @Route("/payment", name="payment")
  1420.      * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  1421.      * @return \Symfony\Component\HttpFoundation\Response
  1422.      */
  1423.     public function paymentAction(Request $request)
  1424.     {
  1425.         $em $this->getDoctrine()
  1426.                     ->getManager();
  1427.         $boutique $this->session->get('boutique');
  1428.         $plan $this->session->get('plan');
  1429.         $montant 12;
  1430.         $montant *= $plan->getTarif();
  1431.         
  1432.         $coupon =  $this->session->get('coupon');
  1433.         $remise =  $this->session->get('remise');
  1434.         $mt =  $this->session->get('mt');
  1435.         $total $plan->getTarif() * 12;
  1436.         if($coupon == 'ABOMOLIE'){
  1437.             $tt $total;
  1438.             $laRemise 0;
  1439.             switch($total){
  1440.                 case 120:
  1441.                     $laRemise = (0.2 $total);
  1442.                     $tt $total $laRemise;
  1443.                 break;
  1444.                         
  1445.                 case 300:
  1446.                     $laRemise = (0.3 $total);
  1447.                     $tt $total $laRemise
  1448.                 break;
  1449.                         
  1450.                 case 1188:
  1451.                     $laRemise = (0.4 $total);
  1452.                     $tt $total $laRemise
  1453.                             
  1454.                 break;
  1455.             }
  1456.             
  1457.             $montant $tt;
  1458.         }
  1459.         
  1460.         $redirectUrl $this->generateUrl('save_payment');
  1461.         return $this->render('entreprise/payment.html.twig', [
  1462.            'montant' => $montant
  1463.            'redirectUrl' => $redirectUrl
  1464.         ]);
  1465.     }
  1466.     
  1467.     /**
  1468.      * @Route("/save_payment", name="save_payment")
  1469.      * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  1470.      * @return \Symfony\Component\HttpFoundation\Response
  1471.      * 
  1472.      * Faire très attention à cette fonction, car elle doit influencer aussi tous les achats venant
  1473.      * de AppSumo et autre
  1474.      */
  1475.     public function savePaymentAction(Request $request)
  1476.     {
  1477.         $em $this->getDoctrine()
  1478.                     ->getManager();
  1479.         $plan $this->session->get('plan');
  1480.         $plan $em->getRepository(Plan::class)
  1481.                     ->findOneById($plan->getId());
  1482.         $boutique $this->session->get('boutique');
  1483.         $user $this->getUser();
  1484.         $em->persist($boutique);
  1485.         $em->flush();
  1486.         $validiteService = new ValiditeService;
  1487.         $today = new \DateTime();
  1488.         $today->modify('+1 year');
  1489.         $validiteService->setTypeValidite(ValiditeService::TYPE_PAYE);
  1490.         
  1491.         
  1492.         $service = new Service;
  1493.         $service->setUser($user);
  1494.         $service->setPlan($plan);
  1495.         $service->setBoutique($boutique);
  1496.         $em->persist($service);
  1497.         $em->flush();
  1498.         
  1499.         $em->persist($validiteService);
  1500.         $validiteService->setService($service);
  1501.         $validiteService->setValableJusquAu($today);
  1502.         $validiteService->setMontantAbonnement($plan->getTarif() * 12);
  1503.         
  1504.     
  1505.         $tva = new TVA;
  1506.         $tva->setValeur(20);
  1507.         $tva->setLibelle('20%');
  1508.         $tva->setBoutique($boutique);
  1509.         $em->persist($tva);
  1510.         $userBoutique = new UserBoutique;
  1511.         $userBoutique->setUser($user);
  1512.         $userBoutique->setBoutique($boutique);
  1513.         $userBoutique->setRole(RoleBoutique::ADMIN);
  1514.         $em->persist($userBoutique);
  1515.         $em->flush();
  1516.         
  1517.         
  1518.         $paymentMethod 'PayPal';
  1519.         //Générer facture pour le client
  1520.         
  1521.         $pdf = new Html2Pdf('P''A4''en');
  1522.         $user $this->getUser();
  1523.         
  1524.         $content $this->renderView('pdf/facture_client.html.twig', [
  1525.                 'boutique' => $boutique,
  1526.                 'user' => $user,
  1527.                 'plan' => $plan,
  1528.                 'validiteService' => $validiteService,
  1529.                 'paymentMethod' => $paymentMethod,
  1530.                 'domaine' => $this->getDomain()
  1531.             ]);
  1532.         $pdf->writeHTML($content);
  1533.         $name time().$boutique->getId().rand(110000).'.pdf';
  1534.         $lienPhysique __DIR__.'/../../public/my-invoices/'.$name;
  1535.     
  1536.         $validiteService->setLienFacture($this->getDomain().'/my-invoices/'.$name);
  1537.         $pdf->output($lienPhysique'F');
  1538.         
  1539.         $em->flush();
  1540.         $this->session->set('boutique''');
  1541.         $this->session->set('plan''');
  1542.         return $this->redirectToRoute('admin.show_shop', array('slug' => $boutique->getSlug()));
  1543.     
  1544.     }
  1545.     
  1546.     /**
  1547.      * @Route("/choose-paied-plan", name="choose_paied_plan")
  1548.      * @return \Symfony\Component\HttpFoundation\Response
  1549.      */
  1550.     public function choosePaiedPlanAction(Request $request)
  1551.     {
  1552.         $em $this->getDoctrine()
  1553.                     ->getManager();
  1554.         $plans $em->getRepository(Plan::class)
  1555.                     ->paidPlan();
  1556.                     
  1557.         return $this->render('entreprise/choose_paied_plan.html.twig', [
  1558.             'plans' => $plans
  1559.         ]);
  1560.     }
  1561.     
  1562.     /**
  1563.      * @Route("/pricing", name="pricing")
  1564.      * @return \Symfony\Component\HttpFoundation\Response
  1565.      */
  1566.     public function pricingAction(Request $request)
  1567.     {
  1568.         $em $this->getDoctrine()
  1569.                     ->getManager();
  1570.                     
  1571.         $plans $em->getRepository(Plan::class)
  1572.                     ->paidPlan();
  1573.                     
  1574.         return $this->render('entreprise/pricing.html.twig', [
  1575.             'plans' => $plans
  1576.         ]);
  1577.     }
  1578.     
  1579.     /**
  1580.      * @Route("/sfc", name="cgv")
  1581.      * @return \Symfony\Component\HttpFoundation\Response
  1582.      */
  1583.     public function sfcAction(Request $request)
  1584.     {
  1585.         $locale $request->getLocale();
  1586.         
  1587.         return $this->render('entreprise/'.$locale.'_sfc.html.twig', [
  1588.         'locale' => $locale
  1589.         ]);
  1590.     }
  1591.     
  1592.     
  1593.     /**
  1594.      * @Route("/chose-plan", name="chose_plan")
  1595.      * @return \Symfony\Component\HttpFoundation\Response
  1596.      */
  1597.     public function chosePlanAction(Request $request)
  1598.     {
  1599.         return $this->render('entreprise/chose_plan.html.twig', [
  1600.         ]);
  1601.     }
  1602.     
  1603.     
  1604.     /**
  1605.      * @Route("/{slug}/renouveller-abonnement", name="renouveller_abonnement")
  1606.      * @return \Symfony\Component\HttpFoundation\Response
  1607.      */
  1608.     public function renouvellerAbonnementAction(Request $requestBoutique $boutique)
  1609.     {
  1610.               
  1611.         $em $this->getDoctrine()
  1612.                     ->getManager();
  1613.         $derniereValiditeService =  $em->getRepository(ValiditeService::class)
  1614.                         ->derniereValiditeService($boutique->getId());
  1615.         
  1616.         $service $derniereValiditeService->getService();
  1617.         $planActuel $service->getPlan();
  1618.         
  1619.         $plans $em->getRepository(Plan::class)
  1620.                     ->paidPlan();
  1621.         $totalAchat 12;
  1622.         $prix $planActuel->getTarif();
  1623.         
  1624.         if($prix <= 0){
  1625.             $prix 10;
  1626.             foreach($plans as $plan){
  1627.                 if($plan->getTarif() == 10){
  1628.                     $planActuel $plan;
  1629.                 }
  1630.             }
  1631.         } else{
  1632.             
  1633.         }
  1634.         
  1635.         $totalAchat *= $prix;
  1636.         $redirectUrl $this->generateUrl('enregistrer_renouvellement_abonnement', array('slug' => $boutique->getSlug()));
  1637.         
  1638.         return $this->render('entreprise/renouveller_abonnement.html.twig', [
  1639.            'boutique' => $boutique,
  1640.            'plans' => $plans,
  1641.            'redirectUrl' => $redirectUrl,
  1642.            'planActuel' => $planActuel,
  1643.            'totalAchat' => $totalAchat,
  1644.            'prix' => $prix
  1645.         ]);
  1646.     }
  1647.     
  1648.     /**
  1649.      * @Route("/{slug}/enregistrer-renouvellement-abonnement/{plan}", name="enregistrer_renouvellement_abonnement")
  1650.      * @return \Symfony\Component\HttpFoundation\Response
  1651.      */
  1652.     public function enregistrerRenouvellementAbonnementAction(Request $request,  $slug$plan 0)
  1653.     {
  1654.               
  1655.         $em $this->getDoctrine()
  1656.                     ->getManager();
  1657.         
  1658.         $derniereValiditeService =  $em->getRepository(ValiditeService::class)
  1659.                         ->derniereValiditeService($boutique->getId());
  1660.         
  1661.         $boutique $em->getRepository(Boutique::class)
  1662.                         ->findOneBySlug($slug);
  1663.         
  1664.         $service $derniereValiditeService->getService();
  1665.         
  1666.         $plans $em->getRepository(Plan::class)
  1667.                     ->paidPlan();
  1668.         $plan $em->getRepository(Plan::class)
  1669.                         ->findOneById($plan);
  1670.                             
  1671.             if($service->getPlan()->getTarif() == || $service->getPlan()->getId() != $plan->getId()){
  1672.                 $service = new Service;
  1673.                 $service->setUser($user);
  1674.                 $service->setPlan($plan);
  1675.                 $service->setBoutique($boutique);
  1676.                 $em->persist($service);
  1677.                 $em->flush();
  1678.             } else{
  1679.                 
  1680.             }
  1681.             
  1682.             $validiteService = new ValiditeService;
  1683.             $today = new \DateTime();
  1684.             $today->modify('+1 year');
  1685.             $validiteService->setTypeValidite(ValiditeService::TYPE_PAYE);
  1686.         
  1687.             $em->persist($validiteService);
  1688.             $validiteService->setService($service);
  1689.             $validiteService->setValableJusquAu($today);
  1690.             $validiteService->setMontantAbonnement($plan->getTarif() * 12);
  1691.         
  1692.         
  1693.             $paymentMethod 'PayPal';
  1694.             //Générer facture pour le client
  1695.             
  1696.             $pdf = new Html2Pdf('P''A4''en');
  1697.             $user $this->getUser();
  1698.             
  1699.             $content $this->renderView('pdf/facture_client.html.twig', [
  1700.                     'boutique' => $boutique,
  1701.                     'user' => $user,
  1702.                     'plan' => $plan,
  1703.                     'validiteService' => $validiteService,
  1704.                     'paymentMethod' => $paymentMethod,
  1705.                     'domaine' => $this->getDomain()
  1706.                 ]);
  1707.             $pdf->writeHTML($content);
  1708.             $name time().$boutique->getId().rand(110000).'.pdf';
  1709.             $lienPhysique __DIR__.'/../../public/my-invoices/'.$name;
  1710.         
  1711.             $validiteService->setLienFacture($this->getDomain().'/my-invoices/'.$name);
  1712.             $pdf->output($lienPhysique'F');
  1713.             
  1714.             $em->flush();
  1715.             return $this->redirectToRoute('admin.show_shop', array('slug' => $boutique->getSlug()));
  1716.     }
  1717.     
  1718.     /**
  1719.      * @Route("/display-product/{slug}", name="display_product")
  1720.      * @return \Symfony\Component\HttpFoundation\Response
  1721.      */
  1722.     public function displayProductAction(Request $request,  Produit $produit)
  1723.     {
  1724.               
  1725.         $em $this->getDoctrine()
  1726.                     ->getManager();
  1727.         
  1728.         return $this->render('entreprise/display_product.html.twig', [
  1729.            'produit' => $produit
  1730.         ]);
  1731.         
  1732.     }
  1733.     
  1734.     /**
  1735.      * @Route("/notification-to-join-team/{email}", name="notification_requette_ajout_boutique")
  1736.      * @return \Symfony\Component\HttpFoundation\Response
  1737.      */
  1738.     public function notificationRequetteAjoutBoutiqueAction(Request $request,  $email)
  1739.     {
  1740.               
  1741.         $em $this->getDoctrine()
  1742.                     ->getManager();
  1743.         
  1744.             
  1745.         $requeteBoutiques $em->getRepository(RequeteAjoutBoutique::class)
  1746.                         ->findBy(
  1747.                             array(
  1748.                                 'email' => $email
  1749.                             )
  1750.                             );
  1751.         $nbRequete count($requeteBoutiques);
  1752.         
  1753.         return $this->render('entreprise/notification_requette_ajout_boutique.html.twig', [
  1754.            'nbRequete' => $nbRequete
  1755.         ]);
  1756.         
  1757.     }
  1758.     
  1759.     /**
  1760.      * @Route("/notification/{id}", name="nouvelles_notifications")
  1761.      * @return \Symfony\Component\HttpFoundation\Response
  1762.      */
  1763.     public function nouvellesNotificationsAction(Request $requestAppUser $user)
  1764.     {  
  1765.         $em $this->getDoctrine()
  1766.                     ->getManager();
  1767.         
  1768.             
  1769.         $notifications $em->getRepository(Notification::class)
  1770.                         ->findBy(
  1771.                             array(
  1772.                                 'user' => $user,
  1773.                                 'vu' => false
  1774.                             )
  1775.                             );
  1776.         $nombreNotification count($notifications);
  1777.         
  1778.         return $this->render('entreprise/nouvelles_notifications.html.twig', [
  1779.            'nombreNotification' => $nombreNotification,
  1780.            'notifications' => $notifications
  1781.         ]);
  1782.         
  1783.     }
  1784.     
  1785.     /**
  1786.      * @Route("/request-to-join-team/{email}", name="afficher_requette_ajout_boutique")
  1787.      * @return \Symfony\Component\HttpFoundation\Response
  1788.      */
  1789.     public function afficherRequetteAjoutBoutiqueAction(Request $request,  $email)
  1790.     {
  1791.               
  1792.         $em $this->getDoctrine()
  1793.                     ->getManager();
  1794.             
  1795.         $requeteBoutiques $em->getRepository(RequeteAjoutBoutique::class)
  1796.                         ->findByEmail($email);
  1797.                         
  1798.         foreach($requeteBoutiques as $requeteBoutique){
  1799.             $requeteBoutique->setVu(true);
  1800.         }
  1801.         
  1802.         $em->flush();
  1803.         
  1804.         return $this->render('entreprise/afficher_requette_ajout_boutique.html.twig', [
  1805.            'requeteBoutiques' => $requeteBoutiques
  1806.         ]);
  1807.         
  1808.     }
  1809.     
  1810.     /**
  1811.      * @Route("/respond-request-to-join-team/{id}/{status}", name="repondre_requette_ajout_boutique")
  1812.      * @return \Symfony\Component\HttpFoundation\Response
  1813.      */
  1814.     public function repondreRequetteAjoutBoutiqueAction(Request $request,  $id$status)
  1815.     {
  1816.               
  1817.         $em $this->getDoctrine()
  1818.                     ->getManager();
  1819.             
  1820.         $requeteAjout $em->getRepository(RequeteAjoutBoutique::class)
  1821.                         ->findOneById($id);
  1822.         $user $this->getUser();    
  1823.         if($status){
  1824.             $userBoutique $em->getRepository(UserBoutique::class)
  1825.                                 ->findOneBy(
  1826.                                     array(
  1827.                                         'user' => $user->getId(),
  1828.                                         'boutique' => $requeteAjout->getBoutique()->getId()
  1829.                                     )
  1830.                                 );
  1831.             if(null === $userBoutique){
  1832.                 $userBoutique = new UserBoutique;
  1833.                 $userBoutique->setUser($user);
  1834.                 $userBoutique->setBoutique($requeteAjout->getBoutique());
  1835.                 $userBoutique->setRole($requeteAjout->getRole());
  1836.                 $em->persist($userBoutique);
  1837.             }
  1838.         } 
  1839.         $em->remove($requeteAjout);
  1840.         $em->flush();
  1841.         
  1842.         return $this->redirectToRoute('home');
  1843.         
  1844.     }
  1845.     
  1846.     public function getDomain()
  1847.     {
  1848.         $domaine $_SERVER['HTTP_HOST'];
  1849.         $protocol '';
  1850.         if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'){
  1851.             $protocol 'https://';
  1852.         } else{
  1853.             $protocol 'http://';
  1854.         }
  1855.         
  1856.         return $protocol.$domaine;
  1857.     }
  1858.     
  1859. }