<?php
namespace App\Controller;
use App\Repository\TrainingsRepository;
use Doctrine\DBAL\Exception;
use Doctrine\ORM\EntityManagerInterface;
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 home(TrainingsRepository $fichesRepository): Response
{
if($this->getUser()){
$roles = $this->getUser()->getRoles();
if (in_array('ROLE_SUPER_ADMIN', $roles)) {
return $this->render('admin/admin.html.twig');
} elseif (in_array('ROLE_COMMERCIAL', $roles)) {
return $this->render('commercial/commercial.html.twig', [
'fiches' => $fichesRepository->findBy(['owner' => $this->getUser(), 'isFiche' => true], ['creationDate' => 'ASC'], 15),
]);
} elseif (in_array('ROLE_ADMIN', $roles)) {
return $this->render('adminDesktop.html.twig', [
'proposals' => $fichesRepository->findBy(['isFiche' => true],['creationDate' => 'DESC'], 10),
'fiches' => $fichesRepository->findBy(['isFiche' => false],['creationDate' => 'DESC'], 10),
]);
}
}else {
return $this->redirectToRoute('login');
}
}
/**
* @throws Exception
*/
#[Route('/test', name: 'test')]
public function test(EntityManagerInterface $entityManager): Response
{
$queryBuilder = $entityManager->getConnection();
$sql = "SELECT * FROM isens_pages";
$query = $queryBuilder->prepare($sql);
$result = $query->executeQuery();
$results = $result->fetchAllAssociative();
// foreach($results as $dataSeo) {
/* $arraySeo = explode('?>',$dataSeo['corps']);*/
// }
return $this->render('admin/admin.html.twig');
}
}