src/Controller/PageController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Predis\Client;
  4. use Doctrine\DBAL\Connection;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. class PageController extends BaseController
  10. {   
  11.     
  12.     public function __construct(Client $redisConnection $connection)
  13.     {
  14.         $this->redis $redis;
  15.         $this->connection $connection;
  16.     }
  17.     
  18.     private function getHistory(): array
  19.     {
  20.         $historyRaw $this->redis->lRange('game_history'09);
  21.         return array_map(fn($item) => json_decode($itemtrue), $historyRaw);
  22.     }
  23.     
  24.     /**
  25.      * @Route("/", name="main_page")
  26.      */
  27.     public function index(): Response
  28.     {
  29.         return $this->render('main.html.twig', [
  30.             'history' => $this->getHistory(),
  31.         ]);
  32.     }
  33.     /**
  34.      * @Route("/mines", name="mines_page")
  35.      */
  36.     public function mines(): Response
  37.     {
  38.         return $this->render('mines.html.twig', [
  39.             'history' => $this->getHistory(),
  40.         ]);
  41.     }
  42.     
  43.     /**
  44.      * @Route("/nvuti", name="nvuti_page")
  45.      */
  46.     public function nvuti(): Response
  47.     {
  48.         return $this->render('nvuti.html.twig', [
  49.             'history' => $this->getHistory(),
  50.         ]);
  51.     }
  52.     
  53.     /**
  54.      * @Route("/lobby", name="lobby_page")
  55.      */
  56.     public function lobby(): Response
  57.     {
  58.         return $this->render('lobby.html.twig');
  59.     }
  60.     
  61.     /**
  62.      * @Route("/tournament", name="tour_page")
  63.      */
  64.     public function tournament(): Response
  65.     {
  66.         return $this->render('tournament.html.twig');
  67.     }
  68.     
  69.     /**
  70.      * @Route("/bonus", name="bonus_page")
  71.      */
  72.     public function bonus(Request $request): Response
  73.     {   
  74.         $user $this->getAuthorizedUser($request);
  75.         if (!$user) {
  76.             return $this->redirectToRoute('main_page');
  77.         }
  78.         
  79.         return $this->render('bonus.html.twig');
  80.     }
  81.     
  82.     /**
  83.      * @Route("/referral", name="referral_page")
  84.      */
  85.     public function referral(Request $request): Response
  86.     {   
  87.         $user $this->getAuthorizedUser($request);
  88.         if (!$user) {
  89.             return $this->redirectToRoute('main_page');
  90.         }
  91.         
  92.         return $this->render('referral.html.twig');
  93.     }
  94.     
  95.     /**
  96.      * @Route("/go/{id}", name="referral_redirect", requirements={"id"="\d+"})
  97.      */
  98.     public function referralRedirect(int $idRequest $request): RedirectResponse
  99.     {
  100.         $request->getSession()->set('ref_id'$id);
  101.         return $this->redirectToRoute('main_page');
  102.     }
  103.     
  104.     /**
  105.      * @Route("/profile", name="profile_page")
  106.      */
  107.     public function profile(Request $request): Response
  108.     {
  109.         $user $this->getAuthorizedUser($request);
  110.         if (!$user) {
  111.             return $this->redirectToRoute('main_page');
  112.         }
  113.         $sumDeposits $this->connection->fetchOne(
  114.             'SELECT COALESCE(SUM(suma), 0) FROM deposits WHERE user_id = ? AND status = 1',
  115.             [$user['id']]
  116.         );
  117.         $sumWithdraws $this->connection->fetchOne(
  118.             'SELECT COALESCE(SUM(sum), 0) FROM withdraws WHERE user_id = ? AND status = 1',
  119.             [$user['id']]
  120.         );
  121.         return $this->render('profile.html.twig', [
  122.             'user' => $user,
  123.             'sumDeposits' => $sumDeposits,
  124.             'sumWithdraws' => $sumWithdraws,
  125.         ]);
  126.     }
  127.     
  128.     /**
  129.      * @Route("/faq", name="faq_page")
  130.      */
  131.     public function faq(): Response
  132.     {
  133.         return $this->render('faq.html.twig');
  134.     }
  135.     
  136.     /**
  137.      * @Route("/support", name="support_redirect")
  138.      */
  139.     public function support(): Response
  140.     {
  141.         return $this->redirectTo('https://vk.me/candy1_win3');
  142.     }
  143. }