<?php
namespace App\Controller;
use App\Repository\ResultResto44Repository;
use App\Entity\ResultResto44;
use App\Repository\DepartementRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Service\AgentService;
use App\Service\admin\AdminService;
use Symfony\Component\HttpFoundation\RequestStack;
class ValidationFicheController extends AbstractController {
private $twig;
private $agentService;
private $depRepo;
private $requestStack;
public function __construct(Environment $twig, AgentService $agentService,
DepartementRepository $depRepo,RequestStack $requestStack){
$this->twig=$twig;
$this->agentService=$agentService;
$this->depRepo=$depRepo;
$this->requestStack = $requestStack;
}
/**
*@Route("/depChoice", name="choice_page", methods={"GET"})
*
*/
public function choicePage(){
$this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
$user = $this->getUser();
$items=$this->depRepo->getDepByUseridRes($user->getId());
return new Response($this->twig->render('agent/choiceList.html.twig',["items"=>$items]));
}
/**
* @Route ("/pResto", name="fiche_valid_rest", methods={"GET"})
*
*/
public function firstView(){
$this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
$session = $this->requestStack->getSession();
$dep=$session->get('dep');
$items=$this->agentService->getFicheToValidate($dep);
$deps=array("75","06","13","33","59","69","67","94");
if(in_array($dep,$deps)){
$items=$this->agentService->getCodinseeByDep($dep);
//dd($items);
return new Response($this->twig->render("agent/codinsseChoose.html.twig",["items"=>$items]));
}else{
if(count($items)>0){
$user = $this->getUser();
$deps=$this->depRepo->getDepByUseridRes($user->getId());
return new Response($this->twig->render('agent/interfaceDeValidation.html.twig',['items'=>$items,"deps"=>$deps, "depChoiced"=>$dep ]));
}else
return new Response($this->twig->render('agent/validationEnd.html.twig'));
}
}
/**
* @Route("/pResto/specialDep", name="fiche_valid_for_special_rest",methods={"GEt"})
*/
public function specialDep(){
$this->denyAccessUnlessGranted('ROLE_USER',null,'access denied');
$session = $this->requestStack->getSession();
$codinsee=$session->get('codinsee');
$dep=$session->get('dep');
$items=$this->agentService->getFicheFromSpecialDepToValidate($dep,$codinsee);
if(count($items)>0){
$user = $this->getUser();
$deps=$this->depRepo->getDepByUseridRes($user->getId());
return new Response($this->twig->render('agent/interfaceDeValidation.html.twig',['items'=>$items,
"deps"=>$deps, "depChoiced"=>$dep,"codinsee"=>$codinsee ]));
}else
return new Response($this->twig->render('agent/validationEnd.html.twig'));
}
/**
* @Route ("/", name="home")
*
*/
public function homePage(){
$hasAccess = $this->isGranted('ROLE_USER');
if($hasAccess)
return $this->redirectToRoute("choice_page");
else
return $this->redirectToRoute("login");
}
}