src/Controller/Home/IndexController.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Home;
  4. use App\Entity\Security\Manager;
  5. use App\Entity\Security\ShopManager;
  6. use App\Entity\Security\User;
  7. use App\Helper\LegalTerms\LegalTermsHelper;
  8. use App\Helper\LegalTerms\LegalTermsInterface;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. class IndexController extends AbstractController
  15. {
  16.     public function __construct(
  17.         private LegalTermsHelper $legalTermsHelper,
  18.         private EntityManagerInterface $entityManager,
  19.         private TranslatorInterface $translator,
  20.     ) {
  21.     }
  22.     public function index(): Response
  23.     {
  24.         $user $this->getUser();
  25.         if ($user instanceof Manager) {
  26.             return $this->redirectToRoute('foxorders_franchise_dashboard', ['id' => $user->getFranchise()->getId()]);
  27.         }
  28.         if ($user instanceof ShopManager) {
  29.             return $this->redirectToRoute('foxorders_shop_dashboard', ['id' => $user->getShop()->getId()]);
  30.         }
  31.         if ($this->isGranted('ROLE_SUPPORT')) {
  32.             return $this->redirectToRoute('foxorders_admin_dashboard');
  33.         }
  34.         return $this->redirectToRoute('foxorders_dashboard');
  35.     }
  36.     public function home(): Response
  37.     {
  38.         return $this->redirectToRoute('foxorders_dashboard');
  39.     }
  40.     /**
  41.      * @IsGranted("ROLE_SHOP_MANAGER")
  42.      */
  43.     public function acceptTOU(): Response
  44.     {
  45.         /** @var User $user */
  46.         $user $this->getUser();
  47.         if (!$user->hasAcceptedTOU()) {
  48.             $user->setAcceptedTOU(true);
  49.             $this->entityManager->flush();
  50.         }
  51.         return $this->redirectToRoute('foxorders_dashboard');
  52.     }
  53.     public function legalTermsPreview(string $type): Response
  54.     {
  55.         if (
  56.             !\in_array($typeLegalTermsInterface::TYPEStrue)
  57.             || (null === $fileContent $this->legalTermsHelper->getFileContent($type))
  58.         ) {
  59.             $this->addFlash('danger'$this->translator->trans('app.legal_terms.flash_messages.error.invalid_type'));
  60.             return $this->redirectToRoute('security_login');
  61.         }
  62.         return $this->renderForm('Home/legal_terms_preview.html.twig'compact('fileContent'));
  63.     }
  64. }