src/Controller/DefaultController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Invoice;
  4. use App\Entity\User;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Doctrine\ORM\EntityRepository;
  11. use App\Entity\Customer;
  12. use App\Entity\OrderProduct;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Symfony\Component\HttpFoundation\Session\Session;
  15. /**
  16.  * Require ROLE_ADMIN for *every* controller method in this class.
  17. *
  18. * @IsGranted("ROLE_USER")
  19. */
  20. class DefaultController extends AbstractController
  21. {
  22.     /**
  23.      * @Route("/", name="homepage")
  24.      *
  25.      */
  26.     public function index(Session $session)
  27.     {
  28.         $session = new Session();
  29.         $locale $this->getUser()->getLocale();
  30.         $session->set('_locale'$locale);
  31.         $url $locale.'/home';
  32.         //return $this->redirectToRoute('home');
  33.         return $this->redirect($url);
  34.     }
  35.     /**
  36.      * @Route(
  37.      *     "/{_locale}/home",
  38.      *     name="home",
  39.      *     requirements={
  40.      *         "_locale": "%app_locales%",
  41.      *     }
  42.      * )
  43.      */
  44.     public function home(Request $requestTranslatorInterface $translator)
  45.     {
  46.         $locale $request->getLocale();
  47.         if ($this->isGranted("ROLE_ADMIN"))
  48.         {
  49.             $i $request->get('form');
  50.             if ($i==1)
  51.             {
  52.                 $dateDeb = new \DateTime($request->get('dateD'));
  53.                 $dateFin = new \DateTime($request->get('dateF'));
  54.                 $dateDeb $dateDeb -> format('Y-m-d');
  55.                 $dateFin $dateFin -> format('Y-m-d');
  56.             }
  57.             else
  58.             {
  59.                 $date = new \DateTime();
  60.                 $dateDeb $date -> format('Y-m-01');
  61.                 $dateFin $date -> format('Y-m-t');
  62.             }
  63.             $stats $this->getDoctrine()->getManager()->getRepository(OrderProduct::class)->statProductOrder($dateDeb$dateFin$this->getUser()->getShopID());
  64.             return $this->render('default/index.html.twig', ['dateD' => $dateDeb'dateF' => $dateFin'stats' => $stats]);
  65.         }
  66.         else
  67.         {
  68.             if ($this->getUser()->getSigned() == false)
  69.             {
  70.                 $this->addFlash('alert''Attention, vous n\'avez pas encore accepté la convention, pour le faire, veuillez cliquer ici
  71.                 
  72. ');
  73.             }
  74.             if ($this->isGranted("ROLE_LOG"))
  75.             {
  76.                 $now = new \DateTime('now');
  77.                 $year $now->format('Y');
  78.                 $invoices $this->getDoctrine()->getManager()->getRepository(Invoice::class)->findAdmin($year);
  79.                 return $this->render('default/index_log.html.twig', ['invoices' => $invoices,]);
  80.             }
  81.             else
  82.             {
  83.                 $customers $this->getDoctrine()->getManager()->getRepository(Customer::class)->customerBoost(array(['user_id' => $this->getUser()]));
  84.                 return $this->render('default/index_user.html.twig', ['customers' => $customers'locale' => $locale]);
  85.             }
  86.         }
  87.     }
  88.     /**
  89.      * @Route("/phpmyadmin", name="phpmyadmin")
  90.      */
  91.     public function phpmyadmin(Request $request)
  92.     {
  93.         return $this->redirect('/dev/phpMyAdmin5/index.php'301);
  94.     }
  95.     /**
  96.      * @Route("/winbooks", name="winbooks")
  97.      */
  98.     public function winbooks(Request $request)
  99.     {
  100.         return $this->redirect('/dev/winbooks/index.php'301);
  101.     }
  102.     
  103. }