src/Controller/FrontendController.php line 309

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Beat;
  4. use App\Entity\BeatAuthor;
  5. use App\Entity\Crew;
  6. use App\Entity\Rapper;
  7. use App\Form\Type\BeatAuthorType;
  8. use App\Form\Type\BeatType;
  9. use App\Form\Type\ClientType;
  10. use App\Form\Type\CrewType;
  11. use App\Form\Type\RapperType;
  12. use App\Repository\BattleRepository;
  13. use App\Repository\BeatAuthorRepository;
  14. use App\Repository\BeatRepository;
  15. use App\Repository\ClientRepository;
  16. use App\Repository\CountryRepository;
  17. use App\Repository\CrewRepository;
  18. use App\Repository\RapperRepository;
  19. use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  22. use Symfony\Component\Form\Extension\Core\Type\FileType;
  23. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Component\Security\Core\Security;
  28. use Vich\UploaderBundle\Form\Type\VichFileType;
  29. use Vich\UploaderBundle\Form\Type\VichImageType;
  30. class FrontendController extends AbstractController
  31. {
  32.     private BeatRepository $beatRepository;
  33.     private BattleRepository $battleRepository;
  34.     private RapperRepository $rapperRepository;
  35.     private ClientRepository $clientRepository;
  36.     private CrewRepository $crewRepository;
  37.     private CountryRepository $countryRepository;
  38.     private UserDataController $userDataController;
  39.     private BeatAuthorRepository $beatAuthorRepository;
  40.     public function __construct(
  41.         BeatRepository $beatRepository,
  42.         BattleRepository $battleRepository,
  43.         RapperRepository $rapperRepository,
  44.         ClientRepository $clientRepository,
  45.         UserDataController $userDataController,
  46.         CrewRepository $crewRepository,
  47.         CountryRepository $countryRepository,
  48.         BeatAuthorRepository $beatAuthorRepository
  49.     )
  50.     {
  51.         $this->beatRepository $beatRepository;
  52.         $this->battleRepository $battleRepository;
  53.         $this->rapperRepository $rapperRepository;
  54.         $this->clientRepository $clientRepository;
  55.         $this->userDataController $userDataController;
  56.         $this->crewRepository $crewRepository;
  57.         $this->countryRepository $countryRepository;
  58.         $this->beatAuthorRepository $beatAuthorRepository;
  59.     }
  60.     #[Route(path:  [
  61.         'en' => '/',
  62.         'cs' => '/cs'
  63.     ], name'homePage')]
  64.     public function frontendHomepageAction(): Response
  65.     {
  66.         $user $this->getUser();
  67.         $homepageBattles $this->battleRepository->findAllForHomepage();
  68.         $homepageBeats $this->beatRepository->findAllForHomepage();
  69.         if ($user==null){
  70.             return $this->render('pages/homepage.html.twig',[
  71.                 'homepageBattles'=>$homepageBattles,
  72.                 'homepageBeats'=>$homepageBeats
  73.             ]);
  74.         }else{
  75.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  76.             if($client!=null && $client->isIsActive()){
  77.                 return $this->render('pages/homepage.html.twig',[
  78.                     'userData'=>$this->userDataController->getUserData(),
  79.                     'homepageBattles'=>$homepageBattles,
  80.                     'homepageBeats'=>$homepageBeats
  81.                 ]);
  82.             }else{
  83.                 return $this->render('pages/non-active-content.html.twig',[
  84.                     'email'=>$client->getEmail(),
  85.                     'userData'=>$this->userDataController->getUserData(),
  86.                     'user'=>$client
  87.                 ]);
  88.             }
  89.         }
  90.     }
  91.     #[Route(path:  [
  92.         'en' => '/sign-in',
  93.         'cs' => '/prihlaseni'
  94.     ], name'login')]
  95.     public function frontendLoginAction(): Response
  96.     {
  97.         return $this->render('pages/auth/sign-in.html.twig');
  98.     }
  99.     #[Route(path:  [
  100.         'en' => '/nonvalid-cat',
  101.         'cs' => '/nevalidni-cat'
  102.     ], name'non_valid_cat')]
  103.     public function frontendNonValidClientActivationToken(): Response
  104.     {
  105.         return $this->render('pages/nonvalid-activation-token.html.twig');
  106.     }
  107.     #[Route(path:  [
  108.         'en' => '/resent-cat',
  109.         'cs' => '/resent-cat'
  110.     ], name'activation_token_resent')]
  111.     public function frontendActivationTokenResent(): Response
  112.     {
  113.         $client $this->clientRepository->findOneByEmail($this->getUser()->getUserIdentifier());
  114.         return $this->render('pages/activation-token-resent.html.twig',[
  115.             'email'=>$client->getEmail()
  116.         ]);
  117.     }
  118.     #[Route(path:  [
  119.         'en' => '/sign-up',
  120.         'cs' => '/registrace'
  121.     ], name'register')]
  122.     public function frontendRegisterAction(): Response
  123.     {
  124.         return $this->render('pages/auth/sign-up.html.twig');
  125.     }
  126.     #[Route(path:  [
  127.         'en' => '/profile',
  128.         'cs' => '/profil'
  129.     ], name'profile')]
  130.     public function frontendProfileAction(): Response
  131.     {
  132.         $user $this->getUser();
  133.         if ($user==null){
  134.             return $this->frontendHomepageAction();
  135.         }else{
  136.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  137.             $rapper $client->getRapper();
  138.             $rappers $this->rapperRepository->findAll();
  139.             $latestBattles = [];
  140.             $openedBattles = [];
  141.             $crews =  $this->crewRepository->findAll();
  142.             $countries =  $this->countryRepository->findAll();
  143.             $createRapperForm=$this->createForm(RapperType::class,new Rapper())->createView();
  144.             $createAuthorForm=$this->createForm(BeatAuthorType::class,new BeatAuthor())->createView();
  145.             $updateClientForm $this->createForm(ClientType::class,$client)->createView();
  146.             $createBeatForm $this->createForm(BeatType::class,new Beat())->createView();
  147.             $updateRapperForm null;
  148.             if($rapper){
  149.                 $updateRapperForm $this->createForm(RapperType::class,$rapper)
  150.                     ->createView();
  151.             }
  152.             $updateCrewForm=null;
  153.             if($rapper && $rapper->getCrew() && $rapper->getCrew()->getCreatedBy()===$client){
  154.                 $updateCrewForm $this->createForm(CrewType::class,$rapper->getCrew())
  155.                     ->createView();
  156.             }
  157.             $updateAuthorForm=null;
  158.             if($client->getAuthor()){
  159.                 $updateAuthorForm $this->createForm(BeatAuthorType::class,$client->getAuthor())
  160.                     ->createView();
  161.             }
  162.             if($rapper!=null){
  163.                 $latestBattles $this->battleRepository->findLatestForRapper($rapper,6);
  164.                 $openedBattles $this->battleRepository->findOpenedForRapper($rapper,6);
  165.             }
  166.             if($client->isIsActive()){
  167.                 return $this->render('pages/profile/profile.html.twig',[
  168.                     'userData'=>$this->userDataController->getUserData($client),
  169.                     'client'=>$client,
  170.                     'rapper'=>$rapper,
  171.                     'allRappers'=>$rappers,
  172.                     'crews'=>$crews,
  173.                     'countries'=>$countries,
  174.                     'latestBattles'=>$latestBattles,
  175.                     'openedBattles'=>$openedBattles,
  176.                     'createRapperForm'=>$createRapperForm,
  177.                     'updateRapperForm'=>$updateRapperForm,
  178.                     'createAuthorForm'=>$createAuthorForm,
  179.                     'updateAuthorForm'=>$updateAuthorForm,
  180.                     'updateClientForm'=>$updateClientForm,
  181.                     'createBeatForm'=>$createBeatForm,
  182.                     'updateCrewForm'=>$updateCrewForm
  183.                 ]);
  184.             }else{
  185.                 return $this->render('pages/non-active-content.html.twig',[
  186.                     'email'=>$client->getEmail(),
  187.                     'user'=>$client
  188.                 ]);
  189.             }
  190.         }
  191.     }
  192.     #[Route(path:  [
  193.         'en' => '/messages',
  194.         'cs' => '/zpravy'
  195.     ], name'messages')]
  196.     public function frontendMessagesAction(): Response
  197.     {
  198.         $user $this->getUser();
  199.         if ($user==null){
  200.             return $this->frontendHomepageAction();
  201.         }else{
  202.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  203.             $rapper $client->getRapper();
  204.             $allClients=$this->clientRepository->findAll();
  205.             if($client!=null && $client->isIsActive()){
  206.                 return $this->render('pages/profile/messages.html.twig',[
  207.                     'client'=>$client,
  208.                     'rapper'=>$rapper,
  209.                     'userData'=>$this->userDataController->getUserData(),
  210.                     'recipients'=>$allClients
  211.                 ]);
  212.             }else{
  213.                 return $this->render('pages/non-active-content.html.twig',[
  214.                     'email'=>$client->getEmail(),
  215.                     'user'=>$client
  216.                 ]);
  217.             }
  218.         }
  219.     }
  220.     #[Route(path:  [
  221.         'en' => '/notifications',
  222.         'cs' => '/upozorneni'
  223.     ], name'notifications')]
  224.     public function frontendNotificationsAction(): Response
  225.     {
  226.         $user $this->getUser();
  227.         if ($user==null){
  228.             return $this->frontendHomepageAction();
  229.         }else{
  230.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  231.             $rapper $client->getRapper();
  232.             if($client!=null && $client->isIsActive()){
  233.                 return $this->render('pages/profile/notifications.html.twig',[
  234.                     'client'=>$client,
  235.                     'rapper'=>$rapper,
  236.                     'userData'=>$this->userDataController->getUserData(),
  237.                 ]);
  238.             }else{
  239.                 return $this->render('pages/non-active-content.html.twig',[
  240.                     'email'=>$client->getEmail(),
  241.                     'user'=>$client
  242.                 ]);
  243.             }
  244.         }
  245.     }
  246.     #[Route(path:  [
  247.         'en' => '/settings',
  248.         'cs' => '/nastaveni'
  249.     ], name'settings')]
  250.     public function frontendSettingsAction(Security $security): Response
  251.     {
  252.         $user $this->getUser();
  253.         if ($user==null){
  254.             return $this->render('pages/profile/settings.html.twig');
  255.         }else{
  256.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  257.             if($client!=null && $client->isIsActive()){
  258.                 return $this->render('pages/profile/settings.html.twig',[
  259.                         'userData'=>$this->userDataController->getUserData()
  260.                     ]);
  261.             }else{
  262.                 return $this->render('pages/non-active-content.html.twig',[
  263.                     'email'=>$client->getEmail(),
  264.                     'user'=>$client
  265.                 ]);
  266.             }
  267.         }
  268.     }
  269.     #[Route(path:  [
  270.         'cs' => '/beaty',
  271.         'en' => '/beats'
  272.     ], name'beats')]
  273.     public function frontendBeatsAction(Security $security): Response
  274.     {
  275.         $user $this->getUser();
  276.         $allBeats $this->beatRepository->findAll(['createdAt'=>"DESC"]);
  277.         $allFavoritedBeats $this->beatRepository->findAllFavoritedBeats(20);
  278.         $authors $this->beatAuthorRepository->findAll();
  279.         if ($user==null){
  280.             return $this->render('pages/beats.html.twig',[
  281.                 'allBeats' => $allBeats,
  282.                 'authors'=>$authors,
  283.                 'favoriteBeats'=>$allFavoritedBeats
  284.             ]);
  285.         }else{
  286.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  287.             if($client!=null && $client->isIsActive()){
  288.                 return $this->render('pages/beats.html.twig',[
  289.                     'userData'=>$this->userDataController->getUserData($client),
  290.                     'allBeats' => $allBeats,
  291.                     'authors'=>$authors,
  292.                     'favoriteBeats'=>$allFavoritedBeats
  293.                 ]);
  294.             }else{
  295.                 return $this->render('pages/non-active-content.html.twig',[
  296.                     'email'=>$client->getEmail(),
  297.                     'user'=>$client
  298.                 ]);
  299.             }
  300.         }
  301.     }
  302.     #[Route(path:  [
  303.         'cs' => '/ke-stazeni',
  304.         'en' => '/downloads'
  305.     ], name'downloads')]
  306.     public function frontendDownloadsAction(Security $security): Response
  307.     {
  308.         $user $this->getUser();
  309.         if ($user==null){
  310.             return $this->render('pages/downloads.html.twig');
  311.         }else{
  312.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  313.             if($client!=null && $client->isIsActive()){
  314.                 return $this->render('pages/downloads.html.twig',[
  315.                     'userData'=>$this->userDataController->getUserData($client),
  316.                 ]);
  317.             }else{
  318.                 return $this->render('pages/non-active-content.html.twig',[
  319.                     'email'=>$client->getEmail(),
  320.                     'user'=>$client
  321.                 ]);
  322.             }
  323.         }
  324.     }
  325.     #[Route(path:  [
  326.         'cs' => '/zebricek',
  327.         'en' => '/leaderboard'
  328.     ], name'leaderboard')]
  329.     public function frontendLeaderboardAction(Security $security): Response
  330.     {
  331.         $user $this->getUser();
  332.         $rappers $this->rapperRepository->findAllForLadderboard();
  333.         $crews $this->crewRepository->findAllForLadderboard();
  334.         if ($user==null){
  335.             return $this->render('pages/leaderboard.html.twig',[
  336.                 'rappers'=>$rappers,
  337.                 'crews'=>$crews
  338.             ]);
  339.         }else{
  340.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  341.             if($client!=null && $client->isIsActive()){
  342.                 return $this->render('pages/leaderboard.html.twig',[
  343.                     'userData'=>$this->userDataController->getUserData($client),
  344.                     'crews'=>$crews,
  345.                     'rappers'=>$rappers
  346.                 ]);
  347.             }else{
  348.                 return $this->render('pages/non-active-content.html.twig',[
  349.                     'email'=>$client->getEmail(),
  350.                     'user'=>$client
  351.                 ]);
  352.             }
  353.         }
  354.     }
  355.     #[Route(path:  [
  356.         'cs' => '/o-projektu',
  357.         'en' => '/about'
  358.     ], name'about')]
  359.     public function frontendAboutAction(): Response
  360.     {
  361.         $user $this->getUser();
  362.         if ($user==null){
  363.             return $this->render('pages/about.html.twig');
  364.         }else{
  365.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  366.             if($client!=null && $client->isIsActive()){
  367.                 return $this->render('pages/about.html.twig',[
  368.                     'userData'=>$this->userDataController->getUserData($client),
  369.                 ]);
  370.             }else{
  371.                 return $this->render('pages/non-active-content.html.twig',[
  372.                     'userData'=>$this->userDataController->getUserData($client),
  373.                     'email'=>$client->getEmail()
  374.                 ]);
  375.             }
  376.         }
  377.     }
  378.     #[Route(path:  [
  379.         'cs' => '/faq-cz',
  380.         'en' => '/faq'
  381.     ], name'faq')]
  382.     public function frontendFAQAction(): Response
  383.     {
  384.         $user $this->getUser();
  385.         if ($user==null){
  386.             return $this->render('pages/faq.html.twig');
  387.         }else{
  388.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  389.             if($client!=null && $client->isIsActive()){
  390.                 return $this->render('pages/faq.html.twig',[
  391.                     'userData'=>$this->userDataController->getUserData($client),
  392.                 ]);
  393.             }else{
  394.                 return $this->render('pages/non-active-content.html.twig',[
  395.                     'userData'=>$this->userDataController->getUserData($client),
  396.                     'email'=>$client->getEmail()
  397.                 ]);
  398.             }
  399.         }
  400.     }
  401.     #[Route(path'/error'name'errorPage')]
  402.     public function frontendErrorPageAction(): Response
  403.     {
  404.         $user $this->getUser();
  405.         if ($user==null){
  406.             return $this->render('pages/error_page.html.twig');
  407.         }else{
  408.             $client $this->clientRepository->findOneByEmail($user->getUserIdentifier());
  409.             if($client!=null && $client->isIsActive()){
  410.                 return $this->render('pages/error_page.html.twig',[
  411.                     'userData'=>$this->userDataController->getUserData($client),
  412.                 ]);
  413.             }else{
  414.                 return $this->render('pages/non-active-content.html.twig',[
  415.                     'userData'=>$this->userDataController->getUserData($client),
  416.                     'email'=>$client->getEmail()
  417.                 ]);
  418.             }
  419.         }
  420.     }
  421. }