src/Controller/DashboardController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Entity\Level;
  5. use App\Entity\Project;
  6. use App\Entity\Review;
  7. use App\Entity\User;
  8. use App\Repository\CategoryRepository;
  9. use App\Repository\LevelRepository;
  10. use App\Repository\ProjectRepository;
  11. use App\Repository\ReviewRepository;
  12. use App\Repository\SpecialRepository;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Symfony\Component\HttpFoundation\Request;
  18. class DashboardController extends AbstractController
  19. {
  20.     #[Route('/'name'app_dashboard')]
  21.     public function index(LevelRepository $levelRepositoryProjectRepository $projectRepository): Response
  22.     {
  23.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  24.         $user=$this->getUser();
  25.         $specials $user->getSpecials();
  26.         foreach ($specials as $special)
  27.                                         {
  28.                                             if ($special->isStatus())
  29.                                             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  30.                                         }
  31.         $free $levelRepository->findBy(['id' => 1]);   $freeProjects $projectRepository->findBy(['level'=>$free]);
  32.         $bronze $levelRepository->findBy(['id' => 2]); $bronzeProjects $projectRepository->findBy(['level'=>$bronze]);
  33.         $silver $levelRepository->findBy(['id' => 3]); $silverProjects $projectRepository->findBy(['level'=>$silver]);
  34.         $gold $levelRepository->findBy(['id' => 4]);   $goldProjects $projectRepository->findBy(['level'=>$gold]);
  35.         $diamond $levelRepository->findBy(['id' => 5]); $diamondProjects $projectRepository->findBy(['level'=>$diamond]);
  36.         $black $levelRepository->findBy(['id' => 6]);   $blackProjects $projectRepository->findBy(['level'=>$black]);
  37.         return $this->render('dashboard/index.html.twig', [
  38.             'freeprojects' => $freeProjects,
  39.             'bronzeprojects' => $bronzeProjects,
  40.             'silverprojects' => $silverProjects,
  41.             'goldprojects' => $goldProjects,
  42.             'diamondprojects' => $diamondProjects,
  43.             'blackprojects' => $blackProjects,
  44.         ]);
  45.     }
  46.     #[Route('/project/{id}'name'app_project'methods: ['GET','POST'])]
  47.     public function project(ReviewRepository $reviewRepositoryEntityManagerInterface $entityManagerProject $projectRequest $request): Response
  48.     {
  49.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  50.         /** @var User $user */
  51.         $user $this->getUser();
  52.         $submited false;
  53.         if ($user->getWallet()->getValue() < 0)
  54.             {
  55.                 $this->addFlash('danger''To review a task you need to have a positive balance. Wallet: $ '.$user->getWallet()->getValue());
  56.                 return $this->redirect($request->headers->get('referer'));
  57.             }
  58.         $allReviews $user->getReviews();
  59.             foreach ($allReviews as $oneReview)
  60.                                                 {
  61.                                                     if ($oneReview->getProject() == $project)
  62.                                                                                             {
  63.                                                                                                 if ($oneReview->isStatus()== true || is_null($oneReview->isStatus())){ $submited=true;}
  64.                                                                                             }
  65.                                                 }
  66.          if ($project->getLevel()->getId() > $this->getUser()->getLevel()->getId())
  67.             {
  68.                 $this->addFlash('danger''Please upgrade your user level to '.$project->getLevel().' !');
  69.                 //return $this->redirectToRoute('app_projects');
  70.                 return $this->redirect($request->headers->get('referer'));
  71.             }
  72.                  if (isset($_POST['comment']))  {
  73.                      if (isset($_POST['optradio']))
  74.                          { $rating $_POST['optradio']; $comment $_POST['comment'];
  75.                            $review = new Review();
  76.                            $review->setUser($user);
  77.                            $review->setProject($project);
  78.                            $review->setComment($comment);
  79.                            $review->setRating($rating);
  80.                              $entityManager->persist($review);
  81.                              $entityManager->flush();
  82.                              $submited=true;
  83.                              $this->addFlash('success''Great, your review has been submited !');
  84.                              return $this->redirect($request->headers->get('referer'));
  85.                          }
  86.                              else {      $this->addFlash('danger''Please set rating and insert comment !');
  87.                                          return $this->redirect($request->headers->get('referer'));
  88.                                   }
  89.          }
  90.         return $this->render('dashboard/oneProject.html.twig', [
  91.             'project' => $project,
  92.             'submited' => $submited,
  93.         ]);
  94.     }
  95.     #[Route('/projects'name'app_projects')]
  96.     public function projects(ProjectRepository $projectRepositoryLevelRepository $levelRepository): Response
  97.     {
  98.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  99.         $user=$this->getUser();
  100.         $specials $user->getSpecials();
  101.         foreach ($specials as $special)
  102.         {
  103.             if ($special->isStatus())
  104.             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  105.         }
  106.         $allProjects=[];
  107.             for ($i=1$i<=$user->getLevel()->getId(); $i++)
  108.                                     {
  109.                                         $ProjectList $projectRepository->findBy(['level' => $levelRepository->findBy(['id'=>$i])]);
  110.                                         foreach ($ProjectList as $project)
  111.                                                                             {
  112.                                                                                 $allProjects[]=$project;
  113.                                                                             }
  114.                                     }
  115.         return $this->render('dashboard/projects.html.twig', [
  116.             'projects' => $allProjects,
  117.         ]);
  118.     }
  119.     #[Route('/categories'name'app_categories')]
  120.     public function categories(CategoryRepository $categoryRepository): Response
  121.     {
  122.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  123.         $user=$this->getUser();
  124.         $specials $user->getSpecials();
  125.         foreach ($specials as $special)
  126.         {
  127.             if ($special->isStatus())
  128.             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  129.         }
  130.         return $this->render('dashboard/categories.html.twig', [
  131.             'categories' => $categoryRepository->findAll(),
  132.         ]);
  133.     }
  134.     #[Route('/category/{id}'name'app_category'methods: ['GET'])]
  135.     public function category(Category $categoryProjectRepository $projectRepository): Response
  136.     {
  137.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  138.         $user=$this->getUser();
  139.         $specials $user->getSpecials();
  140.         foreach ($specials as $special)
  141.         {
  142.             if ($special->isStatus())
  143.             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  144.         }
  145.         return $this->render('dashboard/oneCategory.html.twig', [
  146.             'projects' => $projectRepository->findBy(['category'=>$category]),
  147.             'category' => $category,
  148.         ]);
  149.     }
  150.     #[Route('/level/{id}'name'app_level'methods: ['GET'])]
  151.     public function level(Level $levelProjectRepository $projectRepository): Response
  152.     {
  153.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  154.         $user=$this->getUser();
  155.         $specials $user->getSpecials();
  156.         foreach ($specials as $special)
  157.         {
  158.             if ($special->isStatus())
  159.             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  160.         }
  161.         return $this->render('dashboard/oneLevel.html.twig', [
  162.             'projects' => $projectRepository->findBy(['level'=>$level]),
  163.             'level' => $level,
  164.         ]);
  165.     }
  166.     #[Route('/levels'name'app_levels')]
  167.     public function levels(LevelRepository $levelRepository): Response
  168.     {
  169.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
  170.         $user=$this->getUser();
  171.         $specials $user->getSpecials();
  172.         foreach ($specials as $special)
  173.         {
  174.             if ($special->isStatus())
  175.             {    return $this->redirectToRoute('app_special', ['id' => $special->getId()], Response::HTTP_SEE_OTHER); }
  176.         }
  177.         return $this->render('dashboard/levels.html.twig', [
  178.             'levels' => $levelRepository->findAll(),
  179.         ]);
  180.     }
  181.     #[Route('/privacy'name'app_privacy')]
  182.     public function privacy(): Response
  183.     {
  184.         return $this->render('dashboard/privacy.html.twig', [
  185.             'privacy' => 'privacy',
  186.         ]);
  187.     }
  188.     #[Route('/terms'name'app_terms')]
  189.     public function terms(): Response
  190.     {
  191.         return $this->render('dashboard/terms.html.twig', [
  192.             'privacy' => 'privacy',
  193.         ]);
  194.     }
  195.     #[Route('/faqs'name'app_faqs')]
  196.     public function faqs(): Response
  197.     {
  198.         return $this->render('dashboard/faqs.html.twig', [
  199.             'privacy' => 'privacy',
  200.         ]);
  201.     }
  202.     #[Route('/help'name'app_help')]
  203.     public function help(): Response
  204.     {
  205.         return $this->render('dashboard/help.html.twig', [
  206.             'privacy' => 'privacy',
  207.         ]);
  208.     }
  209. }