src/Controller/IndexController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Configuration;
  4. use App\Entity\User;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Security\Core\Security;
  8. class IndexController extends AbstractController
  9. {
  10.     public function index(Security $security): Response
  11.     {
  12.         //If there are no configuration saved, it redirects to create a new configuration
  13.         if (count($this->getDoctrine()->getRepository(Configuration::class)->findAll()) == 0) {
  14.             return $this->redirectToRoute('app_configuration_new');
  15.         }
  16.         //If there are no users, it redirects to create a new user
  17.         if (count($this->getDoctrine()->getRepository(User::class)->findAll()) == 0) {
  18.             return $this->redirectToRoute('app_user_new');
  19.         }
  20.         //If the user is not logged in, it must log in
  21.         if ($security->getUser()) {
  22.             return $this->render('index/index.html.twig');
  23.         } else {
  24.             return $this->redirectToRoute('app_login');
  25.         }
  26.     }
  27.     public function import(Security $security)
  28.     {
  29.         if ($security->getUser() && $security->getUser()->getActive()) {
  30.             return $this->render('index/import.html.twig');
  31.         } else {
  32.             return $this->redirectToRoute('app_index');
  33.         }
  34.     }
  35.     public function export(Security $security)
  36.     {
  37.         if ($security->getUser() && $security->getUser()->getActive()) {
  38.             return $this->render('index/export.html.twig');
  39.         } else {
  40.             return $this->redirectToRoute('app_index');
  41.         }
  42.     }
  43. }