Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller;
- use App\Model\Game;
- use App\Repository\CellRepository;
- use Doctrine\DBAL\DBALException;
- use Doctrine\ORM\NonUniqueResultException;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- class MainController extends AbstractController
- {
- /**
- * @var Game
- */
- private $game;
- /**
- * @var CellRepository
- */
- private $cellRepository;
- public function __construct(
- Game $game,
- CellRepository $cellRepository
- ) {
- $this->game = $game;
- $this->cellRepository = $cellRepository;
- }
- /**
- * @Route ("/", name="main", path="main")
- */
- public function index(): Response
- {
- $cells = $this->cellRepository->getAll();
- return $this->render(
- 'index.html.twig',
- [
- 'cells' => $cells
- ]
- );
- }
- /**
- * @Route ("/reset-game", name="reset-game", path="reset-game")
- * @return RedirectResponse
- * @throws DBALException
- * @throws NonUniqueResultException
- */
- public function resetGame(): RedirectResponse
- {
- $this->game->resetDatabase();
- $this->game->initializeWithFixedValues($this->getInitialCellData());
- return $this->redirectToRoute('main', [], 301);
- }
- /**
- * @return Response
- * @Route ("/refresh-game-single", name="refresh-game-single")
- */
- public function checkTableSingle(): Response
- {
- $this->game->initialize();
- $toastText = '';
- if ($this->game->processSingleCases()) {
- $toastText = 'There are no more exclusions for single values';
- }
- return $this->json(
- [
- 'gameTable' => $this->getRenderedGameTableContent(),
- 'toast' => $toastText
- ]
- );
- }
- /**
- * @return Response
- * @Route ("/refresh-game-multi", name="refresh-game-multi")
- */
- public function checkTableMultiValues(): Response
- {
- $this->game->initialize();
- $toastText = '';
- if ($this->game->processMultiCases()) {
- $toastText = 'There are no more exclusions for multi values';
- }
- return $this->json(
- [
- 'gameTable' => $this->getRenderedGameTableContent(),
- 'toast' => $toastText
- ]
- );
- }
- /**
- * @return false|string
- */
- private function getRenderedGameTableContent()
- {
- return $this->render(
- 'game-table.html.twig',
- [
- 'cells' => $this->game->getCells()
- ]
- )->getContent();
- }
- /**
- * @return int[][]
- */
- private function getInitialCellData(): array
- {
- //initial
- return [
- [2, 1, 7],
- //...
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement