291 lines
6.4 KiB
PHP
291 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace DMD\LaLigaApi\Entity;
|
|
|
|
use DMD\LaLigaApi\Repository\SeasonRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: SeasonRepository::class)]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
class Season
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
|
private ?\DateTimeInterface $dateStart = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?bool $active = null;
|
|
|
|
#[ORM\ManyToMany(targetEntity: Team::class, inversedBy: 'seasons')]
|
|
private Collection $teams;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'seasons')]
|
|
private ?League $league = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Game::class)]
|
|
private Collection $games;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?\DateTimeImmutable $createdAt = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'season', targetEntity: Facility::class)]
|
|
private Collection $facilities;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
|
private ?\DateTimeInterface $updatedAt = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'season', targetEntity: File::class)]
|
|
private Collection $files;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?int $pointsPerWin = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?int $pointsPerDraw = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?int $pointsPerLoss = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->teams = new ArrayCollection();
|
|
$this->games = new ArrayCollection();
|
|
$this->facilities = new ArrayCollection();
|
|
$this->files = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Team>
|
|
*/
|
|
public function getTeams(): Collection
|
|
{
|
|
return $this->teams;
|
|
}
|
|
|
|
public function addTeam(Team $team): static
|
|
{
|
|
if (!$this->teams->contains($team)) {
|
|
$this->teams->add($team);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeTeam(Team $team): static
|
|
{
|
|
$this->teams->removeElement($team);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateStart(): ?\DateTimeInterface
|
|
{
|
|
return $this->dateStart;
|
|
}
|
|
|
|
public function setDateStart(\DateTimeInterface $dateStart): static
|
|
{
|
|
$this->dateStart = $dateStart;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateEnd(): ?\DateTimeInterface
|
|
{
|
|
return $this->dateEnd;
|
|
}
|
|
|
|
public function setDateEnd(?\DateTimeInterface $dateEnd): static
|
|
{
|
|
$this->dateEnd = $dateEnd;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isActive(): ?bool
|
|
{
|
|
return $this->active;
|
|
}
|
|
|
|
public function setActive(?bool $active): static
|
|
{
|
|
$this->active = $active;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCreatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
#[ORM\PrePersist]
|
|
public function setCreatedAt(): void
|
|
{
|
|
$timezone = new \DateTimeZone('Europe/Madrid');
|
|
$this->createdAt = new \DateTimeImmutable('now', $timezone);
|
|
}
|
|
|
|
public function getLeague(): ?League
|
|
{
|
|
return $this->league;
|
|
}
|
|
|
|
public function setLeague(?League $league): static
|
|
{
|
|
$this->league = $league;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Game>
|
|
*/
|
|
public function getGames(): Collection
|
|
{
|
|
return $this->games;
|
|
}
|
|
|
|
public function addGame(Game $game): static
|
|
{
|
|
if (!$this->games->contains($game)) {
|
|
$this->games->add($game);
|
|
$game->setSeason($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeGame(Game $game): static
|
|
{
|
|
if ($this->games->removeElement($game)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($game->getSeason() === $this) {
|
|
$game->setSeason(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Facility>
|
|
*/
|
|
public function getFacilities(): Collection
|
|
{
|
|
return $this->facilities;
|
|
}
|
|
|
|
public function addFacility(Facility $facility): static
|
|
{
|
|
if (!$this->facilities->contains($facility)) {
|
|
$this->facilities->add($facility);
|
|
$facility->setSeason($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeFacility(Facility $facility): static
|
|
{
|
|
if ($this->facilities->removeElement($facility)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($facility->getSeason() === $this) {
|
|
$facility->setSeason(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?\DateTimeInterface
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?\DateTimeInterface $updatedAt): static
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, File>
|
|
*/
|
|
public function getFiles(): Collection
|
|
{
|
|
return $this->files;
|
|
}
|
|
|
|
public function addFile(File $file): static
|
|
{
|
|
if (!$this->files->contains($file)) {
|
|
$this->files->add($file);
|
|
$file->setSeason($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeFile(File $file): static
|
|
{
|
|
if ($this->files->removeElement($file)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($file->getSeason() === $this) {
|
|
$file->setSeason(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPointsPerWin(): ?int
|
|
{
|
|
return $this->pointsPerWin;
|
|
}
|
|
|
|
public function setPointsPerWin(?int $pointsPerWin): static
|
|
{
|
|
$this->pointsPerWin = $pointsPerWin;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPointsPerDraw(): ?int
|
|
{
|
|
return $this->pointsPerDraw;
|
|
}
|
|
|
|
public function setPointsPerDraw(?int $pointsPerDraw): static
|
|
{
|
|
$this->pointsPerDraw = $pointsPerDraw;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPointsPerLoss(): ?int
|
|
{
|
|
return $this->pointsPerLoss;
|
|
}
|
|
|
|
public function setPointsPerLoss(?int $pointsPerLoss): static
|
|
{
|
|
$this->pointsPerLoss = $pointsPerLoss;
|
|
|
|
return $this;
|
|
}
|
|
}
|