src/Controller/MainController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Answear;
  4. use App\Entity\Matcher;
  5. use App\Entity\MemoryGame;
  6. use App\Model\Settings;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. //use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  12. class MainController extends AbstractController
  13. {
  14. /**
  15. * @Route("/", name="app_homepage")
  16. */
  17. public function homepage(): Response
  18. {
  19. $rank = [];
  20. $answear = $second = null;
  21. $quizNr = Settings::getQuizNr();
  22. if ($this->getUser()) {
  23. $em = $this->getDoctrine()->getManager();
  24. $rank[1] = $em->getRepository(Answear::class)->getRank(1,3);
  25. $rank[2] = $em->getRepository(Answear::class)->getRank(2,3);
  26. $rank[3] = $em->getRepository(Answear::class)->getRank(3,3);
  27. $rank[4] = $em->getRepository(Answear::class)->getRank(4,3);
  28. $answear = $em
  29. ->getRepository(Answear::class)
  30. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr], ['id' => 'DESC']);
  31. if(in_array($quizNr,[2,4])) {
  32. $second = $em
  33. ->getRepository(Matcher::class)
  34. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr]);
  35. } else {
  36. $second = $em
  37. ->getRepository(MemoryGame::class)
  38. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr]);
  39. }
  40. }
  41. return $this->render('page/homepage.html.twig', [
  42. 'rank' => $rank,
  43. 'answear' => $answear,
  44. 'second' => $second,
  45. 'quiz' => $quizNr,
  46. ]);
  47. }
  48. /**
  49. * @Route("/summary", name="app_summary")
  50. */
  51. public function summary(): Response
  52. {
  53. $em = $this->getDoctrine()->getManager();
  54. $quizNr = Settings::getQuizNr();
  55. $answear = $em
  56. ->getRepository(Answear::class)
  57. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr]);
  58. if(in_array($quizNr,[2,4])) {
  59. $second = $em
  60. ->getRepository(Matcher::class)
  61. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr]);
  62. } else {
  63. $second = $em
  64. ->getRepository(MemoryGame::class)
  65. ->findOneBy(['user' => $this->getUser(),'quiz' => $quizNr]);
  66. }
  67. if (!($answear instanceof Answear)) {
  68. return new RedirectResponse($this->get('router')->generate('app_homepage'));
  69. }
  70. $points = $answear->getPoints() + $second->getPoints();
  71. $place = $em
  72. ->getRepository(Answear::class)->getSummaryPosition($this->getUser(), $quizNr);
  73. return $this->render('page/summary.html.twig', [
  74. 'points' => $points,
  75. 'place' => $place,
  76. 'quiz' => $quizNr,
  77. ]);
  78. }
  79. /**
  80. * @Route("/rules", name="app_rules")
  81. */
  82. public function rules(): Response
  83. {
  84. return $this->render('page/rules.html.twig', [
  85. ]);
  86. }
  87. }