src/Controller/HomeController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\TrainingsRepository;
  4. use Doctrine\DBAL\Exception;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class HomeController extends AbstractController
  10. {
  11.     #[Route('/'name'home')]
  12.     public function home(TrainingsRepository $fichesRepository): Response
  13.     {
  14.         if($this->getUser()){
  15.             $roles $this->getUser()->getRoles();
  16.             if (in_array('ROLE_SUPER_ADMIN'$roles)) {
  17.                 return $this->render('admin/admin.html.twig');
  18.             } elseif (in_array('ROLE_COMMERCIAL'$roles)) {
  19.                 return $this->render('commercial/commercial.html.twig', [
  20.                     'fiches' => $fichesRepository->findBy(['owner' => $this->getUser(), 'isFiche' => true], ['creationDate' => 'ASC'], 15),
  21.                 ]);
  22.             } elseif (in_array('ROLE_ADMIN'$roles)) {
  23.                 return $this->render('adminDesktop.html.twig', [
  24.                     'proposals' => $fichesRepository->findBy(['isFiche' => true],['creationDate' => 'DESC'], 10),
  25.                     'fiches' => $fichesRepository->findBy(['isFiche' => false],['creationDate' => 'DESC'], 10),
  26.                 ]);
  27.             }
  28.         }else {
  29.             return $this->redirectToRoute('login');
  30.         }
  31.     }
  32.     /**
  33.      * @throws Exception
  34.      */
  35.     #[Route('/test'name'test')]
  36.     public function test(EntityManagerInterface $entityManager): Response
  37.     {
  38.         $queryBuilder $entityManager->getConnection();
  39.         $sql "SELECT * FROM isens_pages";
  40.         $query $queryBuilder->prepare($sql);
  41.         $result $query->executeQuery();
  42.         $results $result->fetchAllAssociative();
  43. //        foreach($results as $dataSeo) {
  44. /*            $arraySeo = explode('?>',$dataSeo['corps']);*/
  45. //        }
  46.         return $this->render('admin/admin.html.twig');
  47.     }
  48. }