src/Controller/AdminStatsController.php line 85

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Stats;
  4. use App\Form\StatsType;
  5. use App\Repository\AdminStatsRepository;
  6. use App\Entity\User;
  7. use App\Form\UserType;
  8. use App\Repository\UserRepository;
  9. use App\Entity\Upartistik;
  10. use App\Repository\UpartistikRepository;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  18. /**
  19.  * @Route("/admin/stats")
  20.  */
  21. class AdminStatsController extends AbstractController
  22. {
  23.   /**
  24.   * @var UserRepository
  25.   */
  26.   private $repository;
  27.   private $passwordEncoder;
  28.   public function __construct(AdminStatsRepository $statsRepoUserRepository $repositoryEntityManagerInterface $emUserPasswordEncoderInterface $passwordEncoderUpartistikRepository $upartRepo)
  29.   {
  30.     $this->repository $repository;
  31.     $this->em $em;
  32.     $this->passwordEncoder $passwordEncoder;
  33.     $this->upartRepo $upartRepo;
  34.     $this->statsRepo $statsRepo;
  35.   }
  36.   /**
  37.    * @Route("/", name="stats_index", methods={"GET"})
  38.    */
  39.   public function index(): Response
  40.   {
  41.     $dateDebut = new \DateTime();
  42.     $dateFin = new \DateTime();
  43.     $dateDebut->setTime(000);
  44.     // dump($dateDebut);
  45.     $dateFin->setTime(2400);
  46.     // dump($dateFin);
  47.     $stats $this->statsRepo->findByDate($dateDebut$dateFin);
  48.     $listeIp = [];
  49.     for($i=0$i<count($stats); $i++){
  50.       // recup ip
  51.       $listeIp[] = $stats[$i]->getIp();
  52.     }
  53.     $listeIp array_unique($listeIp);
  54.       return $this->render('admin_stats/index.html.twig', [
  55.         'controller_name' => 'stats_index',
  56.         'upartRepo' => $this->upartRepo->find(1),
  57.           'stats' => $stats,
  58.           'dateDebut' => $dateDebut,
  59.           'dateFin' => $dateFin,
  60.           'listeIp' => $listeIp,
  61.       ]);
  62.   }
  63.   /**
  64.    * @Route("/{jour}/{mois}/{annee}", name="stats_dateJour", methods={"GET"})
  65.    */
  66.   public function stats_dateJour($jour$mois$annee): Response
  67.   {
  68.     $dateDebut = new \DateTime();
  69.     $dateDebut->setDate($annee$mois$jour);
  70.     $dateDebut->setTime(000);
  71.     $dateFin = new \DateTime();
  72.     $dateFin->setDate($annee$mois, ($jour+1));
  73.     $dateFin->setTime(000);
  74.     $stats $this->statsRepo->findByDate($dateDebut$dateFin);
  75.     $listeIp = [];
  76.     for($i=0$i<count($stats); $i++){
  77.       // recup ip
  78.       $listeIp[] = $stats[$i]->getIp();
  79.     }
  80.     $listeIp array_unique($listeIp);
  81.     // dump($dateDebut);
  82.     // dump($dateFin);
  83.     // dump($stats);
  84.     // dump($listeIp);
  85.       return $this->render('admin_stats/index.html.twig', [
  86.         'controller_name' => 'stats_dateJour',
  87.         'upartRepo' => $this->upartRepo->find(1),
  88.           'dateDebut' => $dateDebut,
  89.           'dateFin' => $dateFin,
  90.           'stats' => $stats,
  91.           'listeIp' => $listeIp,
  92.       ]);
  93.   }
  94.     /**
  95.      * @Route("/new", name="stats_new", methods={"GET", "POST"})
  96.      */
  97.     public function new(Request $requestEntityManagerInterface $entityManager): Response
  98.     {
  99.         $stat = new Stats();
  100.         $form $this->createForm(StatsType::class, $stat);
  101.         $form->handleRequest($request);
  102.         if ($form->isSubmitted() && $form->isValid()) {
  103.             $entityManager->persist($stat);
  104.             $entityManager->flush();
  105.             return $this->redirectToRoute('stats_index', [], Response::HTTP_SEE_OTHER);
  106.         }
  107.         return $this->renderForm('admin_stats/new.html.twig', [
  108.           'upartRepo' => $this->upartRepo->find(1),
  109.             'stat' => $stat,
  110.             'form' => $form,
  111.         ]);
  112.     }
  113.     /**
  114.      * @Route("/{id}", name="stats_show", methods={"GET"})
  115.      */
  116.     public function show(Stats $stat): Response
  117.     {
  118.         return $this->render('admin_stats/show.html.twig', [
  119.           'upartRepo' => $this->upartRepo->find(1),
  120.             'stat' => $stat,
  121.         ]);
  122.     }
  123.     /**
  124.      * @Route("/{id}/edit", name="stats_edit", methods={"GET", "POST"})
  125.      */
  126.     public function edit(Request $requestStats $statEntityManagerInterface $entityManager): Response
  127.     {
  128.         $form $this->createForm(StatsType::class, $stat);
  129.         $form->handleRequest($request);
  130.         if ($form->isSubmitted() && $form->isValid()) {
  131.             $entityManager->flush();
  132.             return $this->redirectToRoute('stats_index', [], Response::HTTP_SEE_OTHER);
  133.         }
  134.         return $this->renderForm('admin_stats/edit.html.twig', [
  135.           'upartRepo' => $this->upartRepo->find(1),
  136.             'stat' => $stat,
  137.             'form' => $form,
  138.         ]);
  139.     }
  140.     /**
  141.      * @Route("/{id}", name="stats_delete", methods={"POST"})
  142.      */
  143.     public function delete(Request $requestStats $statEntityManagerInterface $entityManager): Response
  144.     {
  145.         if ($this->isCsrfTokenValid('delete'.$stat->getId(), $request->request->get('_token'))) {
  146.             $entityManager->remove($stat);
  147.             $entityManager->flush();
  148.         }
  149.         return $this->redirectToRoute('stats_index', [], Response::HTTP_SEE_OTHER);
  150.     }
  151. }