<?php
namespace App\Controller;
use App\Entity\Beat;
use App\Entity\BeatAuthor;
use App\Entity\Crew;
use App\Entity\Rapper;
use App\Form\Type\BeatAuthorType;
use App\Form\Type\BeatType;
use App\Form\Type\ClientType;
use App\Form\Type\CrewType;
use App\Form\Type\RapperType;
use App\Repository\BattleRepository;
use App\Repository\BeatAuthorRepository;
use App\Repository\BeatRepository;
use App\Repository\ClientRepository;
use App\Repository\CountryRepository;
use App\Repository\CrewRepository;
use App\Repository\RapperRepository;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Vich\UploaderBundle\Form\Type\VichFileType;
use Vich\UploaderBundle\Form\Type\VichImageType;
class FrontendController extends AbstractController
{
private BeatRepository $beatRepository;
private BattleRepository $battleRepository;
private RapperRepository $rapperRepository;
private ClientRepository $clientRepository;
private CrewRepository $crewRepository;
private CountryRepository $countryRepository;
private UserDataController $userDataController;
private BeatAuthorRepository $beatAuthorRepository;
public function __construct(
BeatRepository $beatRepository,
BattleRepository $battleRepository,
RapperRepository $rapperRepository,
ClientRepository $clientRepository,
UserDataController $userDataController,
CrewRepository $crewRepository,
CountryRepository $countryRepository,
BeatAuthorRepository $beatAuthorRepository
)
{
$this->beatRepository = $beatRepository;
$this->battleRepository = $battleRepository;
$this->rapperRepository = $rapperRepository;
$this->clientRepository = $clientRepository;
$this->userDataController = $userDataController;
$this->crewRepository = $crewRepository;
$this->countryRepository = $countryRepository;
$this->beatAuthorRepository = $beatAuthorRepository;
}
#[Route(path: [
'en' => '/',
'cs' => '/cs'
], name: 'homePage')]
public function frontendHomepageAction(): Response
{
$user = $this->getUser();
$homepageBattles = $this->battleRepository->findAllForHomepage();
$homepageBeats = $this->beatRepository->findAllForHomepage();
if ($user==null){
return $this->render('pages/homepage.html.twig',[
'homepageBattles'=>$homepageBattles,
'homepageBeats'=>$homepageBeats
]);
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/homepage.html.twig',[
'userData'=>$this->userDataController->getUserData(),
'homepageBattles'=>$homepageBattles,
'homepageBeats'=>$homepageBeats
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'userData'=>$this->userDataController->getUserData(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'en' => '/sign-in',
'cs' => '/prihlaseni'
], name: 'login')]
public function frontendLoginAction(): Response
{
return $this->render('pages/auth/sign-in.html.twig');
}
#[Route(path: [
'en' => '/nonvalid-cat',
'cs' => '/nevalidni-cat'
], name: 'non_valid_cat')]
public function frontendNonValidClientActivationToken(): Response
{
return $this->render('pages/nonvalid-activation-token.html.twig');
}
#[Route(path: [
'en' => '/resent-cat',
'cs' => '/resent-cat'
], name: 'activation_token_resent')]
public function frontendActivationTokenResent(): Response
{
$client = $this->clientRepository->findOneByEmail($this->getUser()->getUserIdentifier());
return $this->render('pages/activation-token-resent.html.twig',[
'email'=>$client->getEmail()
]);
}
#[Route(path: [
'en' => '/sign-up',
'cs' => '/registrace'
], name: 'register')]
public function frontendRegisterAction(): Response
{
return $this->render('pages/auth/sign-up.html.twig');
}
#[Route(path: [
'en' => '/profile',
'cs' => '/profil'
], name: 'profile')]
public function frontendProfileAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->frontendHomepageAction();
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
$rapper = $client->getRapper();
$rappers = $this->rapperRepository->findAll();
$latestBattles = [];
$openedBattles = [];
$crews = $this->crewRepository->findAll();
$countries = $this->countryRepository->findAll();
$createRapperForm=$this->createForm(RapperType::class,new Rapper())->createView();
$createAuthorForm=$this->createForm(BeatAuthorType::class,new BeatAuthor())->createView();
$updateClientForm = $this->createForm(ClientType::class,$client)->createView();
$createBeatForm = $this->createForm(BeatType::class,new Beat())->createView();
$updateRapperForm = null;
if($rapper){
$updateRapperForm = $this->createForm(RapperType::class,$rapper)
->createView();
}
$updateCrewForm=null;
if($rapper && $rapper->getCrew() && $rapper->getCrew()->getCreatedBy()===$client){
$updateCrewForm = $this->createForm(CrewType::class,$rapper->getCrew())
->createView();
}
$updateAuthorForm=null;
if($client->getAuthor()){
$updateAuthorForm = $this->createForm(BeatAuthorType::class,$client->getAuthor())
->createView();
}
if($rapper!=null){
$latestBattles = $this->battleRepository->findLatestForRapper($rapper,6);
$openedBattles = $this->battleRepository->findOpenedForRapper($rapper,6);
}
if($client->isIsActive()){
return $this->render('pages/profile/profile.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'client'=>$client,
'rapper'=>$rapper,
'allRappers'=>$rappers,
'crews'=>$crews,
'countries'=>$countries,
'latestBattles'=>$latestBattles,
'openedBattles'=>$openedBattles,
'createRapperForm'=>$createRapperForm,
'updateRapperForm'=>$updateRapperForm,
'createAuthorForm'=>$createAuthorForm,
'updateAuthorForm'=>$updateAuthorForm,
'updateClientForm'=>$updateClientForm,
'createBeatForm'=>$createBeatForm,
'updateCrewForm'=>$updateCrewForm
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'en' => '/messages',
'cs' => '/zpravy'
], name: 'messages')]
public function frontendMessagesAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->frontendHomepageAction();
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
$rapper = $client->getRapper();
$allClients=$this->clientRepository->findAll();
if($client!=null && $client->isIsActive()){
return $this->render('pages/profile/messages.html.twig',[
'client'=>$client,
'rapper'=>$rapper,
'userData'=>$this->userDataController->getUserData(),
'recipients'=>$allClients
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'en' => '/notifications',
'cs' => '/upozorneni'
], name: 'notifications')]
public function frontendNotificationsAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->frontendHomepageAction();
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
$rapper = $client->getRapper();
if($client!=null && $client->isIsActive()){
return $this->render('pages/profile/notifications.html.twig',[
'client'=>$client,
'rapper'=>$rapper,
'userData'=>$this->userDataController->getUserData(),
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'en' => '/settings',
'cs' => '/nastaveni'
], name: 'settings')]
public function frontendSettingsAction(Security $security): Response
{
$user = $this->getUser();
if ($user==null){
return $this->render('pages/profile/settings.html.twig');
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/profile/settings.html.twig',[
'userData'=>$this->userDataController->getUserData()
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'cs' => '/beaty',
'en' => '/beats'
], name: 'beats')]
public function frontendBeatsAction(Security $security): Response
{
$user = $this->getUser();
$allBeats = $this->beatRepository->findAll(['createdAt'=>"DESC"]);
$allFavoritedBeats = $this->beatRepository->findAllFavoritedBeats(20);
$authors = $this->beatAuthorRepository->findAll();
if ($user==null){
return $this->render('pages/beats.html.twig',[
'allBeats' => $allBeats,
'authors'=>$authors,
'favoriteBeats'=>$allFavoritedBeats
]);
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/beats.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'allBeats' => $allBeats,
'authors'=>$authors,
'favoriteBeats'=>$allFavoritedBeats
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'cs' => '/ke-stazeni',
'en' => '/downloads'
], name: 'downloads')]
public function frontendDownloadsAction(Security $security): Response
{
$user = $this->getUser();
if ($user==null){
return $this->render('pages/downloads.html.twig');
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/downloads.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'cs' => '/zebricek',
'en' => '/leaderboard'
], name: 'leaderboard')]
public function frontendLeaderboardAction(Security $security): Response
{
$user = $this->getUser();
$rappers = $this->rapperRepository->findAllForLadderboard();
$crews = $this->crewRepository->findAllForLadderboard();
if ($user==null){
return $this->render('pages/leaderboard.html.twig',[
'rappers'=>$rappers,
'crews'=>$crews
]);
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/leaderboard.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'crews'=>$crews,
'rappers'=>$rappers
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'email'=>$client->getEmail(),
'user'=>$client
]);
}
}
}
#[Route(path: [
'cs' => '/o-projektu',
'en' => '/about'
], name: 'about')]
public function frontendAboutAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->render('pages/about.html.twig');
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/about.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'email'=>$client->getEmail()
]);
}
}
}
#[Route(path: [
'cs' => '/faq-cz',
'en' => '/faq'
], name: 'faq')]
public function frontendFAQAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->render('pages/faq.html.twig');
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/faq.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'email'=>$client->getEmail()
]);
}
}
}
#[Route(path: '/error', name: 'errorPage')]
public function frontendErrorPageAction(): Response
{
$user = $this->getUser();
if ($user==null){
return $this->render('pages/error_page.html.twig');
}else{
$client = $this->clientRepository->findOneByEmail($user->getUserIdentifier());
if($client!=null && $client->isIsActive()){
return $this->render('pages/error_page.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
]);
}else{
return $this->render('pages/non-active-content.html.twig',[
'userData'=>$this->userDataController->getUserData($client),
'email'=>$client->getEmail()
]);
}
}
}
}