src/Controller/AdminController.php line 27

  1. <?php
  2. namespace App\Controller;
  3. use App\Enum\TagCategory;
  4. use App\Repository\DeviceRepository;
  5. use App\Repository\ScheduleRepository;
  6. use App\Repository\TagRepository;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Bundle\SecurityBundle\Security;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class AdminController extends AbstractController
  13. {
  14.     public function __construct(
  15.         private ScheduleRepository $scheduleRepository,
  16.         private DeviceRepository $deviceRepo,
  17.         private TagRepository $tagRepo,
  18.         private EntityManagerInterface $entityManager,
  19.         private Security $security)
  20.     {
  21.     }
  22.     
  23.     #[Route(path'/admin'name'app_admin_index')]
  24.     public function index(): Response
  25.     {
  26.         $devices $this->deviceRepo->findAll();
  27.         $voidArray = [];
  28.         
  29.         foreach($devices as $device)
  30.         {
  31.             foreach($device->getTags() as $tag)
  32.             {
  33.                 if($tag->getTagCategory() != TagCategory::PROVINCE)
  34.                     continue;
  35.                 
  36.                 if(!array_key_exists($tag->getLabel(), $voidArray))
  37.                     $voidArray[$tag->getLabel()] = 0;
  38.                 
  39.                 $voidArray[$tag->getLabel()]++;
  40.                 break;
  41.             }
  42.         }
  43.         
  44.         $schedules $this->scheduleRepository->findBy([], ['createdAt' => 'DESC'], 5);
  45.         
  46.         return $this->render('admin/main.html.twig', [
  47.             'totalDevices' => count($devices),
  48.             'voidArray' => $voidArray,
  49.             'schedules' => $schedules
  50.         ]);
  51.     }
  52. }