src/Entity/Lot.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LotRepository;
  4. use App\Trait\ActivableTrait;
  5. use App\Trait\DateTrait;
  6. use DateTime;
  7. use DateTimeImmutable;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. #[ORM\Entity(repositoryClassLotRepository::class)]
  12. class Lot
  13. {
  14.     use ActivableTrait;
  15.     use DateTrait;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $reference null;
  22.     #[ORM\Column]
  23.     private ?int $start null;
  24.     #[ORM\Column]
  25.     private ?int $end null;
  26.     #[ORM\Column(length255)]
  27.     private ?string $series null;
  28.     #[ORM\OneToMany(mappedBy'lot'targetEntityTicket::class, cascade: ['persist''remove'])]
  29.     private Collection $tickets;
  30.     #[ORM\ManyToOne]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private ?Establishment $establishment null;
  33.     #[ORM\ManyToOne(inversedBy'lots')]
  34.     private ?Department $department null;
  35.     #[ORM\ManyToOne(inversedBy'lots')]
  36.     #[ORM\JoinColumn(nullablefalse)]
  37.     private ?LotConfiguration $configuration null;
  38.     #[ORM\OneToMany(mappedBy'lot'targetEntityCard::class)]
  39.     private Collection $cards;
  40.     public function __construct()
  41.     {
  42.         $this->isActive true;
  43.         if (is_null($this->reference)) $this->reference strtoupper(uniqid('LOT-'));
  44.         if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();
  45.         $this->updatedAt = new DateTimeImmutable();
  46.         $this->tickets = new ArrayCollection();
  47.         $this->cards = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getReference(): ?string
  54.     {
  55.         return $this->reference;
  56.     }
  57.     public function setReference(string $reference): self
  58.     {
  59.         $this->reference $reference;
  60.         return $this;
  61.     }
  62.     public function getStart(): ?int
  63.     {
  64.         return $this->start;
  65.     }
  66.     public function setStart(int $start): self
  67.     {
  68.         $this->start $start;
  69.         return $this;
  70.     }
  71.     public function getEnd(): ?int
  72.     {
  73.         return $this->end;
  74.     }
  75.     public function setEnd(int $end): self
  76.     {
  77.         $this->end $end;
  78.         return $this;
  79.     }
  80.     public function getSeries(): ?string
  81.     {
  82.         return $this->series;
  83.     }
  84.     public function setSeries(string $series): self
  85.     {
  86.         $this->series $series;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection<int, Ticket>
  91.      */
  92.     public function getTickets(): Collection
  93.     {
  94.         return $this->tickets;
  95.     }
  96.     public function addTicket(Ticket $ticket): self
  97.     {
  98.         if (!$this->tickets->contains($ticket)) {
  99.             $this->tickets->add($ticket);
  100.             $ticket->setLot($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeTicket(Ticket $ticket): self
  105.     {
  106.         if ($this->tickets->removeElement($ticket)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($ticket->getLot() === $this) {
  109.                 $ticket->setLot(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114.     public function getEstablishment(): ?Establishment
  115.     {
  116.         return $this->establishment;
  117.     }
  118.     public function setEstablishment(?Establishment $establishment): self
  119.     {
  120.         $this->establishment $establishment;
  121.         return $this;
  122.     }
  123.     public function getDepartment(): ?Department
  124.     {
  125.         return $this->department;
  126.     }
  127.     public function setDepartment(?Department $department): self
  128.     {
  129.         $this->department $department;
  130.         return $this;
  131.     }
  132.     public function getConfiguration(): ?LotConfiguration
  133.     {
  134.         return $this->configuration;
  135.     }
  136.     public function setConfiguration(?LotConfiguration $configuration): self
  137.     {
  138.         $this->configuration $configuration;
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return Collection<int, Card>
  143.      */
  144.     public function getCards(): Collection
  145.     {
  146.         return $this->cards;
  147.     }
  148.     public function addCard(Card $card): static
  149.     {
  150.         if (!$this->cards->contains($card)) {
  151.             $this->cards->add($card);
  152.             $card->setLot($this);
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeCard(Card $card): static
  157.     {
  158.         if ($this->cards->removeElement($card)) {
  159.             // set the owning side to null (unless already changed)
  160.             if ($card->getLot() === $this) {
  161.                 $card->setLot(null);
  162.             }
  163.         }
  164.         return $this;
  165.     }
  166. }