src/Controller/Api/GameController.php line 609

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