src/Controller/MainController.php line 25

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.         if ($this->getUser()) {
  20. //            $quizNr = $this->getQuizNr();
  21.             $em $this->getDoctrine()->getManager();
  22.             $rank $em->getRepository(Answear::class)->getRank(3);
  23.             $answear $em
  24.                 ->getRepository(Answear::class)
  25.                 ->findOneBy(['user' => $this->getUser()]);
  26.             $memory $em
  27.                 ->getRepository(MemoryGame::class)
  28.                 ->findOneBy(['user' => $this->getUser()]);
  29.         }
  30.         return $this->render('page/homepage.html.twig', [
  31.             'rank' => $rank,
  32.             'answear' => $answear,
  33.             'memory' => $memory,
  34.         ]);
  35.     }
  36.     /**
  37.      * @Route("/summary", name="app_summary")
  38.      */
  39.     public function summary(): Response
  40.     {
  41.         $em $this->getDoctrine()->getManager();
  42. //        $quizNr = $this->getQuizNr();
  43.         $answear $em
  44.             ->getRepository(Answear::class)
  45.             ->findOneBy(['user' => $this->getUser()]);
  46.         $memory $em
  47.             ->getRepository(MemoryGame::class)
  48.             ->findOneBy(['user' => $this->getUser()]);
  49.         if (!($answear instanceof Answear) || !($answear instanceof Answear)) {
  50.             return new RedirectResponse($this->get('router')->generate('app_homepage'));
  51.         }
  52.         $points $answear->getPoints() + $memory->getPoints();
  53.         $place $em
  54.             ->getRepository(Answear::class)->getSummaryPosition($this->getUser());
  55.         return $this->render('page/summary.html.twig', [
  56.             'points' => $points,
  57.             'place' => $place,
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/rules", name="app_rules")
  62.      */
  63.     public function rules(): Response
  64.     {
  65.         return $this->render('page/rules.html.twig', [
  66.         ]);
  67.     }
  68. //    protected function getQuizNr()
  69. //    {
  70. ////        $now = date('Y-m-d');
  71. ////        if ($now < '2024-05-27') {
  72. ////            return 1;
  73. ////        } else if ($now >= '2024-05-27' && $now < '2024-06-03') {
  74. ////            return 2;
  75. ////        } else if ($now >= '2024-06-03' && $now < '2024-06-10') {
  76. ////            return 3;
  77. ////        } else if ($now >= '2024-06-10') {
  78. ////            return 4;
  79. ////        }
  80. //        return 1;
  81. //    }
  82. }