vaso123

Untitled

Mar 2nd, 2021
698
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use App\Model\Game;
  6. use App\Repository\CellRepository;
  7. use Doctrine\DBAL\DBALException;
  8. use Doctrine\ORM\NonUniqueResultException;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13.  
  14. class MainController extends AbstractController
  15. {
  16.  
  17.     /**
  18.      * @var Game
  19.      */
  20.     private $game;
  21.  
  22.     /**
  23.      * @var CellRepository
  24.      */
  25.     private $cellRepository;
  26.  
  27.     public function __construct(
  28.         Game $game,
  29.         CellRepository $cellRepository
  30.     ) {
  31.         $this->game = $game;
  32.         $this->cellRepository = $cellRepository;
  33.     }
  34.  
  35.     /**
  36.      * @Route ("/", name="main", path="main")
  37.      */
  38.     public function index(): Response
  39.     {
  40.         $cells = $this->cellRepository->getAll();
  41.         return $this->render(
  42.             'index.html.twig',
  43.             [
  44.                 'cells' => $cells
  45.             ]
  46.         );
  47.     }
  48.  
  49.     /**
  50.      * @Route ("/reset-game", name="reset-game", path="reset-game")
  51.      * @return RedirectResponse
  52.      * @throws DBALException
  53.      * @throws NonUniqueResultException
  54.      */
  55.     public function resetGame(): RedirectResponse
  56.     {
  57.         $this->game->resetDatabase();
  58.         $this->game->initializeWithFixedValues($this->getInitialCellData());
  59.         return $this->redirectToRoute('main', [], 301);
  60.     }
  61.  
  62.     /**
  63.      * @return Response
  64.      * @Route ("/refresh-game-single", name="refresh-game-single")
  65.      */
  66.     public function checkTableSingle(): Response
  67.     {
  68.         $this->game->initialize();
  69.         $toastText = '';
  70.         if ($this->game->processSingleCases()) {
  71.             $toastText = 'There are no more exclusions for single values';
  72.         }
  73.         return $this->json(
  74.             [
  75.                 'gameTable' => $this->getRenderedGameTableContent(),
  76.                 'toast' => $toastText
  77.             ]
  78.         );
  79.     }
  80.  
  81.     /**
  82.      * @return Response
  83.      * @Route ("/refresh-game-multi", name="refresh-game-multi")
  84.      */
  85.     public function checkTableMultiValues(): Response
  86.     {
  87.         $this->game->initialize();
  88.         $toastText = '';
  89.         if ($this->game->processMultiCases()) {
  90.             $toastText = 'There are no more exclusions for multi values';
  91.         }
  92.         return $this->json(
  93.             [
  94.                 'gameTable' => $this->getRenderedGameTableContent(),
  95.                 'toast' => $toastText
  96.             ]
  97.         );
  98.     }
  99.  
  100.     /**
  101.      * @return false|string
  102.      */
  103.     private function getRenderedGameTableContent()
  104.     {
  105.         return $this->render(
  106.             'game-table.html.twig',
  107.             [
  108.                 'cells' => $this->game->getCells()
  109.             ]
  110.         )->getContent();
  111.     }
  112.  
  113.     /**
  114.      * @return int[][]
  115.      */
  116.     private function getInitialCellData(): array
  117.     {
  118.         //initial
  119.         return [
  120.             [2, 1, 7],
  121.             //...
  122.         ];
  123.     }
  124. }
  125.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×