welcome back to dyb-tech
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\CustomRole;
|
||||
|
||||
class CustomRoleDto
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public \DateTimeImmutable $createdAt;
|
||||
public int $userId;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id ?? '',
|
||||
'name' => $this->name ?? '',
|
||||
'userId' => $this->userId ?? '',
|
||||
'createdAt' => $this->createdAt ? $this->createdAt->format('Y-m-d H:i:s') : ''
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['name']))
|
||||
{
|
||||
$this->name = $dataList['name'];
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
|
||||
}
|
||||
}
|
||||
public function fillFromObject(CustomRole $customRole): void
|
||||
{
|
||||
if (!is_null($customRole->getId()))
|
||||
{
|
||||
$this->id = $customRole->getId();
|
||||
}
|
||||
if (!is_null($customRole->getName()))
|
||||
{
|
||||
$this->name = $customRole->getName();
|
||||
}
|
||||
if (!is_null($customRole->getCreatedAt()))
|
||||
{
|
||||
$this->name = $customRole->getCreatedAt();
|
||||
}
|
||||
if (!is_null(($customRole->getUser())->getId()))
|
||||
{
|
||||
$this->userId = ($customRole->getUser())->getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Facility;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
|
||||
class FacilityDto
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public string $address;
|
||||
public bool $active;
|
||||
public array $gameDtoList;
|
||||
public array $seasonDtoList;
|
||||
public \DateTime $createdAt;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$seasonList = [];
|
||||
if (!empty($this->seasonDtoList))
|
||||
{
|
||||
foreach ($this->seasonDtoList as $seasonDto)
|
||||
{
|
||||
$seasonList = $seasonDto->toArray();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $this->id ?? '',
|
||||
'name' => $this->name ?? '',
|
||||
'address' => $this->address ?? '',
|
||||
'seasonList' => $seasonList,
|
||||
'createdAt' => !empty($this->createdAt) ? $this->createdAt->format('Y-m-d H:i:s') : ''
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['name']))
|
||||
{
|
||||
$this->name = $dataList['name'];
|
||||
}
|
||||
if (!empty($dataList['address']))
|
||||
{
|
||||
$this->address = $dataList['address'];
|
||||
}
|
||||
if (isset($dataList['active']))
|
||||
{
|
||||
$this->active = $dataList['active'];
|
||||
}
|
||||
if (!empty($dataList['seasonList']))
|
||||
{
|
||||
foreach ($dataList['seasonList'] as $seasonItem)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromArray($seasonItem);
|
||||
$this->seasonDtoList[] = $seasonDto;
|
||||
}
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTime::createFromFormat('Y-m-d H:i:s', $dataList['createdAt'], new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(Facility $facilityEntity): void
|
||||
{
|
||||
if ($facilityEntity->getId() !== null)
|
||||
{
|
||||
$this->id = $facilityEntity->getId();
|
||||
}
|
||||
if ($facilityEntity->getName() !== null)
|
||||
{
|
||||
$this->name = $facilityEntity->getName();
|
||||
}
|
||||
if ($facilityEntity->getAddress() !== null)
|
||||
{
|
||||
$this->address = $facilityEntity->getAddress();
|
||||
}
|
||||
if ($facilityEntity->getCreatedAt() !== null)
|
||||
{
|
||||
$this->createdAt = new \DateTime($facilityEntity->getCreatedAt(), new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
// if (empty($this->name))
|
||||
// {
|
||||
// $this->validationErrors[] = 'El nombre del equipo no puede estar vacío.';
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\File;
|
||||
|
||||
class FileDto
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public string $type;
|
||||
public \DateTime $createdAt;
|
||||
public GameDto $gameDto;
|
||||
public PlayerDto $playerDto;
|
||||
public SeasonDto $seasonDto;
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['name']))
|
||||
{
|
||||
$this->name = $dataList['name'];
|
||||
}
|
||||
if (!empty($dataList['type']))
|
||||
{
|
||||
$this->type = $dataList['type'];
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTime::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(File $fileEntity): void
|
||||
{
|
||||
if ($fileEntity->getId() !== null)
|
||||
{
|
||||
$this->id = $fileEntity->getId();
|
||||
}
|
||||
if ($fileEntity->getName() !== null)
|
||||
{
|
||||
$this->name = $fileEntity->getName();
|
||||
}
|
||||
if ($fileEntity->getPlayer() !== null)
|
||||
{
|
||||
$playerDto = new PlayerDto();
|
||||
$playerDto->fillFromObject($fileEntity->getPlayer());
|
||||
$this->playerDto = $playerDto;
|
||||
}
|
||||
if ($fileEntity->getSeason() !== null)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromObject($fileEntity->getSeason());
|
||||
$this->seasonDto = $seasonDto;
|
||||
}
|
||||
if ($fileEntity->getGame() !== null)
|
||||
{
|
||||
$gameDto = new GameDto();
|
||||
$gameDto->fillFromObject($fileEntity->getGame());
|
||||
$this->gameDto = $gameDto;
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Game;
|
||||
|
||||
class GameDto
|
||||
{
|
||||
public int $id;
|
||||
public TeamDto $homeTeamDto;
|
||||
public TeamDto $awayTeamDto;
|
||||
public \DateTime $plannedDate;
|
||||
public \DateTime $gameDateTime;
|
||||
public string $notes;
|
||||
public array $fileDtoList;
|
||||
public SeasonDto $seasonDto;
|
||||
public FacilityDto $facilityDto;
|
||||
public int $pointsHome;
|
||||
public int $pointsAway;
|
||||
public \DateTimeImmutable $createdAt;
|
||||
public \DateTimeImmutable $updatedAt;
|
||||
public array $validationErrors;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$cleanResponseArray = [];
|
||||
$responseArray = [
|
||||
'id' => $this->id ?? null,
|
||||
'homeTeam' => $this->homeTeamDto->toArray() ?? [],
|
||||
'awayTeam' => $this->awayTeamDto->toArray() ?? [],
|
||||
'plannedDate' => !empty($this->plannedDate) ? $this->plannedDate->format('Y-m-d H:i:s') : null,
|
||||
'gameDateTime' => !empty($this->gameDateTime) ? $this->gameDateTime->format('Y-m-d H:i:s') : null,
|
||||
'season' => $this->seasonDto->toArray() ?? [],
|
||||
'notes' => $this->notes ?? null,
|
||||
'facility' => $this->facilityDto->toArray() ?? [],
|
||||
'pointsHome' => $this->pointsHome ?? 0,
|
||||
'pointsAway' => $this->pointsAway ?? 0,
|
||||
'createdAt' => !empty($this->createdAt) ? $this->createdAt->format('Y-m-d H:i:s') : null,
|
||||
'updatedAt' => !empty($this->updatedAt) ? $this->updatedAt->format('Y-m-d H:i:s') : null
|
||||
];
|
||||
foreach ($responseArray as $key => $value)
|
||||
{
|
||||
if ($value !== null)
|
||||
{
|
||||
$cleanResponseArray[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $cleanResponseArray;
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (!empty($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['plannedDate']))
|
||||
{
|
||||
$this->plannedDate = new \DateTime($dataList['plannedDate']);
|
||||
}
|
||||
if (!empty($dataList['gameDateTime']))
|
||||
{
|
||||
$this->gameDateTime = new \DateTime($dataList['gameDateTime']);
|
||||
}
|
||||
if (!empty($dataList['notes']))
|
||||
{
|
||||
$this->notes = $dataList['notes'];
|
||||
}
|
||||
if (!empty($dataList['pointsHome']))
|
||||
{
|
||||
$this->pointsHome = $dataList['pointsHome'];
|
||||
}
|
||||
if (!empty($dataList['pointsAway']))
|
||||
{
|
||||
$this->pointsAway = $dataList['pointsAway'];
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = new \DateTimeImmutable($dataList['createdAt'], new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
if (!empty($dataList['updatedAt']))
|
||||
{
|
||||
$this->updatedAt = new \DateTimeImmutable($dataList['updatedAt'], new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(Game $gameEntity): void
|
||||
{
|
||||
if ($gameEntity->getId() !== null)
|
||||
{
|
||||
$this->id = $gameEntity->getId();
|
||||
}
|
||||
if ($gameEntity->getSeason() !== null)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromObject($gameEntity->getSeason());
|
||||
$this->seasonDto = $seasonDto;
|
||||
}
|
||||
if ($gameEntity->getFacility() !== null)
|
||||
{
|
||||
$facilityDto = new FacilityDto();
|
||||
$facilityDto->fillFromObject($gameEntity->getFacility());
|
||||
$this->facilityDto = $facilityDto;
|
||||
}
|
||||
if ($gameEntity->getHomeTeam() !== null)
|
||||
{
|
||||
$teamDto = new TeamDto();
|
||||
$teamDto->fillFromObject($gameEntity->getHomeTeam());
|
||||
$this->homeTeamDto = $teamDto;
|
||||
}
|
||||
if ($gameEntity->getAwayTeam() !== null)
|
||||
{
|
||||
$teamDto = new TeamDto();
|
||||
$teamDto->fillFromObject($gameEntity->getAwayTeam());
|
||||
$this->awayTeamDto = $teamDto;
|
||||
}
|
||||
if ($gameEntity->getFiles() !== null)
|
||||
{
|
||||
$fileIterator = $gameEntity->getFiles()->getIterator();
|
||||
foreach ($fileIterator as $fileEntity)
|
||||
{
|
||||
$fileDto = new FileDto();
|
||||
$fileDto->fillFromObject($fileEntity);
|
||||
$this->fileDtoList[] = $fileDto;
|
||||
}
|
||||
}
|
||||
if ($gameEntity->getGameDateTime() !== null)
|
||||
{
|
||||
$this->gameDateTime = new \DateTime($gameEntity->getGameDateTime()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
if ($gameEntity->getCreatedAt() !== null)
|
||||
{
|
||||
$this->createdAt = $gameEntity->getCreatedAt();
|
||||
}
|
||||
if ($gameEntity->getUpdatedAt() !== null)
|
||||
{
|
||||
$this->createdAt = $gameEntity->getUpdatedAt();
|
||||
}
|
||||
if ($gameEntity->getPlannedDate() !== null)
|
||||
{
|
||||
$this->plannedDate = new \DateTime($gameEntity->getPlannedDate()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
if ($gameEntity->getNotes() !== null)
|
||||
{
|
||||
$this->notes = $gameEntity->getNotes();
|
||||
}
|
||||
if ($gameEntity->getNotes() !== null)
|
||||
{
|
||||
$this->notes = $gameEntity->getNotes();
|
||||
}
|
||||
if ($gameEntity->getPointsAway() !== null)
|
||||
{
|
||||
$this->pointsAway = $gameEntity->getPointsAway();
|
||||
}
|
||||
if ($gameEntity->getPointsHome() !== null)
|
||||
{
|
||||
$this->pointsAway = $gameEntity->getPointsHome();
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
if (empty($this->name))
|
||||
{
|
||||
$this->validationErrors[] = 'El nombre no puede estar vacío.';
|
||||
}
|
||||
if (
|
||||
empty($this->pointsPerWin)
|
||||
)
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por partido ganado no pueden estar vacíos.';
|
||||
}
|
||||
if (
|
||||
isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) &&
|
||||
(($this->pointsPerWin <= $this->pointsPerDraw) ||
|
||||
($this->pointsPerWin <= $this->pointsPerLoss))
|
||||
)
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por partido ganado deben ser superiores a los puntos por empate y por perdida.';
|
||||
}
|
||||
if (($this->pointsPerDraw > $this->pointsPerWin))
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por empate deben ser inferiores a los puntos por partido ganado.';
|
||||
}
|
||||
if (($this->pointsPerDraw < $this->pointsPerLoss))
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por empate deben ser superiores a los puntos por partido perdido.';
|
||||
}
|
||||
if ($this->pointsPerWin + $this->pointsPerDraw + $this->pointsPerLoss > 20)
|
||||
{
|
||||
$this->validationErrors[] = 'La suma de los puntos por partidos ganados, perdidos y empatados no puede ser superior a 20.';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Exception\ValidationException;
|
||||
use DMD\LaLigaApi\Entity\League;
|
||||
|
||||
class LeagueDto
|
||||
{
|
||||
|
||||
public int $id;
|
||||
public string $name;
|
||||
public string $city;
|
||||
public string $logo;
|
||||
public string $description;
|
||||
public int $pointsPerWin;
|
||||
public int $pointsPerDraw;
|
||||
public int $pointsPerLoss;
|
||||
public int $matchesBetweenTeams;
|
||||
public array $blockedMatchDates;
|
||||
public bool $active;
|
||||
public array $seasonDtoList;
|
||||
public int $presidentId;
|
||||
public bool $isPublic;
|
||||
public \DateTimeImmutable $createdAt;
|
||||
public array $validationErrors;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$seasonIdList = [];
|
||||
if (!empty($this->seasonDtoList))
|
||||
{
|
||||
foreach ($this->seasonDtoList as $seasonDto)
|
||||
{
|
||||
$seasonIdList[] = $seasonDto->id;
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $this->id ?? null,
|
||||
'name' => $this->name ?? null,
|
||||
'logo' => $this->logo ?? null,
|
||||
'description' => $this->description ?? null,
|
||||
'pointsPerWin' => $this->pointsPerWin ?? null,
|
||||
'pointsPerDraw' => $this->pointsPerDraw ?? null,
|
||||
'pointsPerLoss' => $this->pointsPerLoss ?? null,
|
||||
'matchesBetweenTeams' => $this->matchesBetweenTeams ?? [],
|
||||
'blockedMatchDates' => $this->blockedMatchDates ?? [],
|
||||
'active' => $this->active ?? null,
|
||||
'isPublic' => $this->isPublic ?? null,
|
||||
'seasonIdList' => $seasonIdList,
|
||||
'presidentId' => $this->presidentId ?? null,
|
||||
'createdAt' => !empty($this->createdAt) ? $this->createdAt->format('Y-m-d H:i:s') : null
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['name']))
|
||||
{
|
||||
$this->name = $dataList['name'];
|
||||
}
|
||||
if (!empty($dataList['city']))
|
||||
{
|
||||
$this->city = $dataList['city'];
|
||||
}
|
||||
if (!empty($dataList['logo']))
|
||||
{
|
||||
$this->logo = $dataList['logo'];
|
||||
}
|
||||
if (!empty($dataList['description']))
|
||||
{
|
||||
$this->description = $dataList['description'];
|
||||
}
|
||||
if (isset($dataList['pointsPerWin']))
|
||||
{
|
||||
$this->pointsPerWin = (int) $dataList['pointsPerWin'];
|
||||
}
|
||||
if (isset($dataList['pointsPerDraw']))
|
||||
{
|
||||
$this->pointsPerDraw = (int) $dataList['pointsPerDraw'];
|
||||
}
|
||||
if (isset($dataList['pointsPerLoss']))
|
||||
{
|
||||
$this->pointsPerLoss = (int) $dataList['pointsPerLoss'];
|
||||
}
|
||||
if (isset($dataList['matchesBetweenTeams']))
|
||||
{
|
||||
$this->matchesBetweenTeams = (int) $dataList['matchesBetweenTeams'];
|
||||
}
|
||||
if (isset($dataList['blockedMatchDates']))
|
||||
{
|
||||
$this->blockedMatchDates = $dataList['blockedMatchDates'];
|
||||
}
|
||||
if (!empty($dataList['seasonList']))
|
||||
{
|
||||
foreach ($dataList['seasonList'] as $seasonItem)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromArray($seasonItem);
|
||||
$this->seasonDtoList[] = $seasonDto;
|
||||
}
|
||||
}
|
||||
if (isset($dataList['isPublic']))
|
||||
{
|
||||
$this->isPublic = (bool) $dataList['isPublic'];
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(League $leagueObj): void
|
||||
{
|
||||
if ($leagueObj->getId() !== null)
|
||||
{
|
||||
$this->id = $leagueObj->getId();
|
||||
}
|
||||
if ($leagueObj->getName() !== null)
|
||||
{
|
||||
$this->name = $leagueObj->getName();
|
||||
}
|
||||
if ($leagueObj->getCity() !== null)
|
||||
{
|
||||
$this->city = $leagueObj->getCity();
|
||||
}
|
||||
if ($leagueObj->getDescription() !== null)
|
||||
{
|
||||
$this->description = $leagueObj->getDescription();
|
||||
}
|
||||
if ($leagueObj->getLogo() !== null)
|
||||
{
|
||||
$this->logo = $leagueObj->getLogo();
|
||||
}
|
||||
if ($leagueObj->getPointsPerWin() !== null)
|
||||
{
|
||||
$this->pointsPerWin = $leagueObj->getPointsPerWin();
|
||||
}
|
||||
if ($leagueObj->getPointsPerDraw() !== null)
|
||||
{
|
||||
$this->pointsPerDraw = $leagueObj->getPointsPerDraw();
|
||||
}
|
||||
if ($leagueObj->getPointsPerLoss() !== null)
|
||||
{
|
||||
$this->pointsPerLoss = $leagueObj->getPointsPerLoss();
|
||||
}
|
||||
if ($leagueObj->getMatchesBetweenTeams() !== null)
|
||||
{
|
||||
$this->matchesBetweenTeams = $leagueObj->getMatchesBetweenTeams();
|
||||
}
|
||||
if ($leagueObj->getBlockedMatchDates() !== null)
|
||||
{
|
||||
$this->blockedMatchDates = $leagueObj->getBlockedMatchDates();
|
||||
}
|
||||
if ($leagueObj->getCreatedAt() !== null)
|
||||
{
|
||||
$this->createdAt = $leagueObj->getCreatedAt();
|
||||
}
|
||||
if ($leagueObj->isPublic() !== null)
|
||||
{
|
||||
$this->isPublic = $leagueObj->isPublic();
|
||||
}
|
||||
if ($leagueObj->getSeasons() !== null)
|
||||
{
|
||||
foreach ($leagueObj->getSeasons() as $seasonObj)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromObject($seasonObj);
|
||||
$this->seasonDtoList[] = $seasonDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
if (empty($this->name))
|
||||
{
|
||||
$this->validationErrors[] = 'El nombre no puede estar vacío.';
|
||||
}
|
||||
if (empty($this->city))
|
||||
{
|
||||
$this->validationErrors[] = 'La localidad no puede estar vacía.';
|
||||
}
|
||||
if (empty($this->pointsPerWin))
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por partido ganado no pueden estar vacíos.';
|
||||
}
|
||||
if (
|
||||
isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) &&
|
||||
(($this->pointsPerWin <= $this->pointsPerDraw) ||
|
||||
($this->pointsPerWin <= $this->pointsPerLoss))
|
||||
)
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por partido ganado deben ser superiores a los puntos por empate y por perdida.';
|
||||
}
|
||||
if (($this->pointsPerDraw > $this->pointsPerWin))
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por empate deben ser inferiores a los puntos por partido ganado.';
|
||||
}
|
||||
if (($this->pointsPerDraw < $this->pointsPerLoss))
|
||||
{
|
||||
$this->validationErrors[] = 'Los puntos por empate deben ser superiores a los puntos por partido perdido.';
|
||||
}
|
||||
if ($this->pointsPerWin + $this->pointsPerDraw + $this->pointsPerLoss > 20)
|
||||
{
|
||||
$this->validationErrors[] = 'La suma de los puntos por partidos ganados, perdidos y empatados no puede ser superior a 20.';
|
||||
}
|
||||
if (!empty($this->validationErrors))
|
||||
{
|
||||
throw new ValidationException($this->validationErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Notification;
|
||||
|
||||
class NotificationDto
|
||||
{
|
||||
public static string $TYPE_JOIN_LEAGUE = 'joinLeague';
|
||||
public static string $TYPE_JOIN_TEAM = 'joinTeam';
|
||||
public static string $TYPE_CAPTAIN_REQUEST = 'captainRequest';
|
||||
|
||||
public int $id;
|
||||
public string $type;
|
||||
public string $message;
|
||||
|
||||
public int $teamId;
|
||||
public int $leagueId;
|
||||
public int $userWhoFiredEventId;
|
||||
public int $userToNotifyId;
|
||||
public bool $isRead;
|
||||
public \DateTimeImmutable $readAt;
|
||||
public \DateTimeImmutable $createdAt;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id ?? '',
|
||||
'type' => $this->type ?? '',
|
||||
'message' => $this->message ?? '',
|
||||
'teamId' => $this->teamId ?? '',
|
||||
'leagueId' => $this->leagueId ?? '',
|
||||
'isRead' => $this->isRead ?? false,
|
||||
'readAt' => !empty($this->readAt) ? $this->readAt->format('Y-m-d H:i:s') : '',
|
||||
'createdAt' => !empty($this->createdAt) ? $this->createdAt->format('Y-m-d H:i:s') : ''
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['type']))
|
||||
{
|
||||
$this->type = match($dataList['type']) {
|
||||
self::$TYPE_JOIN_LEAGUE => 'JOIN_LEAGUE',
|
||||
self::$TYPE_JOIN_TEAM => 'JOIN_TEAM',
|
||||
self::$TYPE_CAPTAIN_REQUEST => 'CAPTAIN_REQUEST',
|
||||
default => null
|
||||
};
|
||||
}
|
||||
if (!empty($dataList['message']))
|
||||
{
|
||||
$this->message = $dataList['message'];
|
||||
}
|
||||
if (!empty($dataList['isRead']))
|
||||
{
|
||||
$this->isRead = $dataList['isRead'];
|
||||
}
|
||||
if (!empty($dataList['readAt']))
|
||||
{
|
||||
$this->readAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['readAt']);
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
|
||||
}
|
||||
if (isset($dataList['teamId']))
|
||||
{
|
||||
$this->teamId = (int) $dataList['teamId'];
|
||||
}
|
||||
if (isset($dataList['userWhoFiredEventId']))
|
||||
{
|
||||
$this->userWhoFiredEventId = $dataList['userWhoFiredEventId'];
|
||||
}
|
||||
if (isset($dataList['userToNotifyId']))
|
||||
{
|
||||
$this->userToNotifyId = $dataList['userToNotifyId'];
|
||||
}
|
||||
if (isset($dataList['leagueId']))
|
||||
{
|
||||
$this->leagueId = $dataList['leagueId'];
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObj(Notification $notificationObj): self
|
||||
{
|
||||
if ($notificationObj->getId() !== null)
|
||||
{
|
||||
$this->id = $notificationObj->getId();
|
||||
}
|
||||
if ($notificationObj->getType() !== null)
|
||||
{
|
||||
$this->type = $notificationObj->getType();
|
||||
}
|
||||
if ($notificationObj->getMessage() !== null)
|
||||
{
|
||||
$this->message = $notificationObj->getMessage();
|
||||
}
|
||||
if ($notificationObj->getUserWhoFiredEvent() !== null)
|
||||
{
|
||||
$this->userWhoFiredEventId = ($notificationObj->getUserWhoFiredEvent())->getId();
|
||||
}
|
||||
if ($notificationObj->getUserToNotify() !== null)
|
||||
{
|
||||
$this->userToNotifyId = ($notificationObj->getUserToNotify())->getId();
|
||||
}
|
||||
if ($notificationObj->getLeague() !== null)
|
||||
{
|
||||
$this->leagueId = ($notificationObj->getLeague())->getId();
|
||||
}
|
||||
if ($notificationObj->getTeamId() !== null)
|
||||
{
|
||||
$this->teamId = $notificationObj->getTeamId();
|
||||
}
|
||||
if ($notificationObj->isIsRead() !== null)
|
||||
{
|
||||
$this->isRead = $notificationObj->isIsRead();
|
||||
}
|
||||
if ($notificationObj->getReadAt() !== null)
|
||||
{
|
||||
$this->readAt = $notificationObj->getReadAt();
|
||||
}
|
||||
if ($notificationObj->getCreatedAt() !== null)
|
||||
{
|
||||
$this->createdAt = $notificationObj->getCreatedAt();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Player;
|
||||
|
||||
class PlayerDto
|
||||
{
|
||||
public int $id;
|
||||
public string $firstName;
|
||||
public string $lastName;
|
||||
public string $position;
|
||||
public int $jerseyNumber;
|
||||
public bool $isFederated;
|
||||
public string $pictureFileName;
|
||||
public \DateTime $birthday;
|
||||
public array $fileDtoList;
|
||||
public TeamDto $teamDto;
|
||||
public \DateTime $createdAt;
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['firstName']))
|
||||
{
|
||||
$this->firstName = $dataList['firstName'];
|
||||
}
|
||||
if (!empty($dataList['lastName']))
|
||||
{
|
||||
$this->lastName = $dataList['lastName'];
|
||||
}
|
||||
if (!empty($dataList['position']))
|
||||
{
|
||||
$this->position = $dataList['position'];
|
||||
}
|
||||
if (!isset($dataList['jerseyNumber']))
|
||||
{
|
||||
$this->jerseyNumber = (int) $dataList['jerseyNumber'];
|
||||
}
|
||||
if (isset($dataList['isFederated']))
|
||||
{
|
||||
$this->isFederated = (bool) $dataList['isFederated'];
|
||||
}
|
||||
if (isset($dataList['pictureFileName']))
|
||||
{
|
||||
$this->pictureFileName = $dataList['pictureFileName'];
|
||||
}
|
||||
if (!empty($dataList['birthday']))
|
||||
{
|
||||
$this->birthday = \DateTime::createFromFormat('Y-m-d', $dataList['birthday']);
|
||||
}
|
||||
if (!empty($dataList['fileList']))
|
||||
{
|
||||
foreach ($dataList['fileList'] as $fileItem)
|
||||
{
|
||||
$fileDto = new FileDto();
|
||||
$fileDto->fillFromArray($fileItem);
|
||||
$this->fileDtoList[] = $fileDto;
|
||||
}
|
||||
}
|
||||
if (!empty($dataList['team']))
|
||||
{
|
||||
$teamDto = new TeamDto();
|
||||
$teamDto->fillFromArray($dataList['team']);
|
||||
$this->teamDto = $teamDto;
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTime::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(Player $playerEntity): void
|
||||
{
|
||||
if ($playerEntity->getId() !== null)
|
||||
{
|
||||
$this->id = $playerEntity->getId();
|
||||
}
|
||||
if ($playerEntity->getFirstName() !== null)
|
||||
{
|
||||
$this->firstName = $playerEntity->getFirstName();
|
||||
}
|
||||
if ($playerEntity->getLastName() !== null)
|
||||
{
|
||||
$this->lastName = $playerEntity->getLastName();
|
||||
}
|
||||
if ($playerEntity->getBirthday() !== null)
|
||||
{
|
||||
$this->birthday = new \DateTime($playerEntity->getBirthday()->format('Y-m-d'),new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
if ($playerEntity->getJerseyNumber() !== null)
|
||||
{
|
||||
$this->jerseyNumber = $playerEntity->getJerseyNumber();
|
||||
}
|
||||
if ($playerEntity->getPosition() !== null)
|
||||
{
|
||||
$this->position = $playerEntity->getPosition();
|
||||
}
|
||||
if ($playerEntity->getPictureFileName() !== null)
|
||||
{
|
||||
$this->pictureFileName = $playerEntity->getPictureFileName();
|
||||
}
|
||||
if ($playerEntity->getTeam() !== null)
|
||||
{
|
||||
$teamDto = new TeamDto();
|
||||
$teamDto->fillFromObject($playerEntity->getTeam());
|
||||
$this->teamDto = $teamDto;
|
||||
}
|
||||
if ($playerEntity->getFiles() !== null)
|
||||
{
|
||||
foreach ($playerEntity->getFiles() as $fileEntity)
|
||||
{
|
||||
$fileDto = new FileDto();
|
||||
$fileDto->fillFromObject($fileEntity);
|
||||
$this->fileDtoList[] = $fileDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
class SeasonDataDto
|
||||
{
|
||||
public int $id;
|
||||
public int $teamId;
|
||||
public int $points;
|
||||
public int $seasonId;
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = (int) $dataList['id'];
|
||||
}
|
||||
if (isset($dataList['teamId']))
|
||||
{
|
||||
$this->teamId = $dataList['teamId'];
|
||||
}
|
||||
if (isset($dataList['points']))
|
||||
{
|
||||
$this->points = $dataList['points'];
|
||||
}
|
||||
if (isset($dataList['seasonId']))
|
||||
{
|
||||
$this->seasonId = $dataList['seasonId'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Season;
|
||||
use DMD\LaLigaApi\Exception\ValidationException;
|
||||
|
||||
class SeasonDto
|
||||
{
|
||||
public int $id;
|
||||
public \DateTime $dateStart;
|
||||
public array $teamDtoList;
|
||||
public array $facilityDtoList;
|
||||
public int $leagueId;
|
||||
public array $gameDtoList;
|
||||
public array $seasonDataDtoList;
|
||||
public bool $active;
|
||||
public array $validationErrors;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$teamList = [];
|
||||
$facilityList = [];
|
||||
if (!empty($this->teamDtoList))
|
||||
{
|
||||
foreach ($this->teamDtoList as $teamDto)
|
||||
{
|
||||
$teamList[] = $teamDto->toArray();
|
||||
}
|
||||
}
|
||||
if (!empty($this->facilityDtoList))
|
||||
{
|
||||
foreach ($this->facilityDtoList as $facilityDto)
|
||||
{
|
||||
$facilityList[] = $facilityDto->toArray();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $this->id ?? null,
|
||||
'dateStart' => !empty($this->dateStart) ? $this->dateStart->format('Y-m'): null,
|
||||
'leagueId' => $this->leagueId ?? null,
|
||||
'teamList' => $teamList,
|
||||
'facilityList' => $facilityList,
|
||||
'active' => $this->active ?? null
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = (int) $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['dateStart']))
|
||||
{
|
||||
$dateStart = \DateTime::createFromFormat('Y-m' ,$dataList['dateStart']);
|
||||
if ($dateStart)
|
||||
{
|
||||
$this->dateStart = $dateStart;
|
||||
}
|
||||
}
|
||||
if (isset($dataList['active']))
|
||||
{
|
||||
$this->active = $dataList['active'];
|
||||
}
|
||||
if (isset($dataList['teamList']))
|
||||
{
|
||||
foreach ($dataList['teamList'] as $teamName)
|
||||
{
|
||||
$teamDto = new TeamDto();
|
||||
$teamDto->name = $teamName;
|
||||
$this->teamDtoList[] = $teamDto;
|
||||
}
|
||||
}
|
||||
if (!empty($dataList['facilityList']))
|
||||
{
|
||||
foreach ($dataList['facilityList'] as $facilityItem)
|
||||
{
|
||||
$facilityDto = new FacilityDto();
|
||||
$facilityDto->fillFromArray($facilityItem);
|
||||
$this->facilityDtoList[] = $facilityDto;
|
||||
}
|
||||
}
|
||||
if (isset($dataList['gameList']))
|
||||
{
|
||||
foreach ($dataList['gameList'] as $gameItem)
|
||||
{
|
||||
$gameDto = new GameDto();
|
||||
$gameDto->fillFromArray($gameItem);
|
||||
$this->gameDtoList[] = $gameDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(Season $seasonObj): void
|
||||
{
|
||||
if ($seasonObj->getId() !== null)
|
||||
{
|
||||
$this->id = $seasonObj->getId();
|
||||
}
|
||||
if ($seasonObj->getDateStart() !== null)
|
||||
{
|
||||
$this->dateStart = $seasonObj->getDateStart();
|
||||
}
|
||||
$leagueObj = $seasonObj->getLeague();
|
||||
if ($leagueObj !== null)
|
||||
{
|
||||
$this->leagueId = $leagueObj->getId();
|
||||
}
|
||||
if ($leagueObj->isActive() !== null)
|
||||
{
|
||||
$this->active = $leagueObj->isActive();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
if (!empty($this->validationErrors))
|
||||
{
|
||||
throw new ValidationException($this->validationErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\Facility;
|
||||
use DMD\LaLigaApi\Entity\Team;
|
||||
use DMD\LaLigaApi\Exception\ValidationException;
|
||||
|
||||
class TeamDto
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public bool $active;
|
||||
public array $seasonDtoList;
|
||||
public array $playerDtoList;
|
||||
public array $validationErrors;
|
||||
public UserDto $captainDto;
|
||||
public \DateTimeImmutable $createdAt;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$seasonList = [];
|
||||
$playerList = [];
|
||||
if (!empty($this->seasonDtoList))
|
||||
{
|
||||
foreach ($this->seasonDtoList as $seasonDto)
|
||||
{
|
||||
$seasonList = $seasonDto->toArray();
|
||||
}
|
||||
}
|
||||
if (!empty($this->playerDtoList))
|
||||
{
|
||||
foreach ($this->playerDtoList as $playerDto)
|
||||
{
|
||||
$playerList = $playerDto->toArray();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'name' => $this->name ?? '',
|
||||
'playerList' => $playerList,
|
||||
'seasonList' => $seasonList,
|
||||
'captainId' => $this->captainDto?->id,
|
||||
'createdAt' => $this->createdAt->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (isset($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['name']))
|
||||
{
|
||||
$this->name = $dataList['name'];
|
||||
}
|
||||
if (isset($dataList['active']))
|
||||
{
|
||||
$this->active = $dataList['active'];
|
||||
}
|
||||
if (!empty($dataList['seasonList']))
|
||||
{
|
||||
foreach ($dataList['seasonList'] as $seasonItem)
|
||||
{
|
||||
$seasonDto = new SeasonDto();
|
||||
$seasonDto->fillFromArray($seasonItem);
|
||||
$this->seasonDtoList[] = $seasonDto;
|
||||
}
|
||||
}
|
||||
if (!empty($dataList['playerList']))
|
||||
{
|
||||
foreach ($dataList['playerList'] as $playerItem)
|
||||
{
|
||||
$playerDto = new PlayerDto();
|
||||
$playerDto->fillFromArray($playerItem);
|
||||
$this->playerDtoList[] = $playerDto;
|
||||
}
|
||||
}
|
||||
if (!empty($dataList['captain']))
|
||||
{
|
||||
$captainDto = new UserDto();
|
||||
$captainDto->fillFromArray($dataList['captain']);
|
||||
$this->captainDto = $captainDto;
|
||||
}
|
||||
if (!empty($dataList['createdAt']))
|
||||
{
|
||||
$this->createdAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['createdAt'], new \DateTimeZone('Europe/Madrid'));
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromObject(Team $teamEntity): void
|
||||
{
|
||||
if ($teamEntity->getId())
|
||||
{
|
||||
$this->id = $teamEntity->getId();
|
||||
}
|
||||
if ($teamEntity->getName())
|
||||
{
|
||||
$this->name = $teamEntity->getName();
|
||||
}
|
||||
if ($teamEntity->getPlayers())
|
||||
{
|
||||
foreach ($teamEntity->getPlayers() as $playerEntity)
|
||||
{
|
||||
$playerDto = new PlayerDto();
|
||||
$playerDto->fillFromObject($playerEntity);
|
||||
$this->playerDtoList[] = $playerDto;
|
||||
}
|
||||
}
|
||||
if ($teamEntity->getCreatedAt())
|
||||
{
|
||||
$this->createdAt = $teamEntity->getCreatedAt();
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
if (empty($this->name))
|
||||
{
|
||||
$this->validationErrors[] = 'El nombre del equipo no puede estar vacío.';
|
||||
}
|
||||
if (!empty($this->validationErrors))
|
||||
{
|
||||
throw new ValidationException($this->validationErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace DMD\LaLigaApi\Dto;
|
||||
|
||||
use DMD\LaLigaApi\Entity\User;
|
||||
|
||||
class UserDto
|
||||
{
|
||||
public int $id;
|
||||
public array $roles;
|
||||
public string $email;
|
||||
public string $password;
|
||||
public string $firstName;
|
||||
public string $lastName;
|
||||
public string $phone;
|
||||
public string $profilePicture;
|
||||
public \DateTimeInterface $birthday;
|
||||
public array $noteList;
|
||||
public bool $active;
|
||||
public array $notificationDtoList;
|
||||
public array $validationErrors;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
if (!empty($this->notificationDtoList))
|
||||
{
|
||||
foreach ($this->notificationDtoList as $notificationDto)
|
||||
{
|
||||
$notificationArray[] = $notificationDto->toArray();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $this->id ?? null,
|
||||
'email' => $this->email ?? null,
|
||||
'firstName' => $this->firstName ?? null,
|
||||
'lastName' => $this->lastName ?? null,
|
||||
'phone' => $this->phone,
|
||||
'profilePicture' => $this->profilePicture ?? null,
|
||||
'birthday' => $this->birthday->format('Y-m-d'),
|
||||
'noteList' => $this->noteList ?? [],
|
||||
'notificationList' => $notificationArray ?? []
|
||||
];
|
||||
}
|
||||
|
||||
public function fillFromObject(User $userObj): void
|
||||
{
|
||||
if ($userObj->getId() !== null)
|
||||
{
|
||||
$this->id = $userObj->getId();
|
||||
}
|
||||
if ($userObj->getEmail() !== null)
|
||||
{
|
||||
$this->email = $userObj->getEmail();
|
||||
}
|
||||
if ($userObj->getFirstName() !== null)
|
||||
{
|
||||
$this->firstName = $userObj->getFirstName();
|
||||
}
|
||||
if ($userObj->getLastName() !== null)
|
||||
{
|
||||
$this->lastName = $userObj->getLastName();
|
||||
}
|
||||
if ($userObj->getPhone() !== null)
|
||||
{
|
||||
$this->phone = $userObj->getPhone();
|
||||
}
|
||||
if ($userObj->getProfilePicture() !== null)
|
||||
{
|
||||
$this->profilePicture = $userObj->getProfilePicture();
|
||||
}
|
||||
if ($userObj->getBirthday() !== null)
|
||||
{
|
||||
$this->birthday = $userObj->getBirthday();
|
||||
}
|
||||
if ($userObj->getNoteList() !== null)
|
||||
{
|
||||
$this->noteList = $userObj->getNoteList();
|
||||
}
|
||||
}
|
||||
|
||||
public function fillFromArray(array $dataList): void
|
||||
{
|
||||
if (!empty($dataList['id']))
|
||||
{
|
||||
$this->id = $dataList['id'];
|
||||
}
|
||||
if (!empty($dataList['email']))
|
||||
{
|
||||
$this->email = trim($dataList['email']);
|
||||
}
|
||||
if (!empty($dataList['password']))
|
||||
{
|
||||
$this->password = trim($dataList['password']);
|
||||
}
|
||||
if (!empty($dataList['firstName']))
|
||||
{
|
||||
$this->firstName = $dataList['firstName'];
|
||||
}
|
||||
if (!empty($dataList['lastName']))
|
||||
{
|
||||
$this->lastName = $dataList['lastName'];
|
||||
}
|
||||
if (!empty($dataList['phone']))
|
||||
{
|
||||
$this->phone = $dataList['phone'];
|
||||
}
|
||||
if (!empty($dataList['profilePicture']))
|
||||
{
|
||||
$this->profilePicture = $dataList['profilePicture'];
|
||||
}
|
||||
if (!empty($dataList['birthday']))
|
||||
{
|
||||
$this->birthday = \DateTime::createFromFormat('Y-m-d', $dataList['birthday']);
|
||||
}
|
||||
if (!empty($dataList['notes']))
|
||||
{
|
||||
$this->noteList = $dataList['notes'];
|
||||
}
|
||||
if (isset($dataList['active']))
|
||||
{
|
||||
$this->active = $dataList['active'];
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
if (empty($this->email))
|
||||
{
|
||||
$this->validationErrors[] = 'El correo no puede estar vacío.';
|
||||
}
|
||||
if (!empty($this->email) && !(filter_var($this->email, FILTER_VALIDATE_EMAIL)))
|
||||
{
|
||||
$this->validationErrors[] = 'El correo no está en un formato válido.';
|
||||
}
|
||||
if (empty($this->firstName))
|
||||
{
|
||||
$this->validationErrors[] = 'El nombre no puede estar vacío';
|
||||
}
|
||||
if (empty($this->lastName))
|
||||
{
|
||||
$this->validationErrors[] = 'El apellido no puede estar vacío';
|
||||
}
|
||||
if (strlen($this->phone) !== 9)
|
||||
{
|
||||
$this->validationErrors[] = 'El número de teléfono debe tener 9 dígitos.';
|
||||
}
|
||||
if (!preg_match('@[A-Z]@', $this->password))
|
||||
{
|
||||
$this->validationErrors[] = 'La contraseña debe contener al menos una letra mayúscula.';
|
||||
}
|
||||
if (!preg_match('@[0-9]@', $this->password))
|
||||
{
|
||||
$this->validationErrors[] = 'La contraseña debe contener al menos un número.';
|
||||
}
|
||||
if (!preg_match('@\W@', $this->password))
|
||||
{
|
||||
$this->validationErrors[] = 'La contraseña debe contener al menos un caracter especial.';
|
||||
}
|
||||
if (strlen($this->password) < 8)
|
||||
{
|
||||
$this->validationErrors[] = 'La contraseña debe contener al menos 8 caracteres.';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user