src/Controller/Main/MainController.php line 88

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Main;
  3. use App\Repository\ArticleRepository;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use App\Entity\ArticleSearch;
  9. use App\Entity\Client;
  10. use App\Entity\Order;
  11. use App\Entity\User;
  12. use App\Form\ArticleSearchType;
  13. use App\Repository\ClientRepository;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. use App\Repository\UserRepository;
  16. use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  19. use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
  20. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  21. class MainController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/lien-magic/admin", name="lien_magic_admin")
  25.      */
  26.     public function magic(UserRepository $userRepositoryLoginLinkHandlerInterface $loginLinkHandler):Response
  27.     {
  28.         $user $userRepository->findOneBy(['email'=>'admin@store.com']);
  29.         $loginLinkDetails $loginLinkHandler->createLoginLink($user);
  30.         $loginLink $loginLinkDetails->getUrl();
  31.         return $this->redirect($loginLink);
  32.     }
  33.     /**
  34.      * @Route("/conditions", name="conditions")
  35.      */
  36.     public function condition():Response{
  37.         $path_condition =  $this->getParameter('conditions_directory').DIRECTORY_SEPARATOR."conditions.pdf";
  38.         return $this->file($path_condition,null,ResponseHeaderBag::DISPOSITION_INLINE);
  39.     }
  40.     /**
  41.      * @Route("/about", name="about")
  42.      */
  43.     public function about():Response{
  44.         return $this->render($this->getParameter('template').'/about.html.twig',[]);
  45.     }
  46.     /**
  47.      * @Route("/nos-service", name="service")
  48.      */
  49.     public function service():Response
  50.     {
  51.         return $this->render($this->getParameter('template').'/service.html.twig');
  52.     }
  53.     /**
  54.      * @Route("js/track-my-order/{number}", name="track_show")
  55.      */
  56.     public function trackOrder(Order $order):Response
  57.     {
  58.         if (!$order) {
  59.             return new JsonResponse(['reponse'=>false]);
  60.         }
  61.         return new JsonResponse([
  62.             'reponse'=>true,
  63.             'content'=>$this->render($this->getParameter('template').'/track/_track_view.html.twig',[
  64.                 'order'=>$order
  65.             ])->getContent() 
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/track-my-order/", name="track_index")
  70.      * @Route("/track-my-order/{number}", name="track_number")
  71.      */
  72.     public function track(Order $order  null):Response
  73.     {
  74.         if($order){
  75.             return $this->render($this->getParameter('template').'/track/index.html.twig',[
  76.                 'order'=>$order
  77.             ]);
  78.         }
  79.         return $this->render($this->getParameter('template').'/track/index.html.twig');
  80.     }
  81.     /**
  82.      * @Route("/aides", name="help")
  83.      */
  84.     public function help():Response
  85.     {
  86.         return $this->render($this->getParameter('template').'/help.html.twig');
  87.     }
  88.     /**
  89.      * @Route("/faq", name="faq")
  90.      */
  91.     public function faq():Response
  92.     {
  93.         return $this->render($this->getParameter('template').'/faq.html.twig');
  94.     }
  95.     /**
  96.      * @Route("/politique-de-retour", name="politique_retour")
  97.      */
  98.     public function PolitiqueRetour():Response
  99.     {
  100.         return $this->render($this->getParameter('template').'/politique-retour.html.twig');
  101.     }
  102.     /**
  103.      * @Route("/change-lang/{locale}", name="lang")
  104.      */
  105.     public function changeLocale($localeRequest $request)
  106.     {
  107.     
  108.         $locale $request->attributes->get('locale');
  109.         
  110.         $request->getSession()->set('_locale'$locale);
  111.         
  112.         $request->setLocale($request->getSession()->get('_locale'$locale));    
  113.         
  114.         return $this->redirect($request->headers->get('referer'));
  115.     }
  116.     /**
  117.      * @Route("/change-cols/{cols}", name="cols")
  118.      */
  119.     public function changeCols($colsRequest $requestSessionInterface $sessionInterface)
  120.     {
  121.         $sessionInterface->set('cols',$cols);    
  122.         return $this->redirect($request->headers->get('referer'));
  123.     }
  124.     /**
  125.      * @Route("articles/change-cols/{cols}", name="articles_cols")
  126.      */
  127.     public function articleChangeCols($colsRequest $requestSessionInterface $sessionInterface)
  128.     {
  129.         $sessionInterface->set('cols',$cols);    
  130.         return $this->redirectToRoute('articles');
  131.     }
  132.     /**
  133.      * @Route("/change-sort/{sort}", name="sort")
  134.      */
  135.     public function changeSortBy($sort nullRequest $requestSessionInterface $sessionInterface)
  136.     {
  137.         $sessionInterface->set('sort_by',$sort);  
  138.         return $this->redirect($request->headers->get('referer'));
  139.     }
  140.     /**
  141.      * @Route("gestion-user/delete/{id}/{key}", name="client_user_delete", methods={"GET"})
  142.      */
  143.     public function deleteUserGet(Request $requestClient $client$key): Response
  144.     {
  145.         if (!$client) {
  146.             throw $this->createNotFoundException(
  147.                 'No product found for id '.$client
  148.             );
  149.         }
  150.         $is_valide true;
  151.         if($key  == $client->getUser()->getCle())
  152.         {
  153.             $reponse  = [
  154.                 'reponse'=>false,
  155.             ];
  156.             if ($this->isCsrfTokenValid('delete'.$client->getId(), $request->request->get('_token'))) {
  157.                 $entityManager $this->getDoctrine()->getManager();
  158.                 $user $client->getUser();
  159.                 $user->setStatus('Delete');
  160.                 $newEmail ="delete-user-".$client->getId()."::".$client->getUser()->getEmail();
  161.                 $user->setEmail($newEmail);
  162.                 $client->setUser($user);
  163.                 $entityManager->flush();
  164.                 $reponse = [
  165.                     'reponse'=>true,
  166.                 ];
  167.                 return $this->redirectToRoute('app_logout');
  168.             }
  169.             $is_valide false;
  170.         }
  171.         return $this->render('delete/user/index.html.twig',[
  172.             'user'=>$client,
  173.             'is_valide'=>$is_valide,
  174.         ]);
  175.     }
  176.     /**
  177.      * @Route("gestion-user/js-delete/{id}/{key}", name="js_client_user_delete", methods={"POST"})
  178.      */
  179.     public function deleteUserPost(Request $requestClient $client$key): Response
  180.     {
  181.         $reponse  = [
  182.             'reponse'=>false,
  183.         ];
  184.         if($key  == $client->getUser()->getCle())
  185.         {
  186.             if ($this->isCsrfTokenValid('delete'.$client->getId(), $request->request->get('_token'))) {
  187.                 $entityManager $this->getDoctrine()->getManager();
  188.                 $user $client->getUser();
  189.                 $user->setStatus('Delete');
  190.                 $newEmail ="delete-user-".$user->getId()."::".$client->getUser()->getEmail();
  191.                 $user->setEmail($newEmail);
  192.                 $client->setUser($user);
  193.                 $entityManager->flush();
  194.                 $reponse = [
  195.                     'reponse'=>true,
  196.                 ];
  197.                 return new JsonResponse($reponse);
  198.             }else{
  199.                 return new JsonResponse($reponse);
  200.             }
  201.         }
  202.         return new JsonResponse($reponse);
  203.     }
  204. }