<?php
namespace App\Controller;
use App\Entity\Category;
use App\Entity\Level;
use App\Entity\Project;
use App\Entity\Review;
use App\Entity\User;
use App\Repository\CategoryRepository;
use App\Repository\LevelRepository;
use App\Repository\ProjectRepository;
use App\Repository\ReviewRepository;
use App\Repository\SpecialRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
class DashboardController extends AbstractController
{
#[Route('/', name: 'app_dashboard')]
public function index(LevelRepository $levelRepository, ProjectRepository $projectRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
$free = $levelRepository->findBy(['id' => 1]); $freeProjects = $projectRepository->findBy(['level'=>$free]);
$bronze = $levelRepository->findBy(['id' => 2]); $bronzeProjects = $projectRepository->findBy(['level'=>$bronze]);
$silver = $levelRepository->findBy(['id' => 3]); $silverProjects = $projectRepository->findBy(['level'=>$silver]);
$gold = $levelRepository->findBy(['id' => 4]); $goldProjects = $projectRepository->findBy(['level'=>$gold]);
$diamond = $levelRepository->findBy(['id' => 5]); $diamondProjects = $projectRepository->findBy(['level'=>$diamond]);
$black = $levelRepository->findBy(['id' => 6]); $blackProjects = $projectRepository->findBy(['level'=>$black]);
return $this->render('dashboard/index.html.twig', [
'freeprojects' => $freeProjects,
'bronzeprojects' => $bronzeProjects,
'silverprojects' => $silverProjects,
'goldprojects' => $goldProjects,
'diamondprojects' => $diamondProjects,
'blackprojects' => $blackProjects,
]);
}
#[Route('/project/{id}', name: 'app_project', methods: ['GET','POST'])]
public function project(ReviewRepository $reviewRepository, EntityManagerInterface $entityManager, Project $project, Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
/** @var User $user */
$user = $this->getUser();
$submited = false;
if ($user->getWallet()->getValue() < 0)
{
$this->addFlash('danger', 'To review a task you need to have a positive balance. Wallet: $ '.$user->getWallet()->getValue());
return $this->redirect($request->headers->get('referer'));
}
$allReviews = $user->getReviews();
foreach ($allReviews as $oneReview)
{
if ($oneReview->getProject() == $project)
{
if ($oneReview->isStatus()== true || is_null($oneReview->isStatus())){ $submited=true;}
}
}
if ($project->getLevel()->getId() > $this->getUser()->getLevel()->getId())
{
$this->addFlash('danger', 'Please upgrade your user level to '.$project->getLevel().' !');
//return $this->redirectToRoute('app_projects');
return $this->redirect($request->headers->get('referer'));
}
if (isset($_POST['comment'])) {
if (isset($_POST['optradio']))
{ $rating = $_POST['optradio']; $comment = $_POST['comment'];
$review = new Review();
$review->setUser($user);
$review->setProject($project);
$review->setComment($comment);
$review->setRating($rating);
$entityManager->persist($review);
$entityManager->flush();
$submited=true;
$this->addFlash('success', 'Great, your review has been submited !');
return $this->redirect($request->headers->get('referer'));
}
else { $this->addFlash('danger', 'Please set rating and insert comment !');
return $this->redirect($request->headers->get('referer'));
}
}
return $this->render('dashboard/oneProject.html.twig', [
'project' => $project,
'submited' => $submited,
]);
}
#[Route('/projects', name: 'app_projects')]
public function projects(ProjectRepository $projectRepository, LevelRepository $levelRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
$allProjects=[];
for ($i=1; $i<=$user->getLevel()->getId(); $i++)
{
$ProjectList = $projectRepository->findBy(['level' => $levelRepository->findBy(['id'=>$i])]);
foreach ($ProjectList as $project)
{
$allProjects[]=$project;
}
}
return $this->render('dashboard/projects.html.twig', [
'projects' => $allProjects,
]);
}
#[Route('/categories', name: 'app_categories')]
public function categories(CategoryRepository $categoryRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
return $this->render('dashboard/categories.html.twig', [
'categories' => $categoryRepository->findAll(),
]);
}
#[Route('/category/{id}', name: 'app_category', methods: ['GET'])]
public function category(Category $category, ProjectRepository $projectRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
return $this->render('dashboard/oneCategory.html.twig', [
'projects' => $projectRepository->findBy(['category'=>$category]),
'category' => $category,
]);
}
#[Route('/level/{id}', name: 'app_level', methods: ['GET'])]
public function level(Level $level, ProjectRepository $projectRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
return $this->render('dashboard/oneLevel.html.twig', [
'projects' => $projectRepository->findBy(['level'=>$level]),
'level' => $level,
]);
}
#[Route('/levels', name: 'app_levels')]
public function levels(LevelRepository $levelRepository): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$user=$this->getUser();
$specials = $user->getSpecials();
foreach ($specials as $special)
{
if ($special->isStatus())
{ return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
}
return $this->render('dashboard/levels.html.twig', [
'levels' => $levelRepository->findAll(),
]);
}
#[Route('/privacy', name: 'app_privacy')]
public function privacy(): Response
{
return $this->render('dashboard/privacy.html.twig', [
'privacy' => 'privacy',
]);
}
#[Route('/terms', name: 'app_terms')]
public function terms(): Response
{
return $this->render('dashboard/terms.html.twig', [
'privacy' => 'privacy',
]);
}
#[Route('/faqs', name: 'app_faqs')]
public function faqs(): Response
{
return $this->render('dashboard/faqs.html.twig', [
'privacy' => 'privacy',
]);
}
#[Route('/help', name: 'app_help')]
public function help(): Response
{
return $this->render('dashboard/help.html.twig', [
'privacy' => 'privacy',
]);
}
}