src/Controller/Api/GameController.php line 113

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