src/Controller/HomeController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Business;
  4. use App\Entity\User;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use App\Service\AdminService;
  9. class HomeController extends AbstractController
  10. {
  11.     private $as;
  12.     public function __construct(AdminService $as)
  13.     {
  14.         $this->as $as;
  15.     }
  16.     #[Route(path'/'name'home')]
  17.     public function index(): Response
  18.     {
  19.         $business $this->getDoctrine()->getRepository(Business::class)->findAllWhereNotDeleted();
  20.         $goodOne = [];
  21.         foreach ($business as $key => $value) {
  22.             if ($this->as->hasAccess($value$this->getUser(), 'business.list')) {
  23.                 array_push($goodOne$value);
  24.             }
  25.         }
  26.         if ($this->isGranted('ROLE_SUB_USER')) {
  27.             $businessId $goodOne[0]->getId();
  28.             return $this->redirectToRoute('business_home', ['id' => $businessId]);
  29.         }
  30.         return $this->render('index.html.twig', [
  31.             'page_title' => 'Delyss-menu | Accueil',
  32.             'business' => $goodOne
  33.         ]);
  34.     }
  35. }