src/Entity/Profiling.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Enum\ProfilingType;
  4. use App\Entity\Traits\Sortable;
  5. use App\Repository\ProfilingRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
  10. use Symfony\Component\Validator\Constraints\LessThanOrEqual;
  11. #[ORM\Entity(repositoryClassProfilingRepository::class)]
  12. class Profiling
  13. {
  14.     use Sortable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type'integer')]
  18.     private $id;
  19.     #[ORM\Column(type'string'length20enumTypeProfilingType::class)]
  20.     private $type;
  21.     #[ORM\Column(type'string'length150)]
  22.     private $name;
  23.     #[ORM\Column(type'text'nullabletrue)]
  24.     private $description;
  25.     #[ORM\Column(type'date_immutable'nullabletrue)]
  26.     #[GreaterThanOrEqual(propertyPath'minYear'message"Le maximum doit être supérieur ou égal au minimum")]
  27.     private $maxYear;
  28.     #[ORM\Column(type'date_immutable'nullabletrue)]
  29.     #[LessThanOrEqual(propertyPath'maxYear'message"Le minimum doit être inférieur ou égal au maximum")]
  30.     private $minYear;
  31.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'profilings')]
  32.     private $season;
  33.     #[ORM\OneToMany(mappedBy'profiling'targetEntityProfilingPerson::class, cascade: ['remove'])]
  34.     private $profilingPersons;
  35.     public function __construct()
  36.     {
  37.         $this->profilingPersons = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getType(): ?ProfilingType
  44.     {
  45.         return $this->type;
  46.     }
  47.     public function setType(ProfilingType $type): self
  48.     {
  49.         $this->type $type;
  50.         return $this;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getDescription(): ?string
  62.     {
  63.         return $this->description;
  64.     }
  65.     public function setDescription(?string $description): self
  66.     {
  67.         $this->description $description;
  68.         return $this;
  69.     }
  70.     public function getMaxYear(): ?\DateTimeImmutable
  71.     {
  72.         return $this->maxYear;
  73.     }
  74.     public function setMaxYear(?\DateTimeImmutable $maxYear): self
  75.     {
  76.         $this->maxYear $maxYear;
  77.         return $this;
  78.     }
  79.     public function getMinYear(): ?\DateTimeImmutable
  80.     {
  81.         return $this->minYear;
  82.     }
  83.     public function setMinYear(?\DateTimeImmutable $minYear): self
  84.     {
  85.         $this->minYear $minYear;
  86.         return $this;
  87.     }
  88.     public function getSeason(): ?Season
  89.     {
  90.         return $this->season;
  91.     }
  92.     public function setSeason(?Season $season): self
  93.     {
  94.         $this->season $season;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, ProfilingPerson>
  99.      */
  100.     public function getProfilingPersons(): Collection
  101.     {
  102.         return $this->profilingPersons;
  103.     }
  104.     public function addProfilingPerson(ProfilingPerson $profilingPerson): self
  105.     {
  106.         if (!$this->profilingPersons->contains($profilingPerson)) {
  107.             $this->profilingPersons[] = $profilingPerson;
  108.             $profilingPerson->setProfiling($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeProfilingPerson(ProfilingPerson $profilingPerson): self
  113.     {
  114.         if ($this->profilingPersons->removeElement($profilingPerson)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($profilingPerson->getProfiling() === $this) {
  117.                 $profilingPerson->setProfiling(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     public function __toString(): string
  123.     {
  124.         return $this->getName();
  125.     }
  126.     public function __clone()
  127.     {
  128.         $this->id null;
  129.         $this->profilingPersons = new ArrayCollection();
  130.         $this->season null;
  131.         if ($this->minYear) {
  132.             $minYear \DateTime::createFromImmutable($this->minYear);
  133.             $minYear->add(new \DateInterval('P1Y'));
  134.             $this->minYear \DateTimeImmutable::createFromMutable($minYear);
  135.         }
  136.         if ($this->maxYear) {
  137.             $maxYear \DateTime::createFromImmutable($this->maxYear);
  138.             $maxYear->add(new \DateInterval('P1Y'));
  139.             $this->maxYear \DateTimeImmutable::createFromMutable($maxYear);
  140.         }
  141.     }
  142. }