<?php
namespace App\Controller;
use Predis\Client;
use Doctrine\DBAL\Connection;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
class PageController extends BaseController
{
public function __construct(Client $redis, Connection $connection)
{
$this->redis = $redis;
$this->connection = $connection;
}
private function getHistory(): array
{
$historyRaw = $this->redis->lRange('game_history', 0, 9);
return array_map(fn($item) => json_decode($item, true), $historyRaw);
}
/**
* @Route("/", name="main_page")
*/
public function index(): Response
{
return $this->render('main.html.twig', [
'history' => $this->getHistory(),
]);
}
/**
* @Route("/mines", name="mines_page")
*/
public function mines(): Response
{
return $this->render('mines.html.twig', [
'history' => $this->getHistory(),
]);
}
/**
* @Route("/nvuti", name="nvuti_page")
*/
public function nvuti(): Response
{
return $this->render('nvuti.html.twig', [
'history' => $this->getHistory(),
]);
}
/**
* @Route("/lobby", name="lobby_page")
*/
public function lobby(): Response
{
return $this->render('lobby.html.twig');
}
/**
* @Route("/tournament", name="tour_page")
*/
public function tournament(): Response
{
return $this->render('tournament.html.twig');
}
/**
* @Route("/bonus", name="bonus_page")
*/
public function bonus(Request $request): Response
{
$user = $this->getAuthorizedUser($request);
if (!$user) {
return $this->redirectToRoute('main_page');
}
return $this->render('bonus.html.twig');
}
/**
* @Route("/referral", name="referral_page")
*/
public function referral(Request $request): Response
{
$user = $this->getAuthorizedUser($request);
if (!$user) {
return $this->redirectToRoute('main_page');
}
return $this->render('referral.html.twig');
}
/**
* @Route("/go/{id}", name="referral_redirect", requirements={"id"="\d+"})
*/
public function referralRedirect(int $id, Request $request): RedirectResponse
{
$request->getSession()->set('ref_id', $id);
return $this->redirectToRoute('main_page');
}
/**
* @Route("/profile", name="profile_page")
*/
public function profile(Request $request): Response
{
$user = $this->getAuthorizedUser($request);
if (!$user) {
return $this->redirectToRoute('main_page');
}
$sumDeposits = $this->connection->fetchOne(
'SELECT COALESCE(SUM(suma), 0) FROM deposits WHERE user_id = ? AND status = 1',
[$user['id']]
);
$sumWithdraws = $this->connection->fetchOne(
'SELECT COALESCE(SUM(sum), 0) FROM withdraws WHERE user_id = ? AND status = 1',
[$user['id']]
);
return $this->render('profile.html.twig', [
'user' => $user,
'sumDeposits' => $sumDeposits,
'sumWithdraws' => $sumWithdraws,
]);
}
/**
* @Route("/faq", name="faq_page")
*/
public function faq(): Response
{
return $this->render('faq.html.twig');
}
/**
* @Route("/support", name="support_redirect")
*/
public function support(): Response
{
return $this->redirectTo('https://vk.me/candy1_win3');
}
}