src/Controller/InfoController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class InfoController extends AbstractController
  7. {
  8.     /**
  9.      * @Route("/info", name="info")
  10.      */
  11.     public function index(): Response
  12.     {
  13.         return $this->render('info/index.html.twig', [
  14.             'controller_name' => 'InfoController',
  15.         ]);
  16.     }
  17.     /**
  18.      * @Route("/users", name="info_users", methods={"GET"})
  19.      */
  20.     public function users(): string
  21.     {
  22.         $em $this->getDoctrine()->getManager();
  23.         //$userRepository = $em->getRepository(\App\Entity\User::class);
  24.         $userRepository $em->getRepository(\App\Entity\User::class);
  25.         $data $userRepository->createQueryBuilder('u')
  26.             ->select('count(u.id)')
  27.             ->getQuery()
  28.             ->getSingleScalarResult();
  29.         return $data;
  30.     }
  31.     /**
  32.      * @Route("/cars", name="info_cars", methods={"GET"})
  33.      */
  34.     public function cars(): string
  35.     {
  36.         $em $this->getDoctrine()->getManager();
  37.         //$userRepository = $em->getRepository(\App\Entity\Car::class);
  38.         $userRepository $em->getRepository(\App\Entity\Car::class);
  39.         $data $userRepository->createQueryBuilder('c')
  40.             ->select('count(c.id)')
  41.             ->where('c.status not in (\'sold\', \'swapped\')')
  42.             ->getQuery()
  43.             ->getSingleScalarResult();
  44.         return $data;
  45.     }
  46.     /**
  47.      * @Route("/brands", name="info_cars", methods={"GET"})
  48.      */
  49.     public function brands(): string
  50.     {
  51.         $em $this->getDoctrine()->getManager();
  52.         //$userRepository = $em->getRepository(\App\Entity\Brand::class);
  53.         $userRepository $em->getRepository(\App\Entity\Brand::class);
  54.         $data $userRepository->createQueryBuilder('b')
  55.             ->select('count(b.id)')
  56.             ->getQuery()
  57.             ->getSingleScalarResult();
  58.         return $data;
  59.     }
  60.     /**
  61.      * @Route("/clients", name="info_clients", methods={"GET"})
  62.      */
  63.     public function clients(): string
  64.     {
  65.         $em $this->getDoctrine()->getManager();
  66.         //$userRepository = $em->getRepository(\App\Entity\Client::class);
  67.         $userRepository $em->getRepository(\App\Entity\Client::class);
  68.         if ($this->getUser()->getRoles()[0] == 'ROLE_ADMIN') {
  69.             $data $userRepository->createQueryBuilder('c')
  70.                 ->select('count(c.id)')
  71.                 ->getQuery()
  72.                 ->getSingleScalarResult();
  73.         } else {
  74.             $data $userRepository->createQueryBuilder('c')
  75.                 ->select('count(c.id)')
  76.                 ->where('c.user = :user')
  77.                 ->setParameter(':user'$this->getUser()->getId())
  78.                 ->getQuery()
  79.                 ->getSingleScalarResult();
  80.         }
  81.         return $data;
  82.     }
  83.     /**
  84.      * @Route("/notifications", name="info_notifications", methods={"GET"})
  85.      */
  86.     public function notifications(): string
  87.     {
  88.         $userId $this->getUser()->getId();
  89.         $em $this->getDoctrine()->getManager();
  90.         $userRepository $em->getRepository(\App\Entity\Client::class);
  91.         if ($this->getUser()->getRoles()[0] == 'ROLE_ADMIN') {
  92.             $data $userRepository->createQueryBuilder('c')
  93.                 ->select('count(c.id)')
  94.                 ->getQuery()
  95.                 ->getSingleScalarResult();
  96.         } else {
  97.             $data $userRepository->createQueryBuilder('c')
  98.                 ->select('count(c.id)')
  99.                 ->where('c.user = :user')
  100.                 ->setParameter(':user'$this->getUser()->getId())
  101.                 ->getQuery()
  102.                 ->getSingleScalarResult();
  103.         }
  104.         return $data;
  105.     }
  106. }