src/Controller/Api/ReportController.php line 254

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Competition;
  4. use App\Entity\Titulars;
  5. use App\Entity\Game;
  6. use App\Entity\ConvocatoriaPlayer;
  7. use App\Entity\Customer;
  8. use App\Entity\Exercise;
  9. use App\Entity\ExerciseCalendar;
  10. use App\Entity\GamePlayerStatistics;
  11. use App\Entity\JustificationType;
  12. use App\Entity\NoteCalendar;
  13. use App\Entity\Player;
  14. use App\Entity\PlayerJustification;
  15. use App\Entity\SeasonPlayer;
  16. use App\Entity\Season;
  17. use App\Entity\Strategy;
  18. use App\Entity\TrainingAsist;
  19. use App\Helper\MpdfHelper;
  20. use App\Helper\SelectTranslate;
  21. use App\Repository\PlayerRepository;
  22. use App\Services\Api\PlayerManager;
  23. use DateTime;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  26. use Symfony\Component\HttpFoundation\JsonResponse;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Mpdf\HTMLParserMode;
  30. use Symfony\Contracts\Translation\TranslatorInterface;
  31. class ReportController extends ApiController
  32. {
  33.   /** @var PlayerManager $playerManager */
  34.   protected $playerManager;
  35.   protected $translator;
  36.   /**
  37.    * @param PlayerManager $playerManager
  38.    */
  39.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagPlayerManager $playerManagerTranslatorInterface $translator)
  40.   {
  41.     parent::__construct($em$parameterBag);
  42.     $this->playerManager $playerManager;
  43.     $this->translator $translator;
  44.   }
  45.   /**
  46.    * @param Request $request
  47.    * @return JsonResponse
  48.    *
  49.    * @Route("/report/players", name="api_player_report_squad", methods={"POST"})
  50.    */
  51.   public function reportSquad(Request $request)
  52.   {
  53.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  54.     $prefixFile $this->getParameter("app.path.player_images");
  55.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  56.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  57.     $imagePathCustomer =  $prefixFileCustomer "/";
  58.     /** @var Customer $customer */
  59.     $customer $this->getUser();
  60.     $season $customer->getSeasonActive();
  61.     $players = [];
  62.     $filter = [
  63.       "season" => $season->getId()
  64.     ];
  65.     /** @var PlayerRepository $playerRepository */
  66.     $playerRepository $this->em->getRepository(Player::class);
  67.     $seasonArray $season->__toArray($imagePathCustomer);
  68.     $seasonArray['customerName'] = $customer->getName();
  69.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  70.     $seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 03));
  71.     foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
  72.       $player $seasonPlayer->getPlayer();
  73.       $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  74.       $isActive $player->getIsActive();
  75.       if ($isActive && $seasonPlayerActive) {
  76.         $playerArr $player->__toArray($baseurl $prefixFile "/");
  77.         $miscellaneous $playerRepository->getStatsMiscellaneous($player$season);
  78.         $player = [
  79.           "dorsal" => $seasonPlayer->getDorsal(),
  80.           "games" => intval($miscellaneous['countPlayed'] ?? 0),
  81.           "goals" => intval($miscellaneous['goals'] ?? 0),
  82.           "image" => !empty($player->getImage()) ?  $prefixFile "/" $player->getImage() : null,
  83.         ];
  84.         $player["shortName"] = strtoupper(substr($playerArr['lastname'], 01) . substr($playerArr['name'], 01));
  85.         if ($player['image']) {
  86.           $player['image'] = realpath('.' $player['image']);
  87.         }
  88.         $players[] = array_merge($playerArr$player);
  89.       }
  90.     }
  91.     $bootstrap file_get_contents(realpath('./design/css/bootstrap.min.css'));
  92.     $mpdf MpdfHelper::Mpdf();
  93.     $html $this->renderView('reports/players_squad.html.twig', [
  94.       'players' => $players,
  95.       'season'  => $seasonArray,
  96.       'bootstrap' => $bootstrap,
  97.     ]);
  98.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  99.     $mpdf->WriteHTML($html);
  100.     $mpdf->output();
  101.     exit(0);
  102.   }
  103.   /**
  104.    * @param Request $request
  105.    * @return JsonResponse
  106.    *
  107.    * @Route("/report/games/{id}", name="api_report_games_id", methods={"POST"})
  108.    */
  109.   public function getAlignment($idRequest $request)
  110.   {
  111.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  112.     $prefixFilePlayer $this->getParameter("app.path.player_images");
  113.     $prefixFileGame $this->getParameter("app.path.game_images");
  114.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  115.     $imagePathCustomer $prefixFileCustomer "/";
  116.     $imagePathPlayer =  $prefixFilePlayer "/";
  117.     $imagePathGame =  $prefixFileGame "/";
  118.     /** @var Customer $customer */
  119.     $customer $this->getUser();
  120.     /** @var Season $season */
  121.     $season $customer->getSeasonActive();
  122.     $filter = [
  123.       "season" => $season->getId(),
  124.       "id" => $id
  125.     ];
  126.     /** @var Game $game */
  127.     $game $this->em->getRepository(Game::class)->findOneBy($filter);
  128.     $gameArray $game->__toArray($imagePathGame);
  129.     $gameArray['teamNameShort'] = strtoupper(substr($gameArray['rival'], 02));
  130.     if ($gameArray['image'] != "") {
  131.       $gameArray['image'] = realpath('.' $gameArray['image']);
  132.     }
  133.     $filter = [
  134.       "season" => $season->getId()
  135.     ];
  136.     $convocatoria $game->getConvocatoria();
  137.     $convocatoriaPlayerRepository $this->em->getRepository(ConvocatoriaPlayer::class);
  138.     $players = [];
  139.     /** @var PlayerRepository $playerRepository */
  140.     $playerRepository $this->em->getRepository(Player::class);
  141.     foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
  142.       $player $seasonPlayer->getPlayer();
  143.       $playerArr $player->__toArray($imagePathPlayer);
  144.       if ($playerArr['image'] != "") {
  145.         $playerArr['image'] = realpath('.' $playerArr['image']);
  146.       } else {
  147.         $playerArr['image'] = false;
  148.       }
  149.       $isActive $player->getIsActive();
  150.       $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  151.       if (!$isActive || !$seasonPlayerActive) {
  152.         continue;
  153.       }
  154.       $criteria = [
  155.         "seasonplayer" => $seasonPlayer,
  156.         "game" => $game
  157.       ];
  158.       /** @var GamePlayerStatistics $statists */
  159.       $statists $this->em->getRepository(GamePlayerStatistics::class)->findOneBy($criteria);
  160.       $isTitular $statists $statists->getIsTitular() : false;
  161.       $goals $statists $statists->getGoals() : 0;
  162.       $yellowCards $statists $statists->getYellowCards() : 0;
  163.       $redCards $statists $statists->getRedCards() : 0;
  164.       $minutes $statists $statists->getMinutes() : 0;
  165.       $out = [
  166.         "dorsal" => $seasonPlayer->getDorsal(),
  167.         "goals" => $goals,
  168.         "yellowCards" => $yellowCards,
  169.         "redCards" => $redCards,
  170.         "minutes" => $minutes,
  171.         "isTitular" => $isTitular,
  172.         "shortName" => strtoupper(substr($playerArr['lastname'], 01) . substr($playerArr['name'], 01)),
  173.       ];
  174.       if ($convocatoria) {
  175.         /** @var ConvocatoriaPlayer $convocatoriaPlayer */
  176.         $convocatoriaPlayer $convocatoriaPlayerRepository->findOneBy([
  177.           "player_id" => $player->getId(),
  178.           "convocatoria_id" => $convocatoria->getId(),
  179.         ]);
  180.         if ($convocatoriaPlayer) {
  181.           $out array_merge($out, [
  182.             "isOn" => $convocatoriaPlayer->getIsActive(),
  183.           ], $convocatoriaPlayer->__toArray());
  184.           $players[] = array_merge($playerArr$out);
  185.         }
  186.       }
  187.     }
  188.     $seasonArray $season->__toArray($imagePathCustomer);
  189.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  190.     $seasonArray['appLogo'] = realpath('./assets/img/logo-only-line.png');
  191.     $seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 02));
  192.     $bootstrap file_get_contents(realpath('./design/css/bootstrap.min.css'));
  193.     $mpdf MpdfHelper::Mpdf();
  194.     $html $this->renderView('reports/games_one.html.twig', [
  195.       'game'                  => $gameArray,
  196.       'players'               => $players,
  197.       'bootstrap'             => $bootstrap,
  198.       'team'                  => $season->getTeam(),
  199.       'season'                => $seasonArray,
  200.     ]);
  201.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  202.     $separador explode('-----------------separator-----------------'$html);
  203.     foreach ($separador as $key => $value) {
  204.       if ($key === count($separador)) {
  205.         $mpdf->AddPage();
  206.         $mpdf->WriteHTML($value);
  207.       } else {
  208.         $mpdf->WriteHTML($value);
  209.       }
  210.     }
  211.     $mpdf->output();
  212.     exit(0);
  213.   }
  214.   /**
  215.    * @param Request $request
  216.    * @return JsonResponse
  217.    * @Route("/report/game/convocatoria/{gameId}", name="api_player_report_convocatoria", methods={"POST"})
  218.    */
  219.   public function reportGameAnnouncement($gameIdRequest $request)
  220.   {
  221.     $prefixFile $this->getParameter("app.path.player_images");
  222.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  223.     $prefixFilePlayer $this->getParameter("app.path.player_images");
  224.     $prefixFileGame $this->getParameter("app.path.game_images");
  225.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  226.     $imagePathCustomer =  $prefixFileCustomer "/";
  227.     $imagePathPlayer =  $prefixFilePlayer "/";
  228.     $imagePathGame =  $prefixFileGame "/";
  229.     /** @var Customer $customer */
  230.     $customer $this->getUser();
  231.     $season $customer->getSeasonActive();
  232.     $game $this->em->getRepository(Game::class)->find($gameId);
  233.     $gameArray $game->__toArray($imagePathGame);
  234.     $convocatoria $game->getConvocatoria();
  235.     $filter = [
  236.       "season" => $season->getId()
  237.     ];
  238.     /** @var PlayerRepository $playerRepository */
  239.     $playerRepository $this->em->getRepository(Player::class);
  240.     $seasonArray $season->__toArray($imagePathCustomer);
  241.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  242.     $seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 03));
  243.     $seasonArray['customerName'] = $customer->getName() . " " .  $customer->getSurname();
  244.     if ($game) {
  245.       $convocatoriaPlayerRepository $this->em->getRepository(ConvocatoriaPlayer::class);
  246.       /** @var SeasonPlayer $seasonPlayer */
  247.       foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter, ["dorsal" => "ASC"]) as $seasonPlayer) {
  248.         $player $seasonPlayer->getPlayer();
  249.         $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  250.         $isActive $player->getIsActive();
  251.         $playerArr $player->__toArray($imagePathPlayer);
  252.         $miscellaneous $playerRepository->getStatsMiscellaneous($player$season);
  253.         if ($isActive && $seasonPlayerActive) {
  254.           $out = [
  255.             "id" => $player->getId(),
  256.             "seasonPlayer_id" => $seasonPlayer->getId(),
  257.             "dorsal" => $seasonPlayer->getDorsal(),
  258.             "name" => $player->getName(),
  259.             "lastname" => $player->getLastname(),
  260.             "position" => !empty($player->getPosition()) ? $player->getPosition()->getSlugTranslation() : "",
  261.             "image" => $player->getImage() ? realpath("." $prefixFile "/" $player->getImage())  : false,
  262.             "gameAlignment" => intval($miscellaneous['gameAlignment'] ?? 0),
  263.             "countryId" => !empty($player->getCountry()) ? $player->getCountry()->getId() : null,
  264.           ];
  265.           if ($convocatoria) {
  266.             $convocatoriaPlayer $convocatoriaPlayerRepository->findOneBy([
  267.               "player_id" => $player->getId(),
  268.               "convocatoria_id" => $convocatoria->getId(),
  269.             ]);
  270.             if ($convocatoriaPlayer) {
  271.               $out array_merge($out, [
  272.                 "isOn" => $convocatoriaPlayer->getIsActive(),
  273.                 "in" => $convocatoriaPlayer->getIsActive(),
  274.               ], $convocatoriaPlayer->__toArray());
  275.             } else {
  276.               $out array_merge($out, [
  277.                 "isOn" => false,
  278.                 "in" => false,
  279.                 "justification_type" => null,
  280.                 "is_active" => null,
  281.               ]);
  282.             }
  283.           } else {
  284.             $out array_merge($out, [
  285.               "isOn" => false,
  286.               "in" => false,
  287.               "justification_type" => null,
  288.               "is_active" => null,
  289.             ]);
  290.           }
  291.           if ($out["isOn"]) {
  292.             $out["shortName"] = strtoupper(substr($playerArr['lastname'], 01) . substr($playerArr['name'], 01));
  293.             $players[] = array_merge($playerArr$out);
  294.           }
  295.         }
  296.       }
  297.     }
  298.     $bootstrap file_get_contents(realpath('./design/css/bootstrap.min.css'));
  299.     $mpdf MpdfHelper::Mpdf();
  300.     $html $this->renderView('reports/game_announcement.html.twig', [
  301.       'game'                  => $gameArray,
  302.       'players'               => $players,
  303.       'bootstrap'             => $bootstrap,
  304.       'team'                  => $season->getTeam(),
  305.       'season'                => $seasonArray,
  306.     ]);
  307.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  308.     $mpdf->WriteHTML($html);
  309.     $mpdf->output();
  310.     exit(0);
  311.   }
  312.   /**
  313.    * @param Request $request
  314.    * @return JsonResponse
  315.    *
  316.    * @Route("report/exercise/calendar/{date}/get", name="api_report_exercise_calendar_get", methods={"POST"})
  317.    */
  318.   public function calendarExercisesGet($dateRequest $request)
  319.   {
  320.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  321.     $prefixFile $this->getParameter("app.path.exercise_images");
  322.     $date = \DateTime::createFromFormat("d-m-Y"$date);
  323.     /** @var Customer $customer */
  324.     $customer $this->getUser();
  325.     $season $customer->getSeasonActive();
  326.     $seasonArray $season->__toArray($prefixFileCustomer '/');
  327.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  328.     $exercises = [];
  329.     if (!empty($season)) {
  330.       $filter = [
  331.         'season' => $season->getId(),
  332.         'date' => $date,
  333.       ];
  334.       /** @var ExerciseCalendar $exerciseCalendar */
  335.       foreach ($this->em->getRepository(ExerciseCalendar::class)->findBy($filter) as $exerciseCalendar) {
  336.         $exercise $exerciseCalendar->getExercise();
  337.         $exercise $exercise->__toArray($prefixFile '/');
  338.         $poster =  empty($exercise['poster']) ? $exercise['image']  : $exercise['poster'];
  339.         $exercise['poster'] = rawurlencode(realpath("./" $poster));
  340.         $exercise['description'] = str_replace("\n"""$exercise['description']);
  341.         $maxLength 200;
  342.         if (strlen($exercise['description']) > $maxLength) {
  343.             $exercise['description'] = substr($exercise['description'], 0$maxLength) . '...';
  344.         }
  345.         $exercises[] = $exercise;
  346.       }
  347.     }
  348.     $intensityIcon realpath('./assets/img/intensity.png');
  349.     $durationIcon realpath('./assets/img/time.png');
  350.     $difficultyIcon realpath('./assets/img/intensity.png');
  351.     $icons = [
  352.       'intensity' => $intensityIcon,
  353.       'duration' => $durationIcon,
  354.       'difficulty' => $difficultyIcon
  355.     ];
  356.     $notesRepository $this->em->getRepository(NoteCalendar::class);
  357.     $filterNotes = [
  358.       'season' => $season,
  359.       'date' => $date,
  360.     ];
  361.     $generalObjetives = [];
  362.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_GENERAL_OBJECTIVES])) as $value) {
  363.       $generalObjetives[] = $value->__toArray();
  364.     }
  365.     $physicalObjeties = [];
  366.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_PHYSICAL_TARGETS])) as $value) {
  367.       $physicalObjeties[] = $value->__toArray();
  368.     }
  369.     $tacticObjeties = [];
  370.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_TACTIC_OBJETIVES])) as $value) {
  371.       $tacticObjeties[] = $value->__toArray();
  372.     }
  373.     $warmUpObjeties = [];
  374.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_WARM_UP_OBJETIVES])) as $value) {
  375.       $warmUpObjeties[] = $value->__toArray();
  376.     }
  377.     $objetives = [
  378.       'generals' => $generalObjetives,
  379.       'physicals' => $physicalObjeties,
  380.       'tactics' => $tacticObjeties,
  381.       'warm_up' => $warmUpObjeties
  382.     ];
  383.     $html $this->renderView('reports/exercise_date_day_customer.html.twig', [
  384.       'exercises' => $exercises,
  385.       'season' => $seasonArray,
  386.       'date' => $date->format('d M Y'),
  387.       'objetives' => $objetives,
  388.       'icons' => $icons
  389.     ]);
  390.     $bootstrap file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
  391.     $monserrat file_get_contents(realpath('./design/css/monserrat.css'));
  392.     $mpdf MpdfHelper::Mpdf();
  393.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  394.     $mpdf->WriteHTML($monserratHTMLParserMode::HEADER_CSS);
  395.     $separador explode('-----------------separator-----------------'$html);
  396.     // logic paginate
  397.     $numberPage 1;
  398.     $beforeStrLong 0;
  399.     $columsPrint 0;
  400.     $aumentNumberPage false;
  401.     $aumentNumberColums false;
  402.     foreach ($separador as $key => $value) {
  403.       $str_long strlen($value);
  404.       if ($numberPage == 2) {
  405.         if ($columsPrint == 0) {
  406.           $mpdf->WriteHTML($value);
  407.           $beforeStrLong $str_long;
  408.           $aumentNumberColums true;
  409.         }
  410.         if ($columsPrint == 1) {
  411.           $mpdf->WriteHTML($value);
  412.           $beforeStrLong $str_long $beforeStrLong;
  413.           $aumentNumberColums true;
  414.         }
  415.         if ($columsPrint == && ($str_long $beforeStrLong) < 14000) {
  416.           $mpdf->WriteHTML($value);
  417.           $mpdf->AddPage();
  418.           $columsPrint 0;
  419.           $beforeStrLong 0;
  420.         }
  421.         if ($columsPrint == && ($str_long $beforeStrLong) > 14000) {
  422.           $mpdf->AddPage();
  423.           $mpdf->WriteHTML($value);
  424.           $columsPrint 0;
  425.           $beforeStrLong 0;
  426.         }
  427.       }
  428.       if ($numberPage == && $key <= && $beforeStrLong 3500 && $str_long 4706) {
  429.         $mpdf->WriteHTML($value);
  430.         if ($key == 1) {
  431.           $aumentNumberPage true;
  432.           $mpdf->AddPage();
  433.         }
  434.         $beforeStrLong $str_long;
  435.       }
  436.       if ($aumentNumberPage) {
  437.         $numberPage $numberPage 1;
  438.         $aumentNumberPage false;
  439.       }
  440.       if ($aumentNumberColums) {
  441.         $columsPrint $columsPrint 1;
  442.         $aumentNumberColums false;
  443.       }
  444.       if ($columsPrint == && ($str_long $beforeStrLong) < 14000) {
  445.         $beforeStrLong $str_long $beforeStrLong;
  446.       }
  447.     }
  448.     $mpdf->output();
  449.     exit(0);
  450.   }
  451.     /**
  452.    * @param Request $request
  453.    * @return JsonResponse
  454.    *
  455.    * @Route("report/exercise/calendar/{date}/get/test", name="api_report_exercise_calendar_get_test", methods={"POST"})
  456.    */
  457.   public function calendarExercisesGetTest($dateRequest $request)
  458.   {
  459.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  460.     $prefixFile $this->getParameter("app.path.exercise_images");
  461.     $date = \DateTime::createFromFormat("d-m-Y"$date);
  462.     /** @var Customer $customer */
  463.     $customer $this->getUser();
  464.     $season $customer->getSeasonActive();
  465.     $seasonArray $season->__toArray($prefixFileCustomer '/');
  466.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  467.     $exercises = [];
  468.     if (!empty($season)) {
  469.       $filter = [
  470.         'season' => $season->getId(),
  471.         'date' => $date,
  472.       ];
  473.       /** @var ExerciseCalendar $exerciseCalendar */
  474.       foreach ($this->em->getRepository(ExerciseCalendar::class)->findBy($filter) as $exerciseCalendar) {
  475.         $exercise $exerciseCalendar->getExercise();
  476.         
  477.         $exercise $exercise->__toArray($prefixFile '/');
  478.         $poster =  empty($exercise['poster']) ? $exercise['image']  : $exercise['poster'];
  479.         $exercise['poster'] = rawurlencode(realpath("./" $poster));
  480.         $exercise['description'] = 'hello';
  481.         $exercises[] = $exercise;
  482.       }
  483.     }
  484.     $intensityIcon realpath('./assets/img/intensity.png');
  485.     $durationIcon realpath('./assets/img/time.png');
  486.     $difficultyIcon realpath('./assets/img/intensity.png');
  487.     $icons = [
  488.       'intensity' => $intensityIcon,
  489.       'duration' => $durationIcon,
  490.       'difficulty' => $difficultyIcon
  491.     ];
  492.     $notesRepository $this->em->getRepository(NoteCalendar::class);
  493.     $filterNotes = [
  494.       'season' => $season,
  495.       'date' => $date,
  496.     ];
  497.     $generalObjetives = [];
  498.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_GENERAL_OBJECTIVES])) as $value) {
  499.       $generalObjetives[] = $value->__toArray();
  500.     }
  501.     $physicalObjeties = [];
  502.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_PHYSICAL_TARGETS])) as $value) {
  503.       $physicalObjeties[] = $value->__toArray();
  504.     }
  505.     $tacticObjeties = [];
  506.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_TACTIC_OBJETIVES])) as $value) {
  507.       $tacticObjeties[] = $value->__toArray();
  508.     }
  509.     $warmUpObjeties = [];
  510.     foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_WARM_UP_OBJETIVES])) as $value) {
  511.       $warmUpObjeties[] = $value->__toArray();
  512.     }
  513.     $objetives = [
  514.       'generals' => $generalObjetives,
  515.       'physicals' => $physicalObjeties,
  516.       'tactics' => $tacticObjeties,
  517.       'warm_up' => $warmUpObjeties
  518.     ];
  519.     $result = [
  520.       'exercises' => $exercises,
  521.       'season' => $seasonArray,
  522.       'date' => $date->format('d M Y'),
  523.       'objetives' => $objetives,
  524.       'icons' => $icons
  525.     ];
  526.     
  527.     return $this->response($result);
  528.     // $html = $this->renderView('reports/exercise_date_day_customer.html.twig', [
  529.     //   'exercises' => $exercises,
  530.     //   'season' => $seasonArray,
  531.     //   'date' => $date->format('d M Y'),
  532.     //   'objetives' => $objetives,
  533.     //   'icons' => $icons
  534.     // ]);
  535.     // $bootstrap = file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
  536.     // $monserrat = file_get_contents(realpath('./design/css/monserrat.css'));
  537.     // $mpdf = MpdfHelper::Mpdf();
  538.     // $mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
  539.     // $mpdf->WriteHTML($monserrat, HTMLParserMode::HEADER_CSS);
  540.     // $separador = explode('-----------------separator-----------------', $html);
  541.     // logic paginate
  542.     // $numberPage = 1;
  543.     // $beforeStrLong = 0;
  544.     // $columsPrint = 0;
  545.     // $aumentNumberPage = false;
  546.     // $aumentNumberColums = false;
  547.     // foreach ($separador as $key => $value) {
  548.     //   $str_long = strlen($value);
  549.     //   if ($numberPage == 2) {
  550.     //     if ($columsPrint == 0) {
  551.     //       $mpdf->WriteHTML($value);
  552.     //       $beforeStrLong = $str_long;
  553.     //       $aumentNumberColums = true;
  554.     //     }
  555.     //     if ($columsPrint == 1) {
  556.     //       $mpdf->WriteHTML($value);
  557.     //       $beforeStrLong = $str_long + $beforeStrLong;
  558.     //       $aumentNumberColums = true;
  559.     //     }
  560.     //     if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
  561.     //       $mpdf->WriteHTML($value);
  562.     //       $mpdf->AddPage();
  563.     //       $columsPrint = 0;
  564.     //       $beforeStrLong = 0;
  565.     //     }
  566.     //     if ($columsPrint == 2 && ($str_long + $beforeStrLong) > 14000) {
  567.     //       $mpdf->AddPage();
  568.     //       $mpdf->WriteHTML($value);
  569.     //       $columsPrint = 0;
  570.     //       $beforeStrLong = 0;
  571.     //     }
  572.     //   }
  573.     //   if ($numberPage == 1 && $key <= 1 && $beforeStrLong < 3500 && $str_long < 4706) {
  574.     //     $mpdf->WriteHTML($value);
  575.     //     if ($key == 1) {
  576.     //       $aumentNumberPage = true;
  577.     //       $mpdf->AddPage();
  578.     //     }
  579.     //     $beforeStrLong = $str_long;
  580.     //   }
  581.     //   if ($aumentNumberPage) {
  582.     //     $numberPage = $numberPage + 1;
  583.     //     $aumentNumberPage = false;
  584.     //   }
  585.     //   if ($aumentNumberColums) {
  586.     //     $columsPrint = $columsPrint + 1;
  587.     //     $aumentNumberColums = false;
  588.     //   }
  589.     //   if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
  590.     //     $beforeStrLong = $str_long + $beforeStrLong;
  591.     //   }
  592.     // }
  593.     // $mpdf->output();
  594.     // exit(0);
  595.   }
  596.   
  597.   public function getLetterJustification(int $id): ?string
  598.   {
  599.     $name $this->em->getRepository(JustificationType::class)->find($id)->getName();
  600.     // extraer primera letra
  601.     if (!$name) {
  602.       return null;
  603.     }
  604.     return strtoupper(substr($name01));
  605.   }
  606.   /**
  607.    * @param Request $request
  608.    * @return JsonResponse
  609.    *
  610.    * @Route("report/trainings/{date}/get", name="api_report_training_calendar_get", methods={"POST"})
  611.    */
  612.   public function reportTrainign(Request $requestDateTime $date)
  613.   {
  614.     $trainings = [];
  615.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  616.     $prefixFile $this->getParameter("app.path.player_images");
  617.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  618.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  619.     $imagePathCustomer =  $prefixFileCustomer "/";
  620.     $tmpAvatars = [];
  621.     /** @var Customer $customer */
  622.     $customer $this->getUser();
  623.     $season $customer->getSeasonActive();
  624.     $season $customer->getSeasonActive();
  625.     $dateStart $date->format('Y-m-01');
  626.     $dateEnd $date->format('Y-m-t');
  627.     $playersTemplate = [];
  628.     $seasonArray $season->__toArray($imagePathCustomer);
  629.     $seasonArray['customerName'] = $customer->getName();
  630.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  631.     $seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 03));
  632.     $seasonArray['dateStart'] = $date->format('Y-m-01');
  633.     $seasonArray['dateEnd'] = $date->format('Y-m-t');
  634.     if (!empty($season)) {
  635.       $filter = [
  636.         [
  637.           "prop" => "season",
  638.           "comp" => "=",
  639.           "val" => $season->getId()
  640.         ],
  641.         [
  642.           "prop" => "date",
  643.           "comp" => ">=",
  644.           "val" => $dateStart
  645.         ],
  646.         [
  647.           "prop" => "date",
  648.           "comp" => "<=",
  649.           "val" => $dateEnd
  650.         ],
  651.       ];
  652.       $assists = [];
  653.       $justifycations = [];
  654.       $dates = [];
  655.       $heads = [];
  656.       /** @var TrainingAsist $trainingAsist */
  657.       foreach ($this->em->getRepository(TrainingAsist::class)->findByOwnCriteria($filter) as $trainingAsist) {
  658.         $assists[$trainingAsist->getDate()->format("Y-m-d")] = $trainingAsist->getPlayers()->map(function (Player $player) use ($trainingAsist) {
  659.           return  $player->getId();
  660.         })->toArray();
  661.         $trainings[] = [
  662.           "id" => $trainingAsist->getId(),
  663.           "date" => $trainingAsist->getDate()->format("Y-m-d")
  664.         ];
  665.       }
  666.       // tipos de justificacion
  667.       // lis ids bienen de la base de datos
  668.       // migracion Version20220815252224
  669.       // 1  enfermedad
  670.       // 2  lesion
  671.       // 3  sin justificatiè´¸n
  672.       // 4  viaje
  673.       // 5  estudios
  674.       // 6  sancion
  675.       // 7  dar de baja por lesion
  676.       // 8  tecnico
  677.       // 9  otros
  678.       /** @var PlayerJustification $playerJustification */
  679.       foreach ($this->em->getRepository(PlayerJustification::class)->findByOwnCriteria($filter) as $playerJustification) {
  680.         $justifycations[] = [
  681.           "id" => $playerJustification->getPlayer()->getId(),
  682.           "type" => $playerJustification->getJustificationType()->getId(),
  683.           "letter" => $this->getLetterJustification($playerJustification->getJustificationType()->getId()),
  684.           "date" => $playerJustification->getDate()->format("Y-m-d")
  685.         ];
  686.       }
  687.     }
  688.     $filter = [
  689.       "season" => $season->getId()
  690.     ];
  691.     // se calculan los dias del mes
  692.     for ($i 1$i <= $date->format('t'); $i++) {
  693.       $day $i 10 '0' $i $i;
  694.       $currentDate = new DateTime($date->format('Y-m-' $day));
  695.       $dates[] = $date->format('Y-m-' $day);
  696.       $heads[] = substr($this->translator->trans(SelectTranslate::dayWeek($currentDate->format('D')), [], 'reports'), 01);
  697.     }
  698.     // se marca asistencia en cada dia 
  699.     foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as  $seasonPlayer) {
  700.       $player $seasonPlayer->getPlayer();
  701.       $seasonPlayerActive = !$seasonPlayer->getDeletedAt();
  702.       $isActive $player->getIsActive();
  703.       if ($isActive && $seasonPlayerActive) {
  704.         $dataPlayer =   $player->__toArray($baseurl $prefixFile "/");
  705.         if (!is_null($dataPlayer['image']) && !empty($dataPlayer['image'])) {
  706.           $dataPlayer['image'] = realpath("." $prefixFile "/" $player->getImage());
  707.         } else {
  708.           $dataPlayer['image'] = null;
  709.         }
  710.         $dataPlayer["shortName"] = strtoupper(substr($dataPlayer['lastname'], 01) . substr($dataPlayer['name'], 01));
  711.         $dataPlayer['assists'] = [];
  712.         foreach ($dates as $key => $day) {
  713.           $dataPlayer['assists'][$day] = false;
  714.           foreach ($assists as $key => $value) {
  715.             if ($key === $day) {
  716.               if (in_array($dataPlayer['id'], $value)) {
  717.                 $dataPlayer['assists'][$day] = 'X';
  718.               }
  719.             }
  720.           }
  721.           // se a帽ade la justificacion en caso de tenerla
  722.           foreach ($justifycations as $key => $value) {
  723.             if ($day === $value['date'] && $value['id'] === $dataPlayer['id']) {
  724.               $dataPlayer['assists'][$day] = $value['letter'];
  725.             }
  726.           }
  727.         }
  728.         $playersTemplate[] = $dataPlayer;
  729.       }
  730.     }
  731.     $bootstrap file_get_contents(realpath('./design/css/bootstrap.min.css'));
  732.     $mpdf MpdfHelper::MpdfHorizontal();
  733.     $html $this->renderView('reports/monthly_attendance_report.html.twig', [
  734.       'template'                  => $playersTemplate,
  735.       'assists'               => $assists,
  736.       'bootstrap'             => $bootstrap,
  737.       'team'                  => $season->getTeam(),
  738.       'heads'                  => $heads,
  739.       'season'                => $seasonArray,
  740.     ]);
  741.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  742.     $mpdf->WriteHTML($html);
  743.     $mpdf->output();
  744.     exit(0);
  745.   }
  746.   /**
  747.    * @param Request $request
  748.    * @return JsonResponse
  749.    *
  750.    * @Route("report/stats/{competitionId}/{typeStat}/get", name="api_report_stats_get", methods={"POST"})
  751.    */
  752.   public function reportStats($competitionId$typeStatRequest $request)
  753.   {
  754.     if ($typeStat == 'convocatorias') {
  755.       $typeStat 'convocatoria';
  756.     }
  757.     /** @var Customer $customer */
  758.     $customer $this->getUser();
  759.     $season $customer->getSeasonActive();
  760.     $filter = [
  761.       "season" => $season->getId()
  762.     ];
  763.     $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  764.     $prefixFile $this->getParameter("app.path.player_images");
  765.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  766.     $prefixFile $this->getParameter("app.path.player_images");
  767.     $imagePathCustomer =  $prefixFileCustomer "/";
  768.     $seasonArray $season->__toArray($imagePathCustomer);
  769.     $seasonArray['customerName'] = $customer->getName();
  770.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  771.     $seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 03));
  772.     $players = [];
  773.     $statsKey $typeStat;
  774.     $competitionName $this->translator->trans('general');
  775.     if ($competitionId != 'null') {
  776.       /** @var Competition $competition */
  777.       $competition $this->em->getRepository(Competition::class)->find($competitionId);
  778.       $competitionName $competition->getName();
  779.       $statsKey "${typeStat}_$competitionId";
  780.     }
  781.     /** @var Player $player */
  782.     foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
  783.       /** @var SeasonPlayer $seasonPlayer */
  784.       $player $seasonPlayer->getPlayer();
  785.       /** @var PlayerRepository $playerRepository */
  786.       $playerRepository $this->em->getRepository(Player::class);
  787.       $playerArr $player->__toArray($baseurl $prefixFile "/");
  788.       $playerData["dorsal"] = $seasonPlayer->getDorsal();
  789.       $playerData["name"] = $playerArr['name'];
  790.       $playerData["lastname"] = $playerArr['lastname'];
  791.       $playerData["shortName"] = strtoupper(substr($playerArr['lastname'], 01) . substr($playerArr['name'], 01));
  792.       $miscellaneous $playerRepository->getStatsMiscellaneous($player$season);
  793.       $result $playerRepository->getStatsConvocatoria($player$season);
  794.       $baseData array_merge($playerArr$miscellaneous);
  795.       $statsPlayer array_merge($baseData$result);
  796.       if ($playerArr['image'] != "") {
  797.         $playerData['image'] = realpath('.' $playerArr['image']);
  798.       }
  799.       if ($playerArr['image'] == "") {
  800.         $playerData['image'] = false;
  801.       }
  802.       $playerData["stat"] = intval($statsPlayer[$statsKey]);
  803.       $players[] = $playerData;
  804.     }
  805.     usort($players, function ($a$b) {
  806.       if ($a['stat'] == $b['stat']) return 0;
  807.       if ($a['stat'] < $b['stat']) return -1;
  808.       return 1;
  809.     });
  810.     $endList = [];
  811.     $players array_reverse($players);
  812.     foreach ($players as $key => $value) {
  813.       if ($players[0]['stat'] == || $value['stat'] == 0) {
  814.         $value['graph'] = 0;
  815.       } else {
  816.         $value['graph'] = round(($value['stat'] / $players[0]['stat']) * 10) ?? 0;
  817.       }
  818.       $endList[] = $value;
  819.     }
  820.     $bootstrap file_get_contents(realpath('./design/css/bootstrap.min.css'));
  821.     $mpdf MpdfHelper::Mpdf();
  822.     $html $this->renderView('reports/players_stat_competition.html.twig', [
  823.       'players' => $endList,
  824.       'season'  => $seasonArray,
  825.       'bootstrap' => $bootstrap,
  826.       'typeStat' => $typeStat,
  827.       'competition' => $competitionName,
  828.     ]);
  829.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  830.     $mpdf->WriteHTML($html);
  831.     $mpdf->output();
  832.     exit(0);
  833.   }
  834.   /**
  835.    * @param Request $request
  836.    * @return JsonResponse
  837.    *
  838.    * @Route("report/exercise/{exercise}", name="api_report_exercise", methods={"POST"})
  839.    */
  840.   public function exerciseExport(Exercise $exerciseRequest $request)
  841.   {
  842.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  843.     $prefixFile $this->getParameter("app.path.exercise_images");
  844.     /** @var Customer $customer */
  845.     $customer $this->getUser();
  846.     $season $customer->getSeasonActive();
  847.     $seasonArray $season->__toArray($prefixFileCustomer '/');
  848.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  849.     $exercise $exercise->__toArray($prefixFile '/');
  850.     $poster =  empty($exercise['poster']) ? $exercise['image']  : $exercise['poster'];
  851.     $exercise['poster'] = rawurlencode(realpath("./" $poster));
  852.     $intensityIcon realpath('./assets/img/intensity.png');
  853.     $durationIcon realpath('./assets/img/time.png');
  854.     $difficultyIcon realpath('./assets/img/intensity.png');
  855.     $icons = [
  856.       'intensity' => $intensityIcon,
  857.       'duration' => $durationIcon,
  858.       'difficulty' => $difficultyIcon
  859.     ];
  860.     $html $this->renderView('reports/exercise.html.twig', [
  861.       'exercise' => $exercise,
  862.       'season' => $seasonArray,
  863.       'icons' => $icons
  864.     ]);
  865.     $bootstrap file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
  866.     $monserrat file_get_contents(realpath('./design/css/monserrat.css'));
  867.     $mpdf MpdfHelper::Mpdf();
  868.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  869.     $mpdf->WriteHTML($monserratHTMLParserMode::HEADER_CSS);
  870.     $mpdf->WriteHTML($html);
  871.     $mpdf->output();
  872.     exit(0);
  873.   }
  874.     /**
  875.    * @param Request $request
  876.    * @return JsonResponse
  877.    *
  878.    * @Route("report/strategy/{strategy}", name="api_report_strategy", methods={"POST"})
  879.    */
  880.   public function stategyExport(Strategy $strategyRequest $request)
  881.   {
  882.     $prefixFileCustomer $this->getParameter("app.path.customer_images");
  883.     $prefixFile $this->getParameter("app.path.strategies");
  884.     /** @var Customer $customer */
  885.     $customer $this->getUser();
  886.     $season $customer->getSeasonActive();
  887.     $seasonArray $season->__toArray($prefixFileCustomer '/');
  888.     $seasonArray['teamLogo'] = realpath('.' $seasonArray['teamLogo']);
  889.     $strategy $strategy->__toArray($prefixFile'/');
  890.     $strategy['image'] = realpath("." $strategy['image']);
  891.     $html $this->renderView('reports/strategy.html.twig', [
  892.       'strategy' => $strategy,
  893.       'season' => $seasonArray,
  894.     ]);
  895.     $bootstrap file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
  896.     $monserrat file_get_contents(realpath('./design/css/monserrat.css'));
  897.     $mpdf MpdfHelper::Mpdf();
  898.     $mpdf->WriteHTML($bootstrapHTMLParserMode::HEADER_CSS);
  899.     $mpdf->WriteHTML($monserratHTMLParserMode::HEADER_CSS);
  900.     $mpdf->WriteHTML($html);
  901.     $mpdf->output();
  902.     exit(0);
  903.   }
  904. }