src/Controller/MainController.php line 26

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