<?php
namespace App\Controller;
use App\Repository\CompanyRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* @Route("", name="home")
*/
public function index(CompanyRepository $companyRepository): Response
{
$user = $this->getUser();
if($user){
$companies = $companyRepository->findAll();
$valren = array();
foreach($companies as $company){
if($company->getAdministrators()->findUser($user)
|| ($company->getManagers() && $company->getManagers()->findUser($user))
|| ($company->getUsers() && $company->getUsers()->findUser($user))){
array_push($valren, array(
'company' => $company,
'isAdministrator' => $company->getAdministrators()->findUser($user)
));
}
}
return $this->render('home/index.html.twig', [
'companies' => $valren,
]);
}
return $this->redirectToRoute('app_login',[], Response::HTTP_SEE_OTHER);
}
}