src/Controller/ValidationFicheController.php line 152

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Codinsee;
  4. use App\Entity\DepDone;
  5. use App\Repository\ResultResto44Repository;
  6. use App\Entity\ResultResto44;
  7. use App\Repository\DepartementRepository;
  8. use App\Repository\DepDoneRepository;
  9. use App\Repository\RestaurantRepository;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Twig\Environment;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use App\Service\AgentService;
  17. use App\Service\admin\AdminService;
  18. use Symfony\Component\HttpFoundation\RequestStack;
  19. class ValidationFicheController extends AbstractController {
  20.     private $twig;
  21.     private $restoRep;
  22.     private $agentService;
  23.     private $depRepo;
  24.     private $requestStack;
  25.    
  26.     public function __construct(Environment $twig,ResultResto44Repository $repAgentService $agentService,AdminService $adminService
  27.     DepartementRepository $depRepo,RequestStack $requestStack){
  28.        
  29.         $this->twig=$twig;
  30.         $this->restoRep=$rep;
  31.         $this->agentService=$agentService;
  32.         $this->depRepo=$depRepo;
  33.         $this->requestStack $requestStack;
  34.       
  35.       
  36.     }
  37.     /**
  38.      *@Route("/depChoice", name="choice_page", methods={"GET"}) 
  39.      * 
  40.      */
  41.       public function choicePage(){
  42.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  43.         $user $this->getUser();
  44.         $items=$this->depRepo->getDepByUseridRes($user->getId());
  45.         return new Response($this->twig->render('agent/choiceList.html.twig',["items"=>$items]));
  46.       }
  47.     /**
  48.      * @Route("/view/choice", name="view.choice")
  49.      * 
  50.      */
  51.     public function viewChoice(){
  52.         return new Response($this->twig->render('agent/viewChoice.html.twig'));
  53.     }
  54.     /**
  55.      * @Route("/show/carte/{topo}", name="carte.or.list")
  56.      */
  57.     public function carteOrList($topo){
  58.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  59.         $session $this->requestStack->getSession();
  60.         $session->set('topo',$topo);
  61.         return $this->redirectToRoute('fiche_valid_rest',["topo"=>$topo]);
  62.         // if($topo == "carte"){
  63.         //     $session = $this->requestStack->getSession();
  64.         //     $dep=$session->get('dep');
  65.         //     return new Response( $this->twig->render('agent/carte.html.twig',["dep"=>$dep]));
  66.         // }else{
  67.         //     return $this->redirectToRoute('fiche_valid_rest',["topo"=>$topo]);
  68.         // }
  69.     }
  70.     /**
  71.      * @Route("/validation-carte/{codinsee}/{dep}", name="validation-carte-codinsee", methods={"GET"})
  72.      */
  73.     public function serveCarteByCodinsee($codinsee,$dep){
  74.         return new Response
  75.             $this->twig->render('agent/carte.html.twig',["codinsee"=>$codinsee,"dep"=>$dep])
  76.         );
  77.     } 
  78.     /**
  79.      * @Route("/fiche/id/{id}",name="fiche_valid_id_dep", methods={"GET"})
  80.      */
  81.     public function getViewById($id,RestaurantRepository $rep){
  82.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  83.         $session $this->requestStack->getSession();
  84.         $dep=$session->get('dep');
  85.         $codinsee=$session->get('codinsee');
  86.         $items=$rep->getFicheToValidateByIdAndDep($dep,$id);
  87.         // if($dep == "75" || $dep=="06"){
  88.            
  89.         //     $items=$this->agentService->getCodinseeByDep($dep);
  90.         //     //dd($items);
  91.         //     return new Response($this->twig->render("agent/codinsseChoose.html.twig",["items"=>$items]));
  92.         //   }else{
  93.               if(count($items)>0){
  94.                   
  95.                   $user $this->getUser();
  96.                   $deps=$this->depRepo->getDepByUseridRes($user->getId());
  97.                   return new Response($this->twig->render('agent/interfaceDeValidation.html.twig',
  98.                   ['items'=>$items,"deps"=>$deps"depChoiced"=>$dep,"codinsee"=>$codinsee ]));
  99.               }else{
  100.                   return new Response($this->twig->render('agent/validationEnd.html.twig'));
  101.              }
  102.     }
  103.     /**
  104.      * @Route ("/pResto", name="fiche_valid_rest", methods={"GET"})
  105.      * 
  106.      */
  107.     public function firstView(){
  108.         //         INSERT INTO codinsee (dep, codinsee)
  109.         // SELECT DISTINCT dep, codinsee
  110.         // FROM your_table_name
  111.         // WHERE dep = '75';
  112.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  113.         $session $this->requestStack->getSession();
  114.         $dep=$session->get('dep');
  115.         $topo=$session->get('topo');
  116.         $items=$this->agentService->getFicheToValidate($dep);
  117.         $deps=array("75","06","13","33","59","69","67","31","34","38","74","83");
  118.         
  119.         // if(in_array($dep,$deps)){
  120.         $items=$this->agentService->getCodinseeByDep($dep);
  121.             //dd($items);
  122.         return new Response($this->twig->render("agent/codinsseChoose.html.twig",["items"=>$items,"topo"=>$topo]));
  123.         // }else{
  124.         //       if(count($items)>0){
  125.         //           $user = $this->getUser();
  126.         //           $deps=$this->depRepo->getDepByUseridRes($user->getId());
  127.         //           return new Response($this->twig->render('agent/interfaceDeValidation.html.twig',['items'=>$items,"deps"=>$deps, "depChoiced"=>$dep ]));
  128.         //       }else
  129.         //           return new Response($this->twig->render('agent/validationEnd.html.twig'));
  130.         // }
  131.     
  132.     }
  133.     /**
  134.      * @Route("/pResto/specialDep", name="fiche_valid_for_special_rest_modif",methods={"GEt"})
  135.      */
  136.     public function specialDep(){
  137.        
  138.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  139.         $session $this->requestStack->getSession();
  140.         $codinsee=$session->get('codinsee');
  141.         
  142.         $dep=$session->get('dep');
  143.         
  144.         $items=$this->agentService->getFicheFromSpecialDepToValidate($dep,$codinsee);
  145.         if(count($items)>0){
  146.             $user $this->getUser();
  147.                 $deps=$this->depRepo->getDepByUseridRes($user->getId());
  148.                 return new Response($this->twig->render('agent/interfaceDeValidation.html.twig',['items'=>$items,
  149.                 "deps"=>$deps"depChoiced"=>$dep,"codinsee"=>$codinsee ]));
  150.         }else
  151.             return new Response($this->twig->render('agent/validationEnd.html.twig'));
  152.      }
  153.    
  154.     /**
  155.      * @Route ("/", name="home")
  156.      * 
  157.      */
  158.     public function homePage(){
  159.       
  160.        
  161.         if($this->isGranted('ROLE_ADMIN'))
  162.              return $this->redirectToRoute("admin_home");
  163.         else if($this->isGranted('ROLE_USER'))
  164.             return $this->redirectToRoute("choice_page");
  165.         else 
  166.             return $this->redirectToRoute("login");
  167.     }
  168.     /**
  169.      * @Route("/validation/commune/done", name="valid.com.done", methods="POST")
  170.      */
  171.     public function makeComDone(Request $requestDepDoneRepository $repo){
  172.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  173.         $bodyJson=json_decode($request->getContent(),true);
  174.         $depDone=new DepDone();
  175.         $depDone->setDep($bodyJson['dep']);
  176.         $depDone->setDepName($bodyJson["nom_commune"]);
  177.         try{
  178.             $repo->add($depDone,true);
  179.             return $this->json(["message"=>"ok"],200);
  180.         }catch(\Exception $e){
  181.             return $this->json(["message"=>$e],500);
  182.         }
  183.         
  184.     }
  185.     /** *
  186.      * @Route("/validation/get/commune/done/{dep}", name="get.valid.com.done", methods="get")
  187.      */
  188.     public function getCommuneDone($depDepDoneRepository $repo){
  189.         $this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
  190.         $session $this->requestStack->getSession();
  191.         $dep=$session->get('dep');
  192.        
  193.         try{
  194.             $comDone=$repo->getCommDone($dep);
  195.             return $this->json($comDone,200);
  196.         }catch(\Exception $e){
  197.             return $this->json(["message"=>$e],500);
  198.         }
  199.     }
  200.     /**
  201.      * @Route("/admin/home", name="admin_home", methods="GET")
  202.      */
  203.     public function adminHomePage(){
  204.         $this->denyAccessUnlessGranted('ROLE_ADMIN',null,'access denied');
  205.         return new Response($this->twig->render('admin/home.html.twig'));
  206.     }
  207. }