src/Controller/HomeController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CompanyRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class HomeController extends AbstractController
  8. {
  9.     /**
  10.      * @Route("", name="home")
  11.      */
  12.     public function index(CompanyRepository $companyRepository): Response
  13.     {
  14.         $user $this->getUser();
  15.         if($user){
  16.             $companies $companyRepository->findAll();
  17.             $valren = array();
  18.             foreach($companies as $company){
  19.                 if($company->getAdministrators()->findUser($user
  20.                 || ($company->getManagers() && $company->getManagers()->findUser($user)) 
  21.                 || ($company->getUsers() && $company->getUsers()->findUser($user))){
  22.                     array_push($valren, array(
  23.                         'company' => $company,
  24.                         'isAdministrator' => $company->getAdministrators()->findUser($user)
  25.                     ));
  26.                 }
  27.             }
  28.             return $this->render('home/index.html.twig', [
  29.                 'companies' => $valren,
  30.             ]);
  31.         }
  32.         return $this->redirectToRoute('app_login',[], Response::HTTP_SEE_OTHER);
  33.     }
  34. }