src/Controller/Api/GameController.php line 553

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\ConvocatoriaPlayer;
  4. use App\Entity\Customer;
  5. use App\Entity\ExerciseCalendar;
  6. use App\Entity\Game;
  7. use App\Entity\Player;
  8. use App\Entity\PlayerJustification;
  9. use App\Entity\PlayerSportsInjuries;
  10. use App\Entity\SeasonPlayer;
  11. use App\Entity\TrainingAsist;
  12. use App\Entity\TrainingAsistPlayer;
  13. use App\Helper\UploadedBase64File;
  14. use App\Repository\GameRepository;
  15. use App\Services\Api\PlayerManager;
  16. use App\Services\Api\GameManager;
  17. use DateTime;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Psr\Log\LoggerInterface;
  24. class GameController extends ApiController
  25. {
  26.   /** @var GameManager $gameManager */
  27.   protected $gameManager;
  28.   /** @var PlayerManager $playerManager */
  29.   protected $playerManager;
  30.   /**
  31.    * @param GameManager $gameManager
  32.    */
  33.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagGameManager $gameManagerPlayerManager $playerManager)
  34.   {
  35.     parent::__construct($em$parameterBag);
  36.     $this->gameManager $gameManager;
  37.     $this->playerManager $playerManager;
  38.   }
  39.   /**
  40.    * @param Request $request
  41.    * @return JsonResponse
  42.    *
  43.    * @Route("/game/list", name="api_game_list", methods={"POST"})
  44.    */
  45.   public function listGames(Request $request)
  46.   {
  47.     $prefixFile $this->getParameter("app.path.game_images");
  48.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  49.     $request $this->transformJsonBody($request);
  50.     $games = [];
  51.     /** @var Customer $customer */
  52.     $customer $this->getUser();
  53.     $season $customer->getSeasonActive();
  54.     if (!empty($season)) {
  55.       $filter = [
  56.         "season" => $season->getId()
  57.       ];
  58.       /** @var Game $game */
  59.       foreach ($this->em->getRepository(Game::class)->findAllActiveGames($filter, ["day" => "DESC"]) as $game) {
  60.         $games[] = $game->__toArray($baseurl $prefixFile "/");
  61.       }
  62.     }
  63.     return $this->response($games);
  64.   }
  65.   /**
  66.    * @param Request $request
  67.    * @return JsonResponse
  68.    *
  69.    * @Route("/game/list/recycling", name="api_game_list_recycling", methods={"POST"})
  70.    */
  71.   public function listGamesRecycling(Request $request)
  72.   {
  73.     $prefixFile $this->getParameter("app.path.game_images");
  74.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  75.     $request $this->transformJsonBody($request);
  76.     $games = [];
  77.     /** @var Customer $customer */
  78.     $customer $this->getUser();
  79.     $season $customer->getSeasonActive();
  80.     if (!empty($season)) {
  81.       $filter = [
  82.         "season" => $season->getId(),
  83.       ];
  84.       /** @var Game $game */
  85.       foreach ($this->em->getRepository(Game::class)->findAllRecyclingGames($filter, ["day" => "DESC"]) as $game) {
  86.         $games[] = $game->__toArray($baseurl $prefixFile "/");
  87.       }
  88.     }
  89.     return $this->response($games);
  90.   }
  91.   /**
  92.    * @param Request $request
  93.    * @return JsonResponse
  94.    *
  95.    * @Route("/game/stats", name="api_game_stats", methods={"POST"})
  96.    */
  97.   public function statsGames()
  98.   {
  99.     $victory 0;
  100.     $tied 0;
  101.     $loser 0;
  102.     $percent 0;
  103.     $total 0;
  104.     $totalPlus 0;
  105.     $future 0;
  106.     $leagueMinutes 0;
  107.     $cupMinutes 0;
  108.     /** @var Customer $customer */
  109.     $customer $this->getUser();
  110.     $season $customer->getSeasonActive();
  111.     if (!empty($season)) {
  112.       $filter = [
  113.         "season" => $season->getId()
  114.       ];
  115.       /** @var Game $game */
  116.       foreach ($this->em->getRepository(Game::class)->findBy($filter, ["day" => "DESC"]) as $game) {
  117.         if ((!is_null($game->getGoals())) && !is_null($game->getRivalGoals())) {
  118.           $gameDate $game->getDate()->format("Y-m-d-H-i-s");
  119.           $currentDate date("Y-m-d-H-i-s");
  120.           $totalPlus++;
  121.           if ($currentDate $gameDate) {
  122.             $total++;
  123.             // Update competition-specific minutes
  124.             $competition $game->getCompetition();
  125.             if ($competition !== null) {
  126.                 if ($competition->getId() === 1) { // League games
  127.                     $leagueMinutes += $game->getTimeMatch();
  128.                 } elseif ($competition->getId() === 2) { // Cup games
  129.                     $cupMinutes += $game->getTimeMatch();
  130.                 }
  131.             }
  132.             if ($game->getGoals() > $game->getRivalGoals())
  133.               $victory++;
  134.             else if ($game->getGoals() < $game->getRivalGoals())
  135.               $loser++;
  136.             else {
  137.               $tied++;
  138.             }
  139.           }
  140.         }
  141.       }
  142.     }
  143.     $percent $total round($victory 100 $total) : 0;
  144.     $stats = [
  145.       'victory' => $victory,
  146.       'tied' => $tied,
  147.       'loser' => $loser,
  148.       'percent' => $percent,
  149.       'total' => $total,
  150.       'future' => $totalPlus $total,
  151.       'leagueMinutes' => $leagueMinutes,
  152.       'cupMinutes' => $cupMinutes,
  153.     ];
  154.     return $this->response($stats);
  155.   }
  156.   /**
  157.    * @param Request $request
  158.    * @return JsonResponse
  159.    *
  160.    * @Route("/game/delete/{game}/permanent", name="api_game_delete_permanent", methods={"POST"})
  161.    */
  162.   public function deleteGamePermanent(Game $gameRequest $request)
  163.   {
  164.     $prefixFile $this->getParameter("app.path.game_images");
  165.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  166.     $urlFiles $baseurl $prefixFile "/";
  167.     $response $this->gameManager->deleteGamePermanent($game$urlFiles);
  168.     $this->setStatusCode($response["code"]);
  169.     return $this->response($response);
  170.   }
  171.   /**
  172.    * @param Request $request
  173.    * @return JsonResponse
  174.    *
  175.    * @Route("/game/delete/{game}", name="api_game_delete", methods={"POST"})
  176.    */
  177.   public function deleteGame(Game $gameRequest $request)
  178.   {
  179.     $response $this->gameManager->deleteGame($game);
  180.     $this->setStatusCode($response["code"]);
  181.     return $this->response($response);
  182.   }
  183.   /**
  184.    * @param Request $request
  185.    * @return JsonResponse
  186.    *
  187.    * @Route("/game/restore/{game}", name="api_game_restore", methods={"POST"})
  188.    */
  189.   public function restoreGame(Game $gameRequest $request)
  190.   {
  191.     $response $this->gameManager->restoreGame($game);
  192.     $this->setStatusCode($response["code"]);
  193.     return $this->response($response);
  194.   }
  195.   /**
  196.    * @param Request $request
  197.    * @return JsonResponse
  198.    *
  199.    * @Route("/game/convocatoria/{game}", name="api_game_convocatoria", methods={"POST"})
  200.    */
  201.   public function convocatoriaGame(Game $gameRequest $request)
  202.   {
  203.     $players = [];
  204.     $prefixFile $this->getParameter("app.path.player_images");
  205.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  206.     /** @var Customer $customer */
  207.     $customer $this->getUser();
  208.     $season $customer->getSeasonActive();
  209.     if (!empty($season)) {
  210.       $seasonId =  $season->getId();
  211.       if (!empty($game)) {
  212.         $convocatoria $game->getConvocatoria();
  213.         $filter = [
  214.           "season" => $seasonId,
  215.         ];
  216.         $convocatoriaPlayerRepository $this->em->getRepository(ConvocatoriaPlayer::class);
  217.         /** @var SeasonPlayer $seasonPlayer */
  218.         foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter, ["dorsal" => "ASC"]) as $seasonPlayer) {
  219.           /** @var Player $player */
  220.           $player $seasonPlayer->getPlayer();
  221.           $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  222.           $isActive $player->getIsActive();
  223.           $deletedAt $player->getDeletedAt();
  224.           if ($isActive && $seasonPlayerActive && !$deletedAt) {
  225.             $out = [
  226.               "id" => $player->getId(),
  227.               "seasonPlayer_id" => $seasonPlayer->getId(),
  228.               "dorsal" => $seasonPlayer->getDorsal(),
  229.               "name" => $player->getName(),
  230.               "lastname" => $player->getLastname(),
  231.               "position" => !empty($player->getPosition()) ? $player->getPosition()->getSlug() : "",
  232.               "image" => !empty($player->getImage()) ? $baseurl $prefixFile "/" $player->getImage() : "",
  233.             ];
  234.             if ($convocatoria) {
  235.               /** @var ConvocatoriaPlayer $convocatoriaPlayer */
  236.               $convocatoriaPlayer $convocatoriaPlayerRepository->findOneBy([
  237.                 "player_id" => $player->getId(),
  238.                 "convocatoria_id" => $convocatoria->getId(),
  239.               ]);
  240.               if ($convocatoriaPlayer) {
  241.                 $out array_merge($out, [
  242.                   "isOn" => $convocatoriaPlayer->getIsActive(),
  243.                   "in" => $convocatoriaPlayer->getIsActive(),
  244.                   "justification_type" => $convocatoriaPlayer->getJustificationType() ?  $convocatoriaPlayer->getJustificationType()->getId() : null,
  245.                 ]);
  246.               }
  247.               if (!$convocatoriaPlayer) {
  248.                 $out array_merge($out, [
  249.                   "isOn" => false,
  250.                   "in" => false,
  251.                   "justification_type" => null,
  252.                   "is_active" => null,
  253.                 ]);
  254.               }
  255.             }
  256.             if (!$convocatoria) {
  257.               $out array_merge($out, [
  258.                 "isOn" => false,
  259.                 "in" => false,
  260.                 "justification_type" => null,
  261.                 "is_active" => null,
  262.               ]);
  263.             }
  264.             $players[] = $out;
  265.           }
  266.         }
  267.       }
  268.     }
  269.     return $this->response($players);
  270.   }
  271.   /**
  272.    * @param Request $request
  273.    * @return JsonResponse
  274.    *
  275.    * @Route("/game/convocatoria/{game}/edit", name="api_game_convocatoria_edit", methods={"POST"})
  276.    */
  277.   public function convocatoriaGameEdit($gameRequest $request)
  278.   {
  279.     $request $this->transformJsonBody($request);
  280.     $players $request->get('players'null);
  281.     if (is_string($players)) {
  282.       //INPUT DE JSON
  283.       $inputs json_decode($playerstrue);
  284.       $players = [];
  285.       foreach ($inputs as $input) {
  286.         if ($input['isOn']) {
  287.           $players[] = $input;
  288.         }
  289.       }
  290.     } else if (!is_array($players)) {
  291.       $players = [];
  292.     }
  293.     $response $this->gameManager->editConvocatoria($game$players);
  294.     $this->setStatusCode($response["code"]);
  295.     return $this->response($response);
  296.   }
  297.   /**
  298.    * @param Request $request
  299.    * @return JsonResponse
  300.    *
  301.    * @Route("/game/training/{date}", name="api_game_training", methods={"POST"})
  302.    */
  303.   public function trainingGame($dateRequest $request)
  304.   {
  305.     $prefixFile $this->getParameter("app.path.player_images");
  306.     $justificationIconBase $this->getParameter("app.path.justification_icons");
  307.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  308.     $players = [];
  309.     /** @var Customer $customer */
  310.     $customer $this->getUser();
  311.     $season $customer->getSeasonActive();
  312.     if (!empty($season)) {
  313.       $filter = [
  314.         "season" => $season->getId(),
  315.         "date" => \DateTime::createFromFormat("d-m-Y"$date)
  316.       ];
  317.       /** @var TrainingAsist $trainingAsist */
  318.       $trainingAsist $this->em->getRepository(TrainingAsist::class)->findOneBy($filter);
  319.       $delayPlayersIds = [];
  320.       if (!empty($trainingAsist)) {
  321.         $delayPlayers $this->em->getRepository(TrainingAsistPlayer::class)->findBy([
  322.           "trainingAsist" => $trainingAsist->getId(),
  323.           "delay" => 1
  324.         ]);
  325.         $delayPlayersIds array_map(function ($delayPlayer) {
  326.           return $delayPlayer->getPlayer()->getId();
  327.         }, $delayPlayers);
  328.       }
  329.       $filter = [
  330.         "season" => $season->getId()
  331.       ];
  332.       /** @var SeasonPlayer $seasonPlayer */
  333.       /** @var PlayerJustification $playerjustification */
  334.       foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter, ["dorsal" => "ASC"]) as $seasonPlayer) {
  335.         /** @var Player $player */
  336.         $player $seasonPlayer->getPlayer();
  337.         $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  338.         $isActive $player->getIsActive();
  339.         $isDeleted $player->getDeletedAt();
  340.         $justifications $player->getJustification();
  341.         $type null;
  342.         foreach ($justifications as $j) {
  343.           if ($j->getDate()->format('d-m-Y') == $date) {
  344.             $type $j->getJustificationType();
  345.           }
  346.         };
  347.         $playerSportInjure = [
  348.           [
  349.             "prop" => "finish",
  350.             "comp" => "=",
  351.             "val" => 0
  352.           ],
  353.           [
  354.             "prop" => "season",
  355.             "comp" => "=",
  356.             "val" => $season->getId()
  357.           ],
  358.           [
  359.             "prop" => "seasonPlayer",
  360.             "comp" => "=",
  361.             "val" => $seasonPlayer->getId()
  362.           ],
  363.           [
  364.             "prop" => "dateStart",
  365.             "comp" => "<=",
  366.             "val" => \DateTime::createFromFormat("d-m-Y"$date)->format('Y-m-d')
  367.           ]
  368.         ];
  369.         $playerInjury $this->em->getRepository(PlayerSportsInjuries::class)->findOneByOwnCriteria($playerSportInjure);
  370.         $filterInjureEnd = [
  371.           [
  372.             "prop" => "finish",
  373.             "comp" => "=",
  374.             "val" => 1
  375.           ],
  376.           [
  377.             "prop" => "season",
  378.             "comp" => "=",
  379.             "val" => $season->getId()
  380.           ],
  381.           [
  382.             "prop" => "seasonPlayer",
  383.             "comp" => "=",
  384.             "val" => $seasonPlayer->getId()
  385.           ],
  386.           [
  387.             "prop" => "dateStart",
  388.             "comp" => "<=",
  389.             "val" => \DateTime::createFromFormat("d-m-Y"$date)->format('Y-m-d')
  390.           ],
  391.           [
  392.             "prop" => "dateEnd",
  393.             "comp" => ">=",
  394.             "val" => \DateTime::createFromFormat("d-m-Y"$date)->format('Y-m-d')
  395.           ]
  396.         ];
  397.         if (!$playerInjury) {
  398.           $playerInjury $this->em->getRepository(PlayerSportsInjuries::class)->findOneByOwnCriteria($filterInjureEnd, [
  399.             "sort" => 'dateEnd',
  400.             "dir" => "desc"
  401.           ]);
  402.         }
  403.         $justification = !is_null($type) ? $type->getId() : null;
  404.         $justificationType = !is_null($type) ? $type->__toArray($baseurl $justificationIconBase "/") : null;
  405.         if ($isActive && !$isDeleted && $seasonPlayerActive) {
  406.           $players[] = [
  407.             "id" => $player->getId(),
  408.             "dorsal" => $seasonPlayer->getDorsal(),
  409.             "name" => $player->getName(),
  410.             "lastname" => $player->getLastname(),
  411.             "position" => !empty($player->getPosition()) ? $player->getPosition()->getSlug() : "",
  412.             "image" => !empty($player->getImage()) ? $baseurl $prefixFile "/" $player->getImage() : "",
  413.             "isOn" => !empty($trainingAsist) && $trainingAsist->getPlayers()->contains($player),
  414.             "in" => !empty($trainingAsist) && $trainingAsist->getPlayers()->contains($player),
  415.             "delay" => $delayPlayersIds in_array($player->getId(), $delayPlayersIds) : false,
  416.             "justification" => $justificationType,
  417.             "disabled" => $playerInjury $playerInjury->__toArray() : null,
  418.           ];
  419.         }
  420.       }
  421.     }
  422.     return $this->response($players);
  423.   }
  424.   /**
  425.    * @param Request $request
  426.    * @return JsonResponse
  427.    *
  428.    * @Route("/game/training/{date}/edit", name="api_game_training_edit", methods={"POST"})
  429.    */
  430.   public function trainingGameEdit($dateRequest $request)
  431.   {
  432.     $request $this->transformJsonBody($request);
  433.     $players json_decode($request->get('players'"[]"), true);
  434.     $response $this->gameManager->editTraining($date$players);
  435.     $this->setStatusCode($response["code"]);
  436.     return $this->response($response);
  437.   }
  438.   /**
  439.    * @param Request $request
  440.    * @return JsonResponse
  441.    *
  442.    * @Route("/game/trainings/{date}", name="api_game_trainings", methods={"POST"})
  443.    */
  444.   public function trainingsGame(DateTime $date)
  445.   {
  446.     $trainings = [];
  447.     /** @var Customer $customer */
  448.     $customer $this->getUser();
  449.     $season $customer->getSeasonActive();
  450.     if (!empty($season)) {
  451.       $filter = [
  452.         [
  453.           "prop" => "season",
  454.           "comp" => "=",
  455.           "val" => $season->getId()
  456.         ],
  457.         [
  458.           "prop" => "date",
  459.           "comp" => ">=",
  460.           "val" => \DateTime::createFromFormat("Y/m/d"$date->format('Y/m/') . "01")
  461.         ],
  462.         [
  463.           "prop" => "date",
  464.           "comp" => "<=",
  465.           "val" => \DateTime::createFromFormat("Y/m/d"$date->modify('+2 month')->format('Y/m/t'))
  466.         ],
  467.       ];
  468.       /** @var TrainingAsist $trainingAsist */
  469.       foreach ($this->em->getRepository(TrainingAsist::class)->findByOwnCriteria($filter) as $trainingAsist) {
  470.         $exercises $this->em->getRepository(ExerciseCalendar::class)->findBy([
  471.           'date' => $trainingAsist->getDate(),
  472.           'season' => $season
  473.         ]);
  474.         if (count($exercises) || count($trainingAsist->getPlayers())) {
  475.           $trainings[] = [
  476.             "id" => $trainingAsist->getId(),
  477.             "date" => $trainingAsist->getDate()->format("Y-m-d"),
  478.           ];
  479.         } else {
  480.           $this->em->remove($trainingAsist);
  481.           $this->em->flush();
  482.         }
  483.       }
  484.     }
  485.     return $this->response($trainings);
  486.   }
  487.   /**
  488.    * @param Request $request
  489.    * @return JsonResponse
  490.    *
  491.    * @Route("/game/add", name="api_game_add", methods={"POST"})
  492.    */
  493.   public function addGame(Request $request)
  494.   {
  495.     $request $this->transformJsonBody($request);
  496.     $data $this->getDataFromRequest($request);
  497.     $response $this->gameManager->add($data$request);
  498.     $this->setStatusCode($response["code"]);
  499.     if ($response['code'] == 200) {
  500.       $prefixFile $this->getParameter("app.path.game_images");
  501.       $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  502.       $response['game'] = $response['game']->__toArray($baseurl $prefixFile "/");
  503.     }
  504.     return $this->response($response);
  505.   }
  506.   /**
  507.    * @param Request $request
  508.    * @return JsonResponse
  509.    *
  510.    * @Route("/game/edit/{game}", name="api_game_edit", methods={"POST"})
  511.    */
  512.   public function editGame($gameRequest $request)
  513.   {
  514.     $request $this->transformJsonBody($request);
  515.     $data $this->getDataFromRequest($request);
  516.     $response $this->gameManager->edit($game$data$request);
  517.     $this->setStatusCode($response["code"]);
  518.     return $this->response($response);
  519.   }
  520.   /**
  521.    * @param Request $request
  522.    * @return JsonResponse
  523.    *
  524.    * @Route("/game/editlineup/{id}", name="api_game_editlineup", methods={"POST"})
  525.    */
  526.   public function editGameLineUp($idRequest $requestLoggerInterface $logger)
  527.   {
  528.     $lineup $request->get('lineup');
  529.     $lineup json_decode($lineuptrue);
  530.     $logger->info("DATA-GAME " json_encode($lineup) . " " $id);
  531.     $response $this->gameManager->editLineUp($id$lineup);
  532.     $this->setStatusCode($response["code"]);
  533.     return $this->response($response);
  534.   }
  535.   /**
  536.    * @param Request $request
  537.    * @return JsonResponse
  538.    *
  539.    * @Route("/game/edit/alignment/{id}", name="api_game_edit_alignment", methods={"POST"})
  540.    */
  541.   public function editAlignment($idRequest $requestLoggerInterface $logger)
  542.   {
  543.     $request $this->transformJsonBody($request);
  544.     $timePlayers $request->get('dataPlayers');
  545.     $this->playerManager->updateIsTitularByGame($id);
  546.     foreach (json_decode($timePlayers) as $timePlayer) {
  547.       $player $this->em->getRepository(Player::class)->find($timePlayer->id);
  548.       $data = [
  549.         "gameId" => $id,
  550.         "minutes" =>  $timePlayer->minutes,
  551.         "yellowCards" => $timePlayer->yellowCards,
  552.         "redCards" => $timePlayer->redCards,
  553.         "goals" => $timePlayer->goals,
  554.         "goalAssistances" => $timePlayer->goalAssistances,
  555.         "isTitular" => $timePlayer->isTitular,
  556.         "kilometersTraveled" => $timePlayer->kilometersTraveled,
  557.         "shotsOnGoal" => $timePlayer->shotsOnGoal,
  558.         'stolenBalls' => $timePlayer->stolenBalls,
  559.         'penaltiesCommitted' => $timePlayer->penaltiesCommitted,
  560.         'forcedPenalties' =>  $timePlayer->forcedPenalties,
  561.       ];
  562.       $response $this->playerManager->updateStats($player$data);
  563.     }
  564.     $alignment = [
  565.       'tactic' => $request->get('tactic'),
  566.       'alignment' => $request->get('alignment'),
  567.       'captain' => $request->get('captain'),
  568.     ];
  569.     $response $this->gameManager->editAlignment($id$alignment);
  570.     $this->setStatusCode($response["code"]);
  571.     return $this->response($response);
  572.   }
  573.   /**
  574.    * @param Request $request
  575.    * @return JsonResponse
  576.    *
  577.    * @Route("/game/get/alignment/{id}", name="api_game_get_alignment", methods={"POST"})
  578.    */
  579.   public function getAlignment($idRequest $requestLoggerInterface $logger)
  580.   {
  581.     /** @var Customer $customer */
  582.     $customer $this->getUser();
  583.     $season $customer->getSeasonActive();
  584.     if (empty($season))
  585.       return [
  586.         "messageType" => "danger",
  587.         "message" => $this->translator->trans('msg.season_dont_active'),
  588.         "code" => 403
  589.       ];
  590.     $filter = [
  591.       "season" => $season->getId(),
  592.       "id" => $id
  593.     ];
  594.     /** @var Game $game */
  595.     $game $this->em->getRepository(Game::class)->findOneBy($filter);
  596.     $alignment $game->getAlignment();
  597.     $gameAlignment = [
  598.       'alignment' => isset($alignment) ? json_decode($alignment->getAlignment()) : [],
  599.       'tactic' => isset($alignment) ? $alignment->getTactic() : "",
  600.     ];
  601.     return $this->response($gameAlignment);
  602.   }
  603.   /**
  604.    * @param Request $request
  605.    * @return JsonResponse
  606.    *
  607.    * @Route("/game/statsSeason", name="api_game_statsSeason", methods={"POST"})
  608.    */
  609.   public function assistancePlayer(Request $request)
  610.   {
  611.     $customer $this->getUser();
  612.     $season $customer->getSeasonActive();
  613.     /** @var GameRepository $gameRepository */
  614.     $gameRepository $this->em->getRepository(Game::class);
  615.     $results $gameRepository->getStatsBySeason($season);
  616.     return $this->response($results);
  617.   }
  618.   /**
  619.    * @return JsonResponse
  620.    *
  621.    * @Route("/game/lineup/{id}/captain/{playerId}/add", name="api_game_lineup_add_captain", methods={"POST"})
  622.    */
  623.   public function addGameCaptain($id$playerId)
  624.   {
  625.     $response $this->gameManager->addGameCaptain($id$playerId);
  626.     $this->setStatusCode($response["code"]);
  627.     return $this->response($response);
  628.   }
  629.   /**
  630.    * @return JsonResponse
  631.    *
  632.    * @Route("/game/lineup/{id}/captain", name="api_game_lineup_captain", methods={"POST"})
  633.    */
  634.   public function getCaptain($id)
  635.   {
  636.     $response $this->gameManager->getGameCaptain($id);
  637.     $this->setStatusCode($response["code"]);
  638.     return $this->response($response);
  639.   }
  640.   protected function getDataFromRequest(Request $request)
  641.   {
  642.     $date = \DateTime::createFromFormat('d/m/Y'$request->get('date', (new \DateTime())->format('d/m/Y')));
  643.     $time $request->get('time');
  644.     $date->setTime(00);
  645.     if ($time) {
  646.       $times explode(':'$time);
  647.       if (count($times) > 1) {
  648.         $date->setTime($times[0], $times[1]);
  649.       }
  650.     }
  651.     $data = [
  652.       "rival" => $request->get('rival'),
  653.       "localityId" => $request->get('locality_id'),
  654.       "day" => $request->get('day'),
  655.       "date" => $date,
  656.       "goals" => $request->get('goals'),
  657.       "rivalGoals" => $request->get('rivalGoals'),
  658.       "competitionId" => $request->get('competition_id'),
  659.       "timeMatch" => $request->get('timeMatch'),
  660.       "category" => $request->get('category'),
  661.       "shotsGoal" => $request->get('shotsGoal'),
  662.       "shotsOpponent" => $request->get('shotsOpponent'),
  663.       "cornersFavor" => $request->get('cornersFavor'),
  664.       "cornersAgainst" => $request->get('cornersAgainst'),
  665.       "penaltiesFavor" => $request->get('penaltiesFavor'),
  666.       "penaltiesAgainst" => $request->get('penaltiesAgainst'),
  667.       "foulsFavor" => $request->get('foulsFavor'),
  668.       "foulsAgainst" => $request->get('foulsAgainst'),
  669.       "rivalTactic" => $request->get('rivalTactic'),
  670.       "rivalPlayersFormation" => $request->get('rivalPlayersFormation'),
  671.       "totalShots" => $request->get('totalShots'),
  672.       "totalShotsAgainst" => $request->get('totalShotsAgainst'),
  673.       "yellowCards" => $request->get('yellowCards'),
  674.       "yellowCardsAgainst" => $request->get('yellowCardsAgainst'),
  675.       "redCards" => $request->get('redCards'),
  676.       "redCardsAgainst" => $request->get('redCardsAgainst'),
  677.       "currentPositionLeague" => $request->get('currentPositionLeague'),
  678.       "opponentCurrentPositionLeague" => $request->get('opponentCurrentPositionLeague'),
  679.       "pressureRivalId" => $request->get('pressureRivalId') ?? 0,
  680.     ];
  681.     $image $request->get('image');
  682.     if (!empty($image))
  683.       $data["image"] = new UploadedBase64File($image$request->get('imageFilename'));
  684.     return $data;
  685.   }
  686.    /**
  687.      * @param Request $request
  688.      * @return JsonResponse
  689.      *
  690.      * @Route("/games/main-stats", name="api_game_season_stats", methods={"POST"})
  691.      */
  692.     public function gameMainStats(Request $request)
  693.     {
  694.         /** @var Customer $customer */
  695.         $customer $this->getUser();
  696.         $season $customer->getSeasonActive();
  697.         
  698.         /** @var GameRepository $gameRepository */
  699.         $gameRepository $this->em->getRepository(Game::class);
  700.         
  701.         $gameLeagueStats $gameRepository->getGameSeasonStats($season->getId());
  702.         return $this->response($gameLeagueStats);
  703.     }
  704. }