src/Services/Api/GameManager.php line 143

Open in your IDE?
  1. <?php
  2. namespace App\Services\Api;
  3. use App\Entity\Competition;
  4. use App\Entity\Convocatoria;
  5. use App\Entity\ConvocatoriaPlayer;
  6. use App\Entity\Customer;
  7. use App\Entity\Difficulty;
  8. use App\Entity\Game;
  9. use App\Entity\Player;
  10. use App\Entity\Minutes;
  11. use App\Entity\YellowCards;
  12. use App\Entity\RedCards;
  13. use App\Entity\Goals;
  14. use App\Entity\GoalAssistances;
  15. use App\Entity\TrainingAsist;
  16. use App\Entity\Titulars;
  17. use App\Entity\PlayerJustification;
  18. use App\Entity\GameAlignment;
  19. use App\Entity\GamePlayerStatistics;
  20. use App\Entity\JustificationType;
  21. use App\Entity\KilometersTraveled;
  22. use App\Entity\MediaGame;
  23. use App\Entity\SeasonPlayer;
  24. use App\Entity\ShotsOnGoal;
  25. use App\Entity\Locality;
  26. use Symfony\Component\Filesystem\Filesystem;
  27. class GameManager extends BaseApiManager
  28. {
  29.   public function add($data$request)
  30.   {
  31.     $data $this->runGoalVerifier($data);
  32.     $r $this->validGame($data);
  33.     if ($r['code'] != 200)
  34.       return $r;
  35.     /** @var Customer $customer */
  36.     $customer $this->security->getUser();
  37.     $season $customer->getSeasonActive();
  38.     if (empty($season))
  39.       return [
  40.         "messageType" => "danger",
  41.         "message" => $this->translator->trans('msg.season_dont_active'),
  42.         "code" => 403
  43.       ];
  44.     $game = new Game();
  45.     $game->setSeason($season);
  46.     $game $this->setValues($game$data);
  47.     if ($data['rivalTactic'] && $data['rivalPlayersFormation']) {
  48.       $rivalAlignment = new GameAlignment();
  49.       $rivalAlignment->setTactic($data['rivalTactic']);
  50.       $rivalAlignment->setAlignment($data['rivalPlayersFormation']);
  51.       $game->setRivalAlignment($rivalAlignment);
  52.     }
  53.     // locality 
  54.     $locality $this->em->getRepository(Locality::class)->find((int) $data['localityId']);
  55.     if ($locality) {
  56.       $game->setLocality($locality);
  57.     }
  58.     if (!$locality) {
  59.       $defaultLocality $this->em->getRepository(Locality::class)->findOneBy([]);
  60.       if ($defaultLocality) {
  61.         $game->setLocality($defaultLocality);
  62.       }
  63.     }
  64.     // competition
  65.     $competition $this->em->getRepository(Competition::class)->find((int) $data['competitionId']);
  66.     if ($competition) {
  67.       $game->setCompetition($competition);
  68.     }
  69.     if (!$competition) {
  70.       $defaultCompetition $this->em->getRepository(Competition::class)->findOneBy([]);
  71.       if ($defaultCompetition) {
  72.         $game->setCompetition($defaultCompetition);
  73.       }
  74.     }
  75.     $this->em->persist($game);
  76.     $this->em->flush();
  77.     return [
  78.       "messageType" => "success",
  79.       "message" => $this->translator->trans('msg.game_add_success'),
  80.       "newGame" => $data,
  81.       'game' => $game,
  82.       "gameId" => $game->getId(),
  83.       "code" => 200
  84.     ];
  85.   }
  86.   public function runGoalVerifier($data)
  87.   {
  88.     if (!isset($data["goals"]) || is_null($data["goals"])) {
  89.       $data["goals"] = "0";
  90.     }
  91.     if (!isset($data["category"]) || is_null($data["category"])) {
  92.       $data["category"] = 11;
  93.     }
  94.     if (!isset($data["timeMatch"]) || is_null($data["timeMatch"])) {
  95.       $data["timeMatch"] = 90;
  96.     }
  97.     if (!isset($data["rivalGoals"]) || is_null($data["rivalGoals"])) {
  98.       $data["rivalGoals"] = "0";
  99.     }
  100.     if (!isset($data["shotsGoal"]) || is_null($data["shotsGoal"])) {
  101.       $data["shotsGoal"] = "0";
  102.     }
  103.     if (!isset($data["shotsOpponent"]) || is_null($data["shotsOpponent"])) {
  104.       $data["shotsOpponent"] = "0";
  105.     }
  106.     if (!isset($data["cornersFavor"]) || is_null($data["cornersFavor"])) {
  107.       $data["cornersFavor"] = "0";
  108.     }
  109.     if (!isset($data["cornersAgainst"]) || is_null($data["cornersAgainst"])) {
  110.       $data["cornersAgainst"] = "0";
  111.     }
  112.     if (!isset($data["penaltiesFavor"]) || is_null($data["penaltiesFavor"])) {
  113.       $data["penaltiesFavor"] = "0";
  114.     }
  115.     if (!isset($data["penaltiesAgainst"]) || is_null($data["penaltiesAgainst"])) {
  116.       $data["penaltiesAgainst"] = "0";
  117.     }
  118.     if (!isset($data["foulsFavor"]) || is_null($data["foulsFavor"])) {
  119.       $data["foulsFavor"] = "0";
  120.     }
  121.     if (!isset($data["foulsAgainst"]) || is_null($data["foulsAgainst"])) {
  122.       $data["foulsAgainst"] = "0";
  123.     }
  124.     if (!isset($data["day"]) || is_null($data["day"]) || empty($data["day"])) {
  125.       $data["day"] = "1";
  126.     }
  127.     return $data;
  128.   }
  129.   public function edit($game$data$request)
  130.   {
  131.     $data $this->runGoalVerifier($data);
  132.     $r $this->validGame($data);
  133.     if ($r['code'] != 200)
  134.       return $r;
  135.     /** @var Customer $customer */
  136.     $customer $this->security->getUser();
  137.     $season $customer->getSeasonActive();
  138.     if (empty($season))
  139.       return [
  140.         "messageType" => "danger",
  141.         "message" => $this->translator->trans('msg.season_dont_active'),
  142.         "code" => 403
  143.       ];
  144.     $filter = [
  145.       "season" => $season->getId(),
  146.       "id" => $game
  147.     ];
  148.     /** @var Game $game */
  149.     $game $this->em->getRepository(Game::class)->findOneBy($filter);
  150.     if (!empty($game)) {
  151.       $minutes_game_before = (int) $game->getTimeMatch();
  152.       $game $this->setValues($game$data);
  153.       if ($game->getRivalAlignment()) {
  154.         $rivalAlignment $game->getRivalAlignment();
  155.         if ($data['rivalTactic'] && $data['rivalPlayersFormation']) {
  156.           $rivalAlignment->setTactic($data['rivalTactic']);
  157.           $rivalAlignment->setAlignment($data['rivalPlayersFormation']);
  158.           $game->setRivalAlignment($rivalAlignment);
  159.         } else {
  160.           $game->setRivalAlignment(null);
  161.         }
  162.       } else {
  163.         if ($data['rivalTactic'] && $data['rivalPlayersFormation']) {
  164.           $rivalAlignment = new GameAlignment();
  165.           $rivalAlignment->setTactic($data['rivalTactic']);
  166.           $rivalAlignment->setAlignment($data['rivalPlayersFormation']);
  167.           $game->setRivalAlignment($rivalAlignment);
  168.         }
  169.       }
  170.       /**
  171.        * Verifica minutos jugados por los jugadores segun el partido
  172.        */
  173.       $minutes_game_after = (int) $game->getTimeMatch();
  174.       if ($minutes_game_before != $minutes_game_after) {
  175.         /**
  176.          * Valida y actualiza minutes players
  177.          */
  178.         $criteria = [
  179.           "game" => $game
  180.         ];
  181.         /** @var Minutes[] $obj_minutes */
  182.         /** @var Minutes $minutes */
  183.         $obj_minutes $this->em->getRepository(Minutes::class)->findBy($criteria);
  184.         foreach ($obj_minutes as $_minutes) {
  185.           if ($_minutes) {
  186.             $minutes $_minutes;
  187.             $edit_minutes false;
  188.             $minutes_player = (int) $minutes->getQuantity();
  189.             if ($minutes_game_after $minutes_player) {
  190.               $minutes->setQuantity($minutes_game_after);
  191.               $edit_minutes true;
  192.             } elseif ($minutes_game_after $minutes_player && $minutes_game_before === $minutes_player) {
  193.               $minutes->setQuantity($minutes_game_after);
  194.               $edit_minutes true;
  195.             }
  196.             if ($edit_minutes) {
  197.               $this->em->persist($minutes);
  198.             }
  199.           }
  200.         }
  201.       }
  202.       $difficulty $this->em->getRepository(Difficulty::class)->find((int) $data['pressureRivalId']);
  203.       if ($difficulty) {
  204.         $game->setPressureRival($difficulty);
  205.       }
  206.       $locality $this->em->getRepository(Locality::class)->find((int) $data['localityId']);
  207.       if ($locality) {
  208.         $game->setLocality($locality);
  209.       }
  210.       $competition $this->em->getRepository(Competition::class)->find((int) $data['competitionId']);
  211.       if ($competition) {
  212.         $game->setCompetition($competition);
  213.       }
  214.       $game->setOpponentCurrentPositionLeague((int) $data['opponentCurrentPositionLeague']);
  215.       $this->em->persist($game);
  216.       $this->em->flush();
  217.     }
  218.     return [
  219.       "messageType" => "success",
  220.       "message" => $this->translator->trans('msg.game_edit_success'),
  221.       "code" => 200
  222.     ];
  223.   }
  224.   public function deleteGame(Game $game)
  225.   {
  226.     /** @var Customer $customer */
  227.     $customer $this->security->getUser();
  228.     $season $customer->getSeasonActive();
  229.     if (empty($season))
  230.       return [
  231.         "messageType" => "danger",
  232.         "message" => $this->translator->trans('msg.season_dont_active'),
  233.         "code" => 403
  234.       ];
  235.     $game->setDeletedAt(new \DateTime('now'));
  236.     $this->em->persist($game);
  237.     $this->em->flush();
  238.     return [
  239.       "messageType" => "success",
  240.       "message" => $this->translator->trans('msg.game_delete_success'),
  241.       "code" => 200
  242.     ];
  243.   }
  244.   public function restoreGame(Game $game){
  245.         /** @var Customer $customer */
  246.         $customer $this->security->getUser();
  247.         $season $customer->getSeasonActive();
  248.         if (empty($season))
  249.           return [
  250.             "messageType" => "danger",
  251.             "message" => $this->translator->trans('msg.season_dont_active'),
  252.             "code" => 403
  253.           ];
  254.     
  255.         $game->setDeletedAt(null);
  256.         $this->em->persist($game);
  257.         $this->em->flush();
  258.     
  259.         return [
  260.           "messageType" => "success",
  261.           "message" => $this->translator->trans('msg.game_delete_success'),
  262.           "code" => 200
  263.         ];
  264.   }
  265.   public function deleteGamePermanent(Game $gamestring $urlFiles)
  266.   {
  267.     /** @var Customer $customer */
  268.     $customer $this->security->getUser();
  269.     $season $customer->getSeasonActive();
  270.     if (empty($season))
  271.       return [
  272.         "messageType" => "danger",
  273.         "message" => $this->translator->trans('msg.season_dont_active'),
  274.         "code" => 403
  275.       ];
  276.     $counter 0;
  277.     $criteria = [
  278.       "game" => $game
  279.     ];
  280.     /** @var YellowCards $yellowCards */
  281.     foreach ($this->em->getRepository(YellowCards::class)->findBy($criteria) as $yellowCard) {
  282.       if ($yellowCard) {
  283.         $counter++;
  284.         $this->em->remove($yellowCard);
  285.         $this->em->flush();
  286.       }
  287.     }
  288.     /** @var Minutes $minutes */
  289.     foreach ($this->em->getRepository(Minutes::class)->findBy($criteria) as $minute) {
  290.       if ($minute) {
  291.         $counter++;
  292.         $this->em->remove($minute);
  293.         $this->em->flush();
  294.       }
  295.     }
  296.     /** @var RedCards $redCards */
  297.     foreach ($this->em->getRepository(RedCards::class)->findBy($criteria) as $redCard) {
  298.       if ($redCard) {
  299.         $counter++;
  300.         $this->em->remove($redCard);
  301.         $this->em->flush();
  302.       }
  303.     }
  304.     /** @var Goals $goals */
  305.     foreach ($this->em->getRepository(Goals::class)->findBy($criteria) as $goal) {
  306.       if ($goal) {
  307.         $counter++;
  308.         $this->em->remove($goal);
  309.         $this->em->flush();
  310.       }
  311.     }
  312.     /** @var GoalAssistances $goalAssistances */
  313.     foreach ($this->em->getRepository(GoalAssistances::class)->findBy($criteria) as $goalAssistance) {
  314.       if ($goalAssistance) {
  315.         $counter++;
  316.         $this->em->remove($goalAssistance);
  317.         $this->em->flush();
  318.       }
  319.     }
  320.     /** @var Titulars $titulars */
  321.     foreach ($this->em->getRepository(Titulars::class)->findBy($criteria) as $titulars) {
  322.       if ($titulars) {
  323.         $counter++;
  324.         $this->em->remove($titulars);
  325.         $this->em->flush();
  326.       }
  327.     }
  328.     /** @var KilometersTraveled $titulars */
  329.     foreach ($this->em->getRepository(KilometersTraveled::class)->findBy($criteria) as $kilometers) {
  330.       if ($kilometers) {
  331.         $counter++;
  332.         $this->em->remove($kilometers);
  333.         $this->em->flush();
  334.       }
  335.     }
  336.     /** @var ShotsOnGoal $titulars */
  337.     foreach ($this->em->getRepository(ShotsOnGoal::class)->findBy($criteria) as $shotsOnGoal) {
  338.       if ($shotsOnGoal) {
  339.         $counter++;
  340.         $this->em->remove($shotsOnGoal);
  341.         $this->em->flush();
  342.       }
  343.     }
  344.     /** @var GamePlayerStatistics $titulars */
  345.     foreach ($this->em->getRepository(GamePlayerStatistics::class)->findBy($criteria) as $gamePlayerStatistc) {
  346.       if ($gamePlayerStatistc) {
  347.         $this->em->remove($gamePlayerStatistc);
  348.         $this->em->flush();
  349.       }
  350.     }
  351.     /** @var MediaGame $titulars */
  352.     foreach ($this->em->getRepository(MediaGame::class)->findBy($criteria) as $mediaGame) {
  353.       if ($mediaGame) {
  354.         $media $mediaGame->__toArray($urlFiles);
  355.         $fileSystem = new Filesystem();
  356.         $fileSystem->remove($media);
  357.         $this->em->remove($mediaGame);
  358.         $this->em->flush();
  359.       }
  360.     }
  361.     $this->em->remove($game);
  362.     $this->em->flush();
  363.     return [
  364.       "deleted" => $counter,
  365.       "messageType" => "success",
  366.       "message" => $this->translator->trans('msg.remove_game_permanent_success'),
  367.       "code" => 200
  368.     ];
  369.   }
  370.   public function editLineUp($id$lineup)
  371.   {
  372.     /** @var Customer $customer */
  373.     $customer $this->security->getUser();
  374.     $season $customer->getSeasonActive();
  375.     if (empty($season))
  376.       return [
  377.         "messageType" => "danger",
  378.         "message" => $this->translator->trans('msg.season_dont_active'),
  379.         "code" => 403
  380.       ];
  381.     // foreach ($alignment as $playerId => $info) {
  382.     //   /** @var SeasonPlayer $seasonPlayer */
  383.     //   $seasonPlayer = $this->em->getRepository(SeasonPlayer::class)->find($playerId);
  384.     //   $minutes = $seasonPlayer->getMinutes();
  385.     //   $minutes = json_decode($minutes, true);
  386.     //   $minutes[$id] = (int) $info->minutes;
  387.     //   $minutes = json_encode($minutes);
  388.     //   $seasonPlayer->setMinutes($minutes);
  389.     //   $this->em->persist($seasonPlayer);
  390.     //   $this->em->flush();
  391.     // }
  392.     /** @var Game $game */
  393.     $game $this->em->getRepository(Game::class)->find($id);
  394.     $game->setLineup($lineup);
  395.     $this->em->persist($game);
  396.     $this->em->flush();
  397.     return [
  398.       "messageType" => "success",
  399.       "message" => $this->translator->trans('msg.alignment_success'),
  400.       "code" => 200
  401.     ];
  402.   }
  403.   public function editAlignment($id$alignment)
  404.   {
  405.     /** @var Customer $customer */
  406.     $customer $this->security->getUser();
  407.     $season $customer->getSeasonActive();
  408.     if (empty($season))
  409.       return [
  410.         "messageType" => "danger",
  411.         "message" => $this->translator->trans('msg.season_dont_active'),
  412.         "code" => 403
  413.       ];
  414.     /** @var Game $game */
  415.     $game $this->em->getRepository(Game::class)->find($id);
  416.     /** @var GameAlignment $gameAlignment */
  417.     $gameAlignment $game->getAlignment();
  418.     if (isset($gameAlignment)) {
  419.       $gameAlignment->setTactic($alignment['tactic']);
  420.       $gameAlignment->setAlignment($alignment['alignment']);
  421.     } else {
  422.       $gameAlignment = new GameAlignment();
  423.       $gameAlignment->setTactic($alignment['tactic']);
  424.       $gameAlignment->setAlignment($alignment['alignment']);
  425.       $gameAlignment->setGame($game);
  426.     }
  427.     $this->em->persist($gameAlignment);
  428.     $this->em->flush();
  429.     return [
  430.       "messageType" => "success",
  431.       "message" => $this->translator->trans('msg.alignment_success'),
  432.       "code" => 200
  433.     ];
  434.   }
  435.   public function editConvocatoria($game$players)
  436.   {
  437.     /** @var Customer $customer */
  438.     $customer $this->security->getUser();
  439.     $season $customer->getSeasonActive();
  440.     if (empty($season))
  441.       return [
  442.         "messageType" => "danger",
  443.         "message" => $this->translator->trans('msg.season_dont_active'),
  444.         "code" => 403
  445.       ];
  446.     $filter = [
  447.       "season" => $season->getId(),
  448.       "id" => $game
  449.     ];
  450.     /** @var Game $game */
  451.     $convocatoriaPlayerRepository $this->em->getRepository(ConvocatoriaPlayer::class);
  452.     $game $this->em->getRepository(Game::class)->findOneBy($filter);
  453.     if (!empty($game) && !empty($players)) {
  454.       /** @var Convocatoria $convocatoria */
  455.       $convocatoria $game->getConvocatoria();
  456.       if (empty($convocatoria)) {
  457.         $convocatoria = new Convocatoria();
  458.         $convocatoria->setGame($game);
  459.         $this->em->persist($convocatoria);
  460.         $this->em->flush();
  461.         $this->em->clear();
  462.         $convocatoriaId $convocatoria->getId();
  463.       } else {
  464.         $convocatoriaId $convocatoria->getId();
  465.         $convocatoriaPlayers $convocatoriaPlayerRepository->findBy([
  466.           'convocatoria_id' => $convocatoriaId,
  467.         ]);
  468.         $convocatoria $game->getConvocatoria();
  469.         /**
  470.          * SI NO ESTA EL JUGADOR EN LA CONVOCATORIA ENTRATE, SE ELIMINA
  471.          */
  472.         foreach ($convocatoriaPlayers as $player) {
  473.           if (!in_array($player->getPlayerId(), array_column($players'id'))) {
  474.             $this->em->remove($player);
  475.           }
  476.         }
  477.       }
  478.       $playerRepository $this->em->getRepository(Player::class);
  479.       foreach ($players as $p) {
  480.         /** @var Player $player */
  481.         $player $playerRepository->find($p["id"]);
  482.         if ($player) {
  483.           /** @var ConvocatoriaPlayer $convocatoriaPlayer */
  484.           $convocatoriaPlayer $convocatoriaPlayerRepository->findOneBy([
  485.             'player_id' => $p['id'],
  486.             'convocatoria_id' => $convocatoriaId,
  487.           ]);
  488.           if (empty($convocatoriaPlayer)) {
  489.             $convocatoriaPlayer = new ConvocatoriaPlayer;
  490.             $convocatoriaPlayer->setPlayerId($p['id']);
  491.             $convocatoriaPlayer->setConvocatoriaId($convocatoriaId);
  492.           }
  493.           $isOn true;
  494.           /** @var JustificationType $justificationType */
  495.           $justificationType $this->em->getRepository(JustificationType::class)->find($p['justification_type']);
  496.           if (isset($p['is_active'])) {
  497.             //INPUT DE FORMDATA
  498.             $isOn $p['is_active'];
  499.             // $justificationType = null;
  500.             if (intval($isOn) == && intval($p['justification_type']) > 0) {
  501.               // $justificationType = $p['justification_type'];
  502.             }
  503.           }
  504.         }
  505.         $convocatoriaPlayer->setIsActive($isOn);
  506.         $convocatoriaPlayer->setJustificationType($justificationType);
  507.         $this->em->persist($convocatoriaPlayer);
  508.       }
  509.     }
  510.     $this->em->flush();
  511.     return [
  512.       "messageType" => "success",
  513.       "message" => $this->translator->trans('msg.convocatoria_success'),
  514.       "code" => 200
  515.     ];
  516.   }
  517.   public function editTraining($date$players)
  518.   {
  519.     /** @var Customer $customer */
  520.     $customer $this->security->getUser();
  521.     $season $customer->getSeasonActive();
  522.     if (empty($season))
  523.       return [
  524.         "messageType" => "danger",
  525.         "message" => $this->translator->trans('msg.season_dont_active'),
  526.         "code" => 403
  527.       ];
  528.     $date = \DateTime::createFromFormat("d-m-Y"$date);
  529.     $filter = [
  530.       "season" => $season->getId(),
  531.       "date" => $date
  532.     ];
  533.     /** @var Game $game */
  534.     $trainingAsist $this->em->getRepository(TrainingAsist::class)->findOneBy($filter);
  535.     if (empty($trainingAsist)) {
  536.       $trainingAsist = new TrainingAsist();
  537.       $trainingAsist->setSeason($season)
  538.         ->setDate($date);
  539.     }
  540.     if (!empty($players)) {
  541.       foreach ($players as $p) {
  542.         /** @var Player $player */
  543.         $player $this->em->getRepository(Player::class)->find($p["id"]);
  544.         if (!empty($player)) {
  545.           if ($p["in"]) {
  546.             if (!$trainingAsist->getPlayers()->contains($player))
  547.               $trainingAsist->addPlayer($player);
  548.           } else {
  549.             if ($trainingAsist->getPlayers()->contains($player))
  550.               $trainingAsist->removePlayer($player);
  551.           }
  552.           if (isset($p['justification'])) {
  553.             $subfilter = [
  554.               "date" => $date,
  555.               "player" => $player->getId()
  556.             ];
  557.             /** @var PlayerJustification $playerJustification */
  558.             $playerJustification $this->em->getRepository(PlayerJustification::class)->findOneBy($subfilter);
  559.             /** @var JustificationType $justificationType */
  560.             $justificationType $this->em->getRepository(JustificationType::class)->find($p['justification']['id']);
  561.             if (empty($playerJustification)) {
  562.               $playerJustification = new PlayerJustification();
  563.               $playerJustification->setJustificationType($justificationType);
  564.               $playerJustification->setPlayer($player);
  565.               $playerJustification->setIsActive(true);
  566.               $playerJustification->setDate($date);
  567.               $playerJustification->setSeason($season);
  568.             } else {
  569.               $playerJustification->setJustificationType($justificationType);
  570.             }
  571.             $this->em->persist($playerJustification);
  572.             $this->em->flush();
  573.           }
  574.         }
  575.       }
  576.       $this->em->persist($trainingAsist);
  577.       $this->em->flush();
  578.     }
  579.     return [
  580.       "messageType" => "success",
  581.       "message" => $this->translator->trans('msg.training_edit_success'),
  582.       "code" => 200
  583.     ];
  584.   }
  585.   protected function validGame($data)
  586.   {
  587.     $code 200;
  588.     $validates = [];
  589.     if (empty($data["rival"])) {
  590.       $code 404;
  591.       $validates["rival"] = [
  592.         "type" => "error",
  593.         "msg" => "El nombre de rival es requerido",
  594.         "icon" => "glyphicon-warning-sign",
  595.       ];
  596.     }
  597.     if (empty($data["localityId"])) {
  598.       $code 404;
  599.       $validates["localityId"] = [
  600.         "type" => "error",
  601.         "msg" => "La localia es requerida",
  602.         "icon" => "glyphicon-warning-sign",
  603.       ];
  604.     }
  605.     if (empty($data["day"])) {
  606.       $code 404;
  607.       $validates["day"] = [
  608.         "type" => "error",
  609.         "msg" => "La jornada es requerida",
  610.         "icon" => "glyphicon-warning-sign",
  611.       ];
  612.     }
  613.     if (empty($data["date"])) {
  614.       $code 404;
  615.       $validates["date"] = [
  616.         "type" => "error",
  617.         "msg" => "La fecha es requerida",
  618.         "icon" => "glyphicon-warning-sign",
  619.       ];
  620.     }
  621.     if (!isset($data["goals"]) || is_null($data["goals"])) {
  622.       $code 404;
  623.       $validates["goals"] = [
  624.         "type" => "error",
  625.         "msg" => "Los goles son requeridos",
  626.         "icon" => "glyphicon-warning-sign",
  627.       ];
  628.     }
  629.     if (!isset($data["rivalGoals"]) || is_null($data["rivalGoals"])) {
  630.       $code 404;
  631.       $validates["rivalGoals"] = [
  632.         "type" => "error",
  633.         "msg" => "Los goles son requeridos",
  634.         "icon" => "glyphicon-warning-sign",
  635.       ];
  636.     }
  637.     return [
  638.       "code" => $code,
  639.       "messageType" => "warning",
  640.       "message" => $this->translator->trans('msg.filed_requiered'),
  641.       "validates" => $validates
  642.     ];
  643.   }
  644.   public function reconcileTitulars(Game $game)
  645.   {
  646.     /** @var GameAlignment $gameAlignment */
  647.     $gameAlignment $game->getAlignment();
  648.     if ($gameAlignment) {
  649.       $alignments json_decode((string) $gameAlignment->getAlignment());
  650.       if (JSON_ERROR_NONE !== json_last_error()) {
  651.         return false;
  652.       }
  653.       /** [[{id:0},{id:0}],[{id:0}]] */
  654.       foreach ($alignments as $alignment) {
  655.         /** [{id:0},{id:0}] */
  656.         foreach ($alignment as $player) {
  657.           if (isset($player['id']) && $player['id'] > 0) {
  658.             /** @var SeasonPlayer $seasonPlayer */
  659.             $seasonPlayer $this->em->getRepository(SeasonPlayer::class)->find($player['id']);
  660.             $titular $this->em->getRepository(Titulars::class)->findOneBy([
  661.               "seasonplayer" => $seasonPlayer,
  662.               "game" => $game
  663.             ]);
  664.             if ($titular) {
  665.               $titular->setIsTitular(true);
  666.               $this->em->persist($titular);
  667.             }
  668.           }
  669.         }
  670.       }
  671.       $this->em->flush();
  672.     }
  673.     return true;
  674.   }
  675. }