src/Controller/General/Template/MenuController.php line 156

Open in your IDE?
  1. <?php
  2. /*(c) Noel Kenfack <noel.kenfack@yahoo.fr>
  3. */
  4. namespace App\Controller\General\Template;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use App\Entity\General\Template\Recherche;
  8. use App\Form\Produit\Service\MessageType;
  9. use App\Entity\Produit\Service\Message;
  10. use App\Entity\Users\User\User;
  11. use App\Entity\Users\User\Notification;
  12. use App\Service\Servicetext\GeneralServicetext;
  13. use App\Entity\Produit\Produit\Categorie;
  14. use App\Entity\Produit\Service\Typearticle;
  15. use App\Entity\Produit\Produit\Panier;
  16. use App\Entity\Users\User\Imgprofil;
  17. use App\Entity\Produit\Produit\Collectionproduit;
  18. use App\Entity\Produit\Produit\Produit;
  19. use App\Entity\Produit\Produit\Caracteristique;
  20. use App\Entity\Produit\Produit\Produitpanier;
  21. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  22. use App\Service\Email\Singleemail;
  23. use App\Security\TokenAuthenticator;
  24. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  25. use Symfony\Component\HttpFoundation\Request;
  26. class MenuController extends AbstractController
  27. {
  28. private $params;
  29. private $_servicemail;
  30. private $authenticator;
  31. private $guardHandler;
  32. public function __construct(ParameterBagInterface $paramsSingleemail $servicemailTokenAuthenticator $authenticatorGuardAuthenticatorHandler $guardHandler)
  33. {
  34.     $this->params $params;
  35.     $this->_servicemail $servicemail;
  36.     $this->authenticator $authenticator;
  37.     $this->guardHandler $guardHandler;
  38. }
  39. public function menubare(GeneralServicetext $serviceRequest $request$id 0$position 'admin')
  40. {
  41.     $em $this->getDoctrine()->getManager();    
  42.     $liste_categorie $em->getRepository(Categorie::class)
  43.                           ->myFindAll();
  44.     foreach($liste_categorie as $cat)
  45.     {
  46.         $cat->setEm($em);
  47.     }
  48.     $liste_notif $em->getRepository(Notification::class)
  49.                           ->findBy(array('user'=>$this->getUser(),'lut'=>'false'), array('date'=>'desc'));
  50.               
  51.     $liste_interface $em->getRepository(Typearticle::class)
  52.                           ->findBy(array('position'=>'interface'), array('rang'=>'asc'));
  53.     $user null;
  54.     if($id 0)
  55.     {
  56.         $user $em->getRepository(User::class)
  57.                           ->find($id);
  58.     }
  59.     $categorieapp $em->getRepository(Categorie::class)
  60.                           ->findOneBy(array('rang'=>2));
  61.     $solde 0;
  62.     if($this->getUser() != null)
  63.     {
  64.         $solde $service->getSoldeAccount($this->getUser()->getId());    
  65.     }
  66.     $user null;
  67.     if($this->getUser() == null and isset($_COOKIE["PIDSESSREM"]) and $_COOKIE["PIDSESSREM"] != 'delete')
  68.     {
  69.         $cookies $_COOKIE["PIDSESSREM"];
  70.         $username trim($service->decrypt($cookies$this->params->get('saltcookies')));
  71.         if($service->email($username) || $service->telephone($username))
  72.         {
  73.             $repository $em->getRepository(User::class);
  74.             $user $repository->findOneBy(array('username'=>$username));
  75.             if($user != null)
  76.             {
  77.                 $response $this->guardHandler->authenticateUserAndHandleSuccess(
  78.                     $user,          // the User object you just created
  79.                     $request,
  80.                     $this->authenticator// authenticator whose onAuthenticationSuccess you want to use
  81.                     'main'          // the name of your firewall in security.yaml
  82.                 );
  83.             }
  84.         }
  85.     }
  86.     return $this->render('Theme/General/Template/Menu/menubare.html.twig',
  87.     array('liste_categorie'=>$liste_categorie,'position'=>$position,'liste_notif'=>$liste_notif,
  88.     'liste_interface'=>$liste_interface'user'=>$user'solde'=>$solde'categorieapp'=>$categorieapp));
  89. }
  90. public function menubareleft(User $userGeneralServicetext $service$position 'admin')
  91. {
  92.     $em $this->getDoctrine()->getManager();
  93.     $liste_categorie $em->getRepository(Categorie::class)
  94.                           ->myFindAll();
  95.     $nbprod 0;
  96.     $produitpanier null;
  97.     if($this->getUser() != null)
  98.     {
  99.         $panier $em->getRepository(Panier::class)
  100.                      ->findOneBy(array('user'=>$this->getUser(),'payer'=>0));
  101.         if($panier != null)
  102.         {
  103.             $produitpanier $panier->getProduitpaniers();
  104.             foreach($produitpanier as $prodpan)
  105.             {
  106.                 $nbprod $nbprod $prodpan->getQuantite();
  107.             }
  108.         }
  109.     }
  110.     $solde $service->getSoldeAccount($user->getId());            
  111.     $profiluser $em->getRepository(Imgprofil::class)
  112.                         ->findOneBy(array('user'=>$user));
  113.                         
  114.     return $this->render('Theme/General/Template/Menu/menubareleft.html.twig',
  115.     array('liste_categorie'=>$liste_categorie,'nbprod'=>$nbprod,'produitpanier'=>$produitpanier,
  116.     'user'=>$user,'profiluser'=>$profiluser,'solde'=>$solde,'position'=>$position));
  117. }
  118. public function menuright(User $user)
  119. {
  120.     return $this->render('Theme/General/Template/Menu/menuright.html.twig',
  121.     array('user'=>$user));
  122. }
  123. public function menuleft(User $user)
  124. {
  125.     return $this->render('Theme/General/Template/Menu/menuleft.html.twig',
  126.     array('user'=>$user));
  127. }
  128. public function menubareright()
  129. {
  130.     $em $this->getDoctrine()->getManager();
  131.     $mess = new Message();
  132.     if($this->getUser() != null)
  133.     {
  134.         $id $this->getUser()->getId();
  135.     }else{
  136.         $id 0;
  137.     }
  138.     $liste_message $em->getRepository(Message::class)
  139.                           ->myfindmessvalide($id);
  140.     $form $this->createForm(new MessageType$mess);
  141.     return $this->render('Theme/General/Template/Menu/menubareright.html.twig'
  142.     array('form'=>$form->createView(),'liste_message'=>$liste_message));
  143. }
  144. public function footer($position 'admin')
  145. {
  146.     $em $this->getDoctrine()->getManager();
  147.     $mess = new Message();
  148.     $form $this->createForm(MessageType::class, $mess);
  149.     
  150.     $liste_categorie $em->getRepository(Categorie::class)
  151.                           ->myFindAll();
  152.     foreach($liste_categorie as $cat)
  153.     {
  154.         $cat->setEm($em);
  155.     }
  156.     return $this->render('Theme/General/Template/Menu/footer.html.twig',
  157.     array('form'=>$form->createView(),'position'=>$position'liste_categorie'=>$liste_categorie));
  158. }
  159. public function takeaction(GeneralServicetext $service)
  160. {
  161.     
  162.     $session $this->get('session');
  163.     $em $this->getDoctrine()->getManager();
  164.     $envoi $session->get('test_takeaction');
  165.     if($envoi !== 100)
  166.     {
  167.         $date1 = new \Datetime();
  168.         $date2 = new \Datetime();
  169.         $datedebut $date1->modify("-1 month")->format('Y-m-d');
  170.         $datefin $date2->modify("+1 month")->format('Y-m-d');
  171.     
  172.         $lastupdate time() - 60*60*24;
  173.         $liste_commande $em->getRepository(Produitpanier::class)
  174.                              ->findCommandeExpireOn($datedebut$datefin$lastupdate);
  175.                              
  176.         $siteweb $this->params->get('siteweb');
  177.         $sitename $this->params->get('sitename');
  178.         $emailadmin $this->params->get('emailadmin');
  179.             
  180.         foreach($liste_commande as $commande)
  181.         {
  182.             $panier $commande->getPanier();
  183.             $date_courante = new \DateTime();
  184.             $date_expire $commande->getExpireon();
  185.             $interval $date_courante->diff($date_expire);
  186.             if($date_courante $date_expire){
  187.                 //Expire dans....
  188.             
  189.                 $produit $commande->getProduit();
  190.                 if($produit->getSouscategorie()->getCategorie()->getRang() == 1)
  191.                 {
  192.                     $titre $panier->getUser()->name(25).', Votre domaine <strong>'.$commande->getDomaine().'</strong> expire dans '.$interval->format('%a').' Jour(s)';
  193.                 }else{
  194.                     $titre $panier->getUser()->name(25).', Votre produit <strong>'.$produit->getNom().'</strong> expire dans '.$interval->format('%a').' Jour(s)';
  195.                 }
  196.                 
  197.             }else{
  198.                 //Expiré il y'a ...
  199.                 $produit $commande->getProduit();
  200.                 if($produit->getSouscategorie()->getCategorie()->getRang() == 1)
  201.                 {
  202.                     $titre $panier->getUser()->name(25).', Votre domaine <strong>'.$commande->getDomaine().'</strong> a expiré il y\'a '.$interval->format('%a').' Jour(s)';
  203.                 }else{
  204.                     $titre $panier->getUser()->name(25).', Votre produit <strong>'.$produit->getNom().'</strong> a expiré il y\'a '.$interval->format('%a').' Jour(s)';
  205.                 }
  206.             }
  207.             if($service->email($panier->getUser()->getUsername()))
  208.             {
  209.                 $siteweb $this->params->get('siteweb');
  210.                 $sitename $this->params->get('sitename');
  211.                 $emailadmin $this->params->get('emailadmin');
  212.                 if($service->email($panier->getUser()->getUsername()))
  213.                 {
  214.                     $response $this->_servicemail->sendNotifEmail(
  215.                         $panier->getUser()->name(40), //Nom du destinataire
  216.                         $panier->getUser()->getUsername(), //Email Destinataire
  217.                         $titre//Objet de l'email
  218.                         $titre//Grand Titre de l'email
  219.                         'Nous vous informons de la date d\'expiration de vos services/produits afin d\'éviter toutes interruption de services. </br>Utilisez le lien ci-dessous pour renouveler votre commande.',  //Contenu de l'email
  220.                         $siteweb.'/user/orders/scat/'.$panier->getUser()->getId().'/'.$produit->getSouscategorie()->getId()  //Lien à suivre
  221.                     );
  222.                 }
  223.             }            
  224.             
  225.             //Notification client.
  226.             $notification = new Notification($service);
  227.             $notification->setUser($panier->getUser());
  228.             $notification->setTitre($titre);
  229.             $notification->setDescription('Nous vous informons de la date d\'expiration de vos services/produits afin d\'éviter toutes interruption de services. </br>Utilisez le lien ci-dessous pour renouveler votre commande.');
  230.             $em->persist($notification);
  231.             
  232.             $commande->setLastupdate(time());
  233.             $em->flush();
  234.         }
  235.         
  236.         $liste_categorie $em->getRepository(Categorie::class)
  237.                           ->myFindAll();
  238.         foreach($liste_categorie as $cat)
  239.         {
  240.             $cat->setEm($em);
  241.             $compt 1;
  242.             foreach($cat->getSouscategories() as $scat)
  243.             {
  244.                 $firstprod $em->getRepository(Produit::class)
  245.                                 ->findOneBy(array('souscategorie'=>$scat), array('newprise'=>'asc'));
  246.                 if($firstprod != null)
  247.                 {
  248.                     $scat->setElement($firstprod);
  249.                 }
  250.             }
  251.         }
  252.         return $this->render('Theme/General/Template/Menu/takeaction.html.twig', array('liste_categorie'=>$liste_categorie));
  253.     }
  254.     return new Response('');
  255. }
  256. public function stopAlerttakeaction()
  257. {
  258.     $session $this->get('session');
  259.     $session->set('test_takeaction',100);
  260.     echo 1;
  261.     exit;
  262. }
  263. public function cardmenu()
  264. {
  265.     $em $this->getDoctrine()->getManager();
  266.     $idcard 0;
  267.     if(isset($_COOKIE["PIDCARD"]) and $_COOKIE["PIDCARD"] != 'empty')
  268.     {
  269.         $idcard $_COOKIE["PIDCARD"];
  270.     }
  271.     
  272.     $liste_prod = new \Doctrine\Common\Collections\ArrayCollection();
  273.     $oldpanier $em->getRepository(Panier::class)
  274.                      ->findOneBy(array('id'=>$idcard,'sousmis'=>0));
  275.     if($oldpanier == null and $this->getUser() != null)
  276.     {
  277.         $oldpanier $em->getRepository(Panier::class)
  278.                         ->findOneBy(array('user'=>$this->getUser(),'sousmis'=>0));
  279.     }
  280.     
  281.     if($oldpanier != null)
  282.     {
  283.         $liste_prod $oldpanier->getProduitpaniers();
  284.     }
  285.     
  286.     //Si le panier lié à cette achine n'a pas d'utilisateur, on l'assicie à l'utilisateur connecté.
  287.     if($oldpanier != null and $oldpanier->getUser() == null and $this->getUser() != null)
  288.     {
  289.         $oldpanier->setUser($this->getUser());
  290.         $em->flush();
  291.     }
  292.     
  293.     return $this->render('Theme/General/Template/Menu/cardmenu.html.twig',
  294.     array('oldpanier'=>$oldpanier,'liste_prod'=>$liste_prod));
  295. }
  296. public function carddashboard(User $user)
  297. {
  298.     $em $this->getDoctrine()->getManager();
  299.     
  300.     $oldrenew $em->getRepository(Collectionproduit::class)
  301.                      ->myfindOneBy($user->getId());
  302.                      
  303.     return $this->render('Theme/General/Template/Menu/carddashboard.html.twig',
  304.     array('user'=>$user'oldrenew'=>$oldrenew));
  305. }
  306. public function showmodalofferts()
  307. {
  308.     $em $this->getDoctrine()->getManager();
  309.     $liste_produit $em->getRepository(Produit::class)
  310.                           ->findBestOffres(20);
  311.     $offres_plan = new \Doctrine\Common\Collections\ArrayCollection();
  312.     $souscategorie null;
  313.     foreach($liste_produit as $prod)
  314.     {
  315.         $souscategorie $prod->getSouscategorie();
  316.         $offres_plan $em->getRepository(Caracteristique::class)
  317.                             ->findBy(array('souscategorie'=>$souscategorie),array('rang'=>'asc'));
  318.         break;
  319.     }
  320.     
  321.     return $this->render('Theme/General/Template/Menu/showmodalofferts.html.twig'
  322.     array('offres_plan'=>$offres_plan'liste_produit'=>$liste_produit));
  323. }
  324. }