<?php
namespace App\Controller;
use App\Entity\Configuration;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Security;
class IndexController extends AbstractController
{
public function index(Security $security): Response
{
//If there are no configuration saved, it redirects to create a new configuration
if (count($this->getDoctrine()->getRepository(Configuration::class)->findAll()) == 0) {
return $this->redirectToRoute('app_configuration_new');
}
//If there are no users, it redirects to create a new user
if (count($this->getDoctrine()->getRepository(User::class)->findAll()) == 0) {
return $this->redirectToRoute('app_user_new');
}
//If the user is not logged in, it must log in
if ($security->getUser()) {
return $this->render('index/index.html.twig');
} else {
return $this->redirectToRoute('app_login');
}
}
public function import(Security $security)
{
if ($security->getUser() && $security->getUser()->getActive()) {
return $this->render('index/import.html.twig');
} else {
return $this->redirectToRoute('app_index');
}
}
public function export(Security $security)
{
if ($security->getUser() && $security->getUser()->getActive()) {
return $this->render('index/export.html.twig');
} else {
return $this->redirectToRoute('app_index');
}
}
}