<?php
namespace App\Controller;
use App\Entity\Business;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\AdminService;
class HomeController extends AbstractController
{
private $as;
public function __construct(AdminService $as)
{
$this->as = $as;
}
#[Route(path: '/', name: 'home')]
public function index(): Response
{
$business = $this->getDoctrine()->getRepository(Business::class)->findAllWhereNotDeleted();
$goodOne = [];
foreach ($business as $key => $value) {
if ($this->as->hasAccess($value, $this->getUser(), 'business.list')) {
array_push($goodOne, $value);
}
}
if ($this->isGranted('ROLE_SUB_USER')) {
$businessId = $goodOne[0]->getId();
return $this->redirectToRoute('business_home', ['id' => $businessId]);
}
return $this->render('index.html.twig', [
'page_title' => 'Delyss-menu | Accueil',
'business' => $goodOne
]);
}
}