<?php
namespace App\Controller\Api;
use App\Entity\Competition;
use App\Entity\Titulars;
use App\Entity\Game;
use App\Entity\ConvocatoriaPlayer;
use App\Entity\Customer;
use App\Entity\Exercise;
use App\Entity\ExerciseCalendar;
use App\Entity\GamePlayerStatistics;
use App\Entity\JustificationType;
use App\Entity\NoteCalendar;
use App\Entity\Player;
use App\Entity\PlayerJustification;
use App\Entity\SeasonPlayer;
use App\Entity\Season;
use App\Entity\Strategy;
use App\Entity\TrainingAsist;
use App\Helper\MpdfHelper;
use App\Helper\SelectTranslate;
use App\Repository\PlayerRepository;
use App\Services\Api\PlayerManager;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Mpdf\HTMLParserMode;
use Symfony\Contracts\Translation\TranslatorInterface;
class ReportController extends ApiController
{
/** @var PlayerManager $playerManager */
protected $playerManager;
protected $translator;
/**
* @param PlayerManager $playerManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, PlayerManager $playerManager, TranslatorInterface $translator)
{
parent::__construct($em, $parameterBag);
$this->playerManager = $playerManager;
$this->translator = $translator;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/report/players", name="api_player_report_squad", methods={"POST"})
*/
public function reportSquad(Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.player_images");
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$imagePathCustomer = $prefixFileCustomer . "/";
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$players = [];
$filter = [
"season" => $season->getId()
];
/** @var PlayerRepository $playerRepository */
$playerRepository = $this->em->getRepository(Player::class);
$seasonArray = $season->__toArray($imagePathCustomer);
$seasonArray['customerName'] = $customer->getName();
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 0, 3));
foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
$player = $seasonPlayer->getPlayer();
$seasonPlayerActive = !$seasonPlayer->getDeletedAt();
$isActive = $player->getIsActive();
if ($isActive && $seasonPlayerActive) {
$playerArr = $player->__toArray($baseurl . $prefixFile . "/");
$miscellaneous = $playerRepository->getStatsMiscellaneous($player, $season);
$player = [
"dorsal" => $seasonPlayer->getDorsal(),
"games" => intval($miscellaneous['countPlayed'] ?? 0),
"goals" => intval($miscellaneous['goals'] ?? 0),
"image" => !empty($player->getImage()) ? $prefixFile . "/" . $player->getImage() : null,
];
$player["shortName"] = strtoupper(substr($playerArr['lastname'], 0, 1) . substr($playerArr['name'], 0, 1));
if ($player['image']) {
$player['image'] = realpath('.' . $player['image']);
}
$players[] = array_merge($playerArr, $player);
}
}
$bootstrap = file_get_contents(realpath('./design/css/bootstrap.min.css'));
$mpdf = MpdfHelper::Mpdf();
$html = $this->renderView('reports/players_squad.html.twig', [
'players' => $players,
'season' => $seasonArray,
'bootstrap' => $bootstrap,
]);
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/report/games/{id}", name="api_report_games_id", methods={"POST"})
*/
public function getAlignment($id, Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFilePlayer = $this->getParameter("app.path.player_images");
$prefixFileGame = $this->getParameter("app.path.game_images");
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$imagePathCustomer = $prefixFileCustomer . "/";
$imagePathPlayer = $prefixFilePlayer . "/";
$imagePathGame = $prefixFileGame . "/";
/** @var Customer $customer */
$customer = $this->getUser();
/** @var Season $season */
$season = $customer->getSeasonActive();
$filter = [
"season" => $season->getId(),
"id" => $id
];
/** @var Game $game */
$game = $this->em->getRepository(Game::class)->findOneBy($filter);
$gameArray = $game->__toArray($imagePathGame);
$gameArray['teamNameShort'] = strtoupper(substr($gameArray['rival'], 0, 2));
if ($gameArray['image'] != "") {
$gameArray['image'] = realpath('.' . $gameArray['image']);
}
$filter = [
"season" => $season->getId()
];
$convocatoria = $game->getConvocatoria();
$convocatoriaPlayerRepository = $this->em->getRepository(ConvocatoriaPlayer::class);
$players = [];
/** @var PlayerRepository $playerRepository */
$playerRepository = $this->em->getRepository(Player::class);
foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter, ['dorsal' => 'ASC']) as $seasonPlayer) {
$player = $seasonPlayer->getPlayer();
$playerArr = $player->__toArray($imagePathPlayer);
if ($playerArr['image'] != "") {
$playerArr['image'] = realpath('.' . $playerArr['image']);
} else {
$playerArr['image'] = false;
}
$isActive = $player->getIsActive();
$seasonPlayerActive = !$seasonPlayer->getDeletedAt();
if (!$isActive || !$seasonPlayerActive) {
continue;
}
$criteria = [
"seasonplayer" => $seasonPlayer,
"game" => $game
];
/** @var GamePlayerStatistics $statists */
$statists = $this->em->getRepository(GamePlayerStatistics::class)->findOneBy($criteria);
$isTitular = $statists ? $statists->getIsTitular() : false;
$goals = $statists ? $statists->getGoals() : 0;
$yellowCards = $statists ? $statists->getYellowCards() : 0;
$redCards = $statists ? $statists->getRedCards() : 0;
$minutes = $statists ? $statists->getMinutes() : 0;
$out = [
"dorsal" => $seasonPlayer->getDorsal(),
"goals" => $goals,
"yellowCards" => $yellowCards,
"redCards" => $redCards,
"minutes" => $minutes,
"isTitular" => $isTitular,
"shortName" => strtoupper(substr($playerArr['lastname'], 0, 1) . substr($playerArr['name'], 0, 1)),
];
if ($convocatoria) {
/** @var ConvocatoriaPlayer $convocatoriaPlayer */
$convocatoriaPlayer = $convocatoriaPlayerRepository->findOneBy([
"player_id" => $player->getId(),
"convocatoria_id" => $convocatoria->getId(),
]);
if ($convocatoriaPlayer) {
$out = array_merge($out, [
"isOn" => $convocatoriaPlayer->getIsActive(),
], $convocatoriaPlayer->__toArray());
$players[] = array_merge($playerArr, $out);
}
}
}
$seasonArray = $season->__toArray($imagePathCustomer);
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$seasonArray['appLogo'] = realpath('./assets/img/logo-only-line.png');
$seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 0, 2));
$bootstrap = file_get_contents(realpath('./design/css/bootstrap.min.css'));
$mpdf = MpdfHelper::Mpdf();
$html = $this->renderView('reports/games_one.html.twig', [
'game' => $gameArray,
'players' => $players,
'bootstrap' => $bootstrap,
'team' => $season->getTeam(),
'season' => $seasonArray,
]);
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$separador = explode('-----------------separator-----------------', $html);
foreach ($separador as $key => $value) {
if ($key + 1 === count($separador)) {
$mpdf->AddPage();
$mpdf->WriteHTML($value);
} else {
$mpdf->WriteHTML($value);
}
}
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
* @Route("/report/game/convocatoria/{gameId}", name="api_player_report_convocatoria", methods={"POST"})
*/
public function reportGameAnnouncement($gameId, Request $request)
{
$prefixFile = $this->getParameter("app.path.player_images");
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFilePlayer = $this->getParameter("app.path.player_images");
$prefixFileGame = $this->getParameter("app.path.game_images");
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$imagePathCustomer = $prefixFileCustomer . "/";
$imagePathPlayer = $prefixFilePlayer . "/";
$imagePathGame = $prefixFileGame . "/";
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$game = $this->em->getRepository(Game::class)->find($gameId);
$gameArray = $game->__toArray($imagePathGame);
$convocatoria = $game->getConvocatoria();
$filter = [
"season" => $season->getId()
];
/** @var PlayerRepository $playerRepository */
$playerRepository = $this->em->getRepository(Player::class);
$seasonArray = $season->__toArray($imagePathCustomer);
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 0, 3));
$seasonArray['customerName'] = $customer->getName() . " " . $customer->getSurname();
if ($game) {
$convocatoriaPlayerRepository = $this->em->getRepository(ConvocatoriaPlayer::class);
/** @var SeasonPlayer $seasonPlayer */
foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter, ["dorsal" => "ASC"]) as $seasonPlayer) {
$player = $seasonPlayer->getPlayer();
$seasonPlayerActive = !$seasonPlayer->getDeletedAt();
$isActive = $player->getIsActive();
$playerArr = $player->__toArray($imagePathPlayer);
$miscellaneous = $playerRepository->getStatsMiscellaneous($player, $season);
if ($isActive && $seasonPlayerActive) {
$out = [
"id" => $player->getId(),
"seasonPlayer_id" => $seasonPlayer->getId(),
"dorsal" => $seasonPlayer->getDorsal(),
"name" => $player->getName(),
"lastname" => $player->getLastname(),
"position" => !empty($player->getPosition()) ? $player->getPosition()->getSlugTranslation() : "",
"image" => $player->getImage() ? realpath("." . $prefixFile . "/" . $player->getImage()) : false,
"gameAlignment" => intval($miscellaneous['gameAlignment'] ?? 0),
"countryId" => !empty($player->getCountry()) ? $player->getCountry()->getId() : null,
];
if ($convocatoria) {
$convocatoriaPlayer = $convocatoriaPlayerRepository->findOneBy([
"player_id" => $player->getId(),
"convocatoria_id" => $convocatoria->getId(),
]);
if ($convocatoriaPlayer) {
$out = array_merge($out, [
"isOn" => $convocatoriaPlayer->getIsActive(),
"in" => $convocatoriaPlayer->getIsActive(),
], $convocatoriaPlayer->__toArray());
} else {
$out = array_merge($out, [
"isOn" => false,
"in" => false,
"justification_type" => null,
"is_active" => null,
]);
}
} else {
$out = array_merge($out, [
"isOn" => false,
"in" => false,
"justification_type" => null,
"is_active" => null,
]);
}
if ($out["isOn"]) {
$out["shortName"] = strtoupper(substr($playerArr['lastname'], 0, 1) . substr($playerArr['name'], 0, 1));
$players[] = array_merge($playerArr, $out);
}
}
}
}
$bootstrap = file_get_contents(realpath('./design/css/bootstrap.min.css'));
$mpdf = MpdfHelper::Mpdf();
$html = $this->renderView('reports/game_announcement.html.twig', [
'game' => $gameArray,
'players' => $players,
'bootstrap' => $bootstrap,
'team' => $season->getTeam(),
'season' => $seasonArray,
]);
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/exercise/calendar/{date}/get", name="api_report_exercise_calendar_get", methods={"POST"})
*/
public function calendarExercisesGet($date, Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.exercise_images");
$date = \DateTime::createFromFormat("d-m-Y", $date);
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$seasonArray = $season->__toArray($prefixFileCustomer . '/');
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$exercises = [];
if (!empty($season)) {
$filter = [
'season' => $season->getId(),
'date' => $date,
];
/** @var ExerciseCalendar $exerciseCalendar */
foreach ($this->em->getRepository(ExerciseCalendar::class)->findBy($filter) as $exerciseCalendar) {
$exercise = $exerciseCalendar->getExercise();
$exercise = $exercise->__toArray($prefixFile . '/');
$poster = empty($exercise['poster']) ? $exercise['image'] : $exercise['poster'];
$exercise['poster'] = rawurlencode(realpath("./" . $poster));
$exercise['description'] = str_replace("\n", "", $exercise['description']);
$maxLength = 200;
if (strlen($exercise['description']) > $maxLength) {
$exercise['description'] = substr($exercise['description'], 0, $maxLength) . '...';
}
$exercises[] = $exercise;
}
}
$intensityIcon = realpath('./assets/img/intensity.png');
$durationIcon = realpath('./assets/img/time.png');
$difficultyIcon = realpath('./assets/img/intensity.png');
$icons = [
'intensity' => $intensityIcon,
'duration' => $durationIcon,
'difficulty' => $difficultyIcon
];
$notesRepository = $this->em->getRepository(NoteCalendar::class);
$filterNotes = [
'season' => $season,
'date' => $date,
];
$generalObjetives = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_GENERAL_OBJECTIVES])) as $value) {
$generalObjetives[] = $value->__toArray();
}
$physicalObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_PHYSICAL_TARGETS])) as $value) {
$physicalObjeties[] = $value->__toArray();
}
$tacticObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_TACTIC_OBJETIVES])) as $value) {
$tacticObjeties[] = $value->__toArray();
}
$warmUpObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_WARM_UP_OBJETIVES])) as $value) {
$warmUpObjeties[] = $value->__toArray();
}
$objetives = [
'generals' => $generalObjetives,
'physicals' => $physicalObjeties,
'tactics' => $tacticObjeties,
'warm_up' => $warmUpObjeties
];
$html = $this->renderView('reports/exercise_date_day_customer.html.twig', [
'exercises' => $exercises,
'season' => $seasonArray,
'date' => $date->format('d M Y'),
'objetives' => $objetives,
'icons' => $icons
]);
$bootstrap = file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
$monserrat = file_get_contents(realpath('./design/css/monserrat.css'));
$mpdf = MpdfHelper::Mpdf();
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($monserrat, HTMLParserMode::HEADER_CSS);
$separador = explode('-----------------separator-----------------', $html);
// logic paginate
$numberPage = 1;
$beforeStrLong = 0;
$columsPrint = 0;
$aumentNumberPage = false;
$aumentNumberColums = false;
foreach ($separador as $key => $value) {
$str_long = strlen($value);
if ($numberPage == 2) {
if ($columsPrint == 0) {
$mpdf->WriteHTML($value);
$beforeStrLong = $str_long;
$aumentNumberColums = true;
}
if ($columsPrint == 1) {
$mpdf->WriteHTML($value);
$beforeStrLong = $str_long + $beforeStrLong;
$aumentNumberColums = true;
}
if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
$mpdf->WriteHTML($value);
$mpdf->AddPage();
$columsPrint = 0;
$beforeStrLong = 0;
}
if ($columsPrint == 2 && ($str_long + $beforeStrLong) > 14000) {
$mpdf->AddPage();
$mpdf->WriteHTML($value);
$columsPrint = 0;
$beforeStrLong = 0;
}
}
if ($numberPage == 1 && $key <= 1 && $beforeStrLong < 3500 && $str_long < 4706) {
$mpdf->WriteHTML($value);
if ($key == 1) {
$aumentNumberPage = true;
$mpdf->AddPage();
}
$beforeStrLong = $str_long;
}
if ($aumentNumberPage) {
$numberPage = $numberPage + 1;
$aumentNumberPage = false;
}
if ($aumentNumberColums) {
$columsPrint = $columsPrint + 1;
$aumentNumberColums = false;
}
if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
$beforeStrLong = $str_long + $beforeStrLong;
}
}
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/exercise/calendar/{date}/get/test", name="api_report_exercise_calendar_get_test", methods={"POST"})
*/
public function calendarExercisesGetTest($date, Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.exercise_images");
$date = \DateTime::createFromFormat("d-m-Y", $date);
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$seasonArray = $season->__toArray($prefixFileCustomer . '/');
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$exercises = [];
if (!empty($season)) {
$filter = [
'season' => $season->getId(),
'date' => $date,
];
/** @var ExerciseCalendar $exerciseCalendar */
foreach ($this->em->getRepository(ExerciseCalendar::class)->findBy($filter) as $exerciseCalendar) {
$exercise = $exerciseCalendar->getExercise();
$exercise = $exercise->__toArray($prefixFile . '/');
$poster = empty($exercise['poster']) ? $exercise['image'] : $exercise['poster'];
$exercise['poster'] = rawurlencode(realpath("./" . $poster));
$exercise['description'] = 'hello';
$exercises[] = $exercise;
}
}
$intensityIcon = realpath('./assets/img/intensity.png');
$durationIcon = realpath('./assets/img/time.png');
$difficultyIcon = realpath('./assets/img/intensity.png');
$icons = [
'intensity' => $intensityIcon,
'duration' => $durationIcon,
'difficulty' => $difficultyIcon
];
$notesRepository = $this->em->getRepository(NoteCalendar::class);
$filterNotes = [
'season' => $season,
'date' => $date,
];
$generalObjetives = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_GENERAL_OBJECTIVES])) as $value) {
$generalObjetives[] = $value->__toArray();
}
$physicalObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_PHYSICAL_TARGETS])) as $value) {
$physicalObjeties[] = $value->__toArray();
}
$tacticObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_TACTIC_OBJETIVES])) as $value) {
$tacticObjeties[] = $value->__toArray();
}
$warmUpObjeties = [];
foreach ($notesRepository->findBy(array_merge($filterNotes, ['type' => NoteCalendar::TYPE_WARM_UP_OBJETIVES])) as $value) {
$warmUpObjeties[] = $value->__toArray();
}
$objetives = [
'generals' => $generalObjetives,
'physicals' => $physicalObjeties,
'tactics' => $tacticObjeties,
'warm_up' => $warmUpObjeties
];
$result = [
'exercises' => $exercises,
'season' => $seasonArray,
'date' => $date->format('d M Y'),
'objetives' => $objetives,
'icons' => $icons
];
return $this->response($result);
// $html = $this->renderView('reports/exercise_date_day_customer.html.twig', [
// 'exercises' => $exercises,
// 'season' => $seasonArray,
// 'date' => $date->format('d M Y'),
// 'objetives' => $objetives,
// 'icons' => $icons
// ]);
// $bootstrap = file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
// $monserrat = file_get_contents(realpath('./design/css/monserrat.css'));
// $mpdf = MpdfHelper::Mpdf();
// $mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
// $mpdf->WriteHTML($monserrat, HTMLParserMode::HEADER_CSS);
// $separador = explode('-----------------separator-----------------', $html);
// logic paginate
// $numberPage = 1;
// $beforeStrLong = 0;
// $columsPrint = 0;
// $aumentNumberPage = false;
// $aumentNumberColums = false;
// foreach ($separador as $key => $value) {
// $str_long = strlen($value);
// if ($numberPage == 2) {
// if ($columsPrint == 0) {
// $mpdf->WriteHTML($value);
// $beforeStrLong = $str_long;
// $aumentNumberColums = true;
// }
// if ($columsPrint == 1) {
// $mpdf->WriteHTML($value);
// $beforeStrLong = $str_long + $beforeStrLong;
// $aumentNumberColums = true;
// }
// if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
// $mpdf->WriteHTML($value);
// $mpdf->AddPage();
// $columsPrint = 0;
// $beforeStrLong = 0;
// }
// if ($columsPrint == 2 && ($str_long + $beforeStrLong) > 14000) {
// $mpdf->AddPage();
// $mpdf->WriteHTML($value);
// $columsPrint = 0;
// $beforeStrLong = 0;
// }
// }
// if ($numberPage == 1 && $key <= 1 && $beforeStrLong < 3500 && $str_long < 4706) {
// $mpdf->WriteHTML($value);
// if ($key == 1) {
// $aumentNumberPage = true;
// $mpdf->AddPage();
// }
// $beforeStrLong = $str_long;
// }
// if ($aumentNumberPage) {
// $numberPage = $numberPage + 1;
// $aumentNumberPage = false;
// }
// if ($aumentNumberColums) {
// $columsPrint = $columsPrint + 1;
// $aumentNumberColums = false;
// }
// if ($columsPrint == 2 && ($str_long + $beforeStrLong) < 14000) {
// $beforeStrLong = $str_long + $beforeStrLong;
// }
// }
// $mpdf->output();
// exit(0);
}
public function getLetterJustification(int $id): ?string
{
$name = $this->em->getRepository(JustificationType::class)->find($id)->getName();
// extraer primera letra
if (!$name) {
return null;
}
return strtoupper(substr($name, 0, 1));
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/trainings/{date}/get", name="api_report_training_calendar_get", methods={"POST"})
*/
public function reportTrainign(Request $request, DateTime $date)
{
$trainings = [];
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.player_images");
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$imagePathCustomer = $prefixFileCustomer . "/";
$tmpAvatars = [];
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$season = $customer->getSeasonActive();
$dateStart = $date->format('Y-m-01');
$dateEnd = $date->format('Y-m-t');
$playersTemplate = [];
$seasonArray = $season->__toArray($imagePathCustomer);
$seasonArray['customerName'] = $customer->getName();
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 0, 3));
$seasonArray['dateStart'] = $date->format('Y-m-01');
$seasonArray['dateEnd'] = $date->format('Y-m-t');
if (!empty($season)) {
$filter = [
[
"prop" => "season",
"comp" => "=",
"val" => $season->getId()
],
[
"prop" => "date",
"comp" => ">=",
"val" => $dateStart
],
[
"prop" => "date",
"comp" => "<=",
"val" => $dateEnd
],
];
$assists = [];
$justifycations = [];
$dates = [];
$heads = [];
/** @var TrainingAsist $trainingAsist */
foreach ($this->em->getRepository(TrainingAsist::class)->findByOwnCriteria($filter) as $trainingAsist) {
$assists[$trainingAsist->getDate()->format("Y-m-d")] = $trainingAsist->getPlayers()->map(function (Player $player) use ($trainingAsist) {
return $player->getId();
})->toArray();
$trainings[] = [
"id" => $trainingAsist->getId(),
"date" => $trainingAsist->getDate()->format("Y-m-d")
];
}
// tipos de justificacion
// lis ids bienen de la base de datos
// migracion Version20220815252224
// 1 enfermedad
// 2 lesion
// 3 sin justificatiè´¸n
// 4 viaje
// 5 estudios
// 6 sancion
// 7 dar de baja por lesion
// 8 tecnico
// 9 otros
/** @var PlayerJustification $playerJustification */
foreach ($this->em->getRepository(PlayerJustification::class)->findByOwnCriteria($filter) as $playerJustification) {
$justifycations[] = [
"id" => $playerJustification->getPlayer()->getId(),
"type" => $playerJustification->getJustificationType()->getId(),
"letter" => $this->getLetterJustification($playerJustification->getJustificationType()->getId()),
"date" => $playerJustification->getDate()->format("Y-m-d")
];
}
}
$filter = [
"season" => $season->getId()
];
// se calculan los dias del mes
for ($i = 1; $i <= $date->format('t'); $i++) {
$day = $i < 10 ? '0' . $i : $i;
$currentDate = new DateTime($date->format('Y-m-' . $day));
$dates[] = $date->format('Y-m-' . $day);
$heads[] = substr($this->translator->trans(SelectTranslate::dayWeek($currentDate->format('D')), [], 'reports'), 0, 1);
}
// se marca asistencia en cada dia
foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
$player = $seasonPlayer->getPlayer();
$seasonPlayerActive = !$seasonPlayer->getDeletedAt();
$isActive = $player->getIsActive();
if ($isActive && $seasonPlayerActive) {
$dataPlayer = $player->__toArray($baseurl . $prefixFile . "/");
if (!is_null($dataPlayer['image']) && !empty($dataPlayer['image'])) {
$dataPlayer['image'] = realpath("." . $prefixFile . "/" . $player->getImage());
} else {
$dataPlayer['image'] = null;
}
$dataPlayer["shortName"] = strtoupper(substr($dataPlayer['lastname'], 0, 1) . substr($dataPlayer['name'], 0, 1));
$dataPlayer['assists'] = [];
foreach ($dates as $key => $day) {
$dataPlayer['assists'][$day] = false;
foreach ($assists as $key => $value) {
if ($key === $day) {
if (in_array($dataPlayer['id'], $value)) {
$dataPlayer['assists'][$day] = 'X';
}
}
}
// se a帽ade la justificacion en caso de tenerla
foreach ($justifycations as $key => $value) {
if ($day === $value['date'] && $value['id'] === $dataPlayer['id']) {
$dataPlayer['assists'][$day] = $value['letter'];
}
}
}
$playersTemplate[] = $dataPlayer;
}
}
$bootstrap = file_get_contents(realpath('./design/css/bootstrap.min.css'));
$mpdf = MpdfHelper::MpdfHorizontal();
$html = $this->renderView('reports/monthly_attendance_report.html.twig', [
'template' => $playersTemplate,
'assists' => $assists,
'bootstrap' => $bootstrap,
'team' => $season->getTeam(),
'heads' => $heads,
'season' => $seasonArray,
]);
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/stats/{competitionId}/{typeStat}/get", name="api_report_stats_get", methods={"POST"})
*/
public function reportStats($competitionId, $typeStat, Request $request)
{
if ($typeStat == 'convocatorias') {
$typeStat = 'convocatoria';
}
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$filter = [
"season" => $season->getId()
];
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$prefixFile = $this->getParameter("app.path.player_images");
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.player_images");
$imagePathCustomer = $prefixFileCustomer . "/";
$seasonArray = $season->__toArray($imagePathCustomer);
$seasonArray['customerName'] = $customer->getName();
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$seasonArray['teamNameShort'] = strtoupper(substr($seasonArray['teamName'], 0, 3));
$players = [];
$statsKey = $typeStat;
$competitionName = $this->translator->trans('general');
if ($competitionId != 'null') {
/** @var Competition $competition */
$competition = $this->em->getRepository(Competition::class)->find($competitionId);
$competitionName = $competition->getName();
$statsKey = "${typeStat}_$competitionId";
}
/** @var Player $player */
foreach ($this->em->getRepository(SeasonPlayer::class)->findBy($filter) as $seasonPlayer) {
/** @var SeasonPlayer $seasonPlayer */
$player = $seasonPlayer->getPlayer();
/** @var PlayerRepository $playerRepository */
$playerRepository = $this->em->getRepository(Player::class);
$playerArr = $player->__toArray($baseurl . $prefixFile . "/");
$playerData["dorsal"] = $seasonPlayer->getDorsal();
$playerData["name"] = $playerArr['name'];
$playerData["lastname"] = $playerArr['lastname'];
$playerData["shortName"] = strtoupper(substr($playerArr['lastname'], 0, 1) . substr($playerArr['name'], 0, 1));
$miscellaneous = $playerRepository->getStatsMiscellaneous($player, $season);
$result = $playerRepository->getStatsConvocatoria($player, $season);
$baseData = array_merge($playerArr, $miscellaneous);
$statsPlayer = array_merge($baseData, $result);
if ($playerArr['image'] != "") {
$playerData['image'] = realpath('.' . $playerArr['image']);
}
if ($playerArr['image'] == "") {
$playerData['image'] = false;
}
$playerData["stat"] = intval($statsPlayer[$statsKey]);
$players[] = $playerData;
}
usort($players, function ($a, $b) {
if ($a['stat'] == $b['stat']) return 0;
if ($a['stat'] < $b['stat']) return -1;
return 1;
});
$endList = [];
$players = array_reverse($players);
foreach ($players as $key => $value) {
if ($players[0]['stat'] == 0 || $value['stat'] == 0) {
$value['graph'] = 0;
} else {
$value['graph'] = round(($value['stat'] / $players[0]['stat']) * 10) ?? 0;
}
$endList[] = $value;
}
$bootstrap = file_get_contents(realpath('./design/css/bootstrap.min.css'));
$mpdf = MpdfHelper::Mpdf();
$html = $this->renderView('reports/players_stat_competition.html.twig', [
'players' => $endList,
'season' => $seasonArray,
'bootstrap' => $bootstrap,
'typeStat' => $typeStat,
'competition' => $competitionName,
]);
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/exercise/{exercise}", name="api_report_exercise", methods={"POST"})
*/
public function exerciseExport(Exercise $exercise, Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.exercise_images");
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$seasonArray = $season->__toArray($prefixFileCustomer . '/');
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$exercise = $exercise->__toArray($prefixFile . '/');
$poster = empty($exercise['poster']) ? $exercise['image'] : $exercise['poster'];
$exercise['poster'] = rawurlencode(realpath("./" . $poster));
$intensityIcon = realpath('./assets/img/intensity.png');
$durationIcon = realpath('./assets/img/time.png');
$difficultyIcon = realpath('./assets/img/intensity.png');
$icons = [
'intensity' => $intensityIcon,
'duration' => $durationIcon,
'difficulty' => $difficultyIcon
];
$html = $this->renderView('reports/exercise.html.twig', [
'exercise' => $exercise,
'season' => $seasonArray,
'icons' => $icons
]);
$bootstrap = file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
$monserrat = file_get_contents(realpath('./design/css/monserrat.css'));
$mpdf = MpdfHelper::Mpdf();
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($monserrat, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("report/strategy/{strategy}", name="api_report_strategy", methods={"POST"})
*/
public function stategyExport(Strategy $strategy, Request $request)
{
$prefixFileCustomer = $this->getParameter("app.path.customer_images");
$prefixFile = $this->getParameter("app.path.strategies");
/** @var Customer $customer */
$customer = $this->getUser();
$season = $customer->getSeasonActive();
$seasonArray = $season->__toArray($prefixFileCustomer . '/');
$seasonArray['teamLogo'] = realpath('.' . $seasonArray['teamLogo']);
$strategy = $strategy->__toArray($prefixFile. '/');
$strategy['image'] = realpath("." . $strategy['image']);
$html = $this->renderView('reports/strategy.html.twig', [
'strategy' => $strategy,
'season' => $seasonArray,
]);
$bootstrap = file_get_contents(realpath('./design/bootstrap-5.0.2/css/bootstrap.min.css'));
$monserrat = file_get_contents(realpath('./design/css/monserrat.css'));
$mpdf = MpdfHelper::Mpdf();
$mpdf->WriteHTML($bootstrap, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($monserrat, HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($html);
$mpdf->output();
exit(0);
}
}