<?php
namespace App\Entity;
use App\Entity\Enum\ProfilingType;
use App\Entity\Traits\Sortable;
use App\Repository\ProfilingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
#[ORM\Entity(repositoryClass: ProfilingRepository::class)]
class Profiling
{
use Sortable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 20, enumType: ProfilingType::class)]
private $type;
#[ORM\Column(type: 'string', length: 150)]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
private $description;
#[ORM\Column(type: 'date_immutable', nullable: true)]
#[GreaterThanOrEqual(propertyPath: 'minYear', message: "Le maximum doit être supérieur ou égal au minimum")]
private $maxYear;
#[ORM\Column(type: 'date_immutable', nullable: true)]
#[LessThanOrEqual(propertyPath: 'maxYear', message: "Le minimum doit être inférieur ou égal au maximum")]
private $minYear;
#[ORM\ManyToOne(targetEntity: Season::class, inversedBy: 'profilings')]
private $season;
#[ORM\OneToMany(mappedBy: 'profiling', targetEntity: ProfilingPerson::class, cascade: ['remove'])]
private $profilingPersons;
public function __construct()
{
$this->profilingPersons = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?ProfilingType
{
return $this->type;
}
public function setType(ProfilingType $type): self
{
$this->type = $type;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getMaxYear(): ?\DateTimeImmutable
{
return $this->maxYear;
}
public function setMaxYear(?\DateTimeImmutable $maxYear): self
{
$this->maxYear = $maxYear;
return $this;
}
public function getMinYear(): ?\DateTimeImmutable
{
return $this->minYear;
}
public function setMinYear(?\DateTimeImmutable $minYear): self
{
$this->minYear = $minYear;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
/**
* @return Collection<int, ProfilingPerson>
*/
public function getProfilingPersons(): Collection
{
return $this->profilingPersons;
}
public function addProfilingPerson(ProfilingPerson $profilingPerson): self
{
if (!$this->profilingPersons->contains($profilingPerson)) {
$this->profilingPersons[] = $profilingPerson;
$profilingPerson->setProfiling($this);
}
return $this;
}
public function removeProfilingPerson(ProfilingPerson $profilingPerson): self
{
if ($this->profilingPersons->removeElement($profilingPerson)) {
// set the owning side to null (unless already changed)
if ($profilingPerson->getProfiling() === $this) {
$profilingPerson->setProfiling(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->getName();
}
public function __clone()
{
$this->id = null;
$this->profilingPersons = new ArrayCollection();
$this->season = null;
if ($this->minYear) {
$minYear = \DateTime::createFromImmutable($this->minYear);
$minYear->add(new \DateInterval('P1Y'));
$this->minYear = \DateTimeImmutable::createFromMutable($minYear);
}
if ($this->maxYear) {
$maxYear = \DateTime::createFromImmutable($this->maxYear);
$maxYear->add(new \DateInterval('P1Y'));
$this->maxYear = \DateTimeImmutable::createFromMutable($maxYear);
}
}
}