src/Entity/VoucherCode.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. #[ORM\Entity]
  7. #[ORM\Table(name'voucher_code')]
  8. class VoucherCode
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\ManyToOne(targetEntityVoucher::class, inversedBy"codes")]
  15.     #[ORM\JoinColumn(name"voucher_id"referencedColumnName"id"onDelete"CASCADE"nullablefalse)]
  16.     private ?Voucher $voucher null;
  17.     #[ORM\Column(length50uniquetrueoptions: ['collation' => 'utf8mb4_bin'])]
  18.     private string $code;
  19.     #[ORM\OneToMany(mappedBy'voucherCode'targetEntityOrder::class)]
  20.     private Collection $orders;
  21.     public function __construct()
  22.     {
  23.         $this->orders = new ArrayCollection();
  24.     }
  25.     public function __toString(): string
  26.     {
  27.         return $this->code;
  28.     }
  29.     /**
  30.      * @return Collection<int, Order>
  31.      */
  32.     public function getOrders(): Collection
  33.     {
  34.         return $this->orders;
  35.     }
  36.     public function addOrder(Order $order): static
  37.     {
  38.         if (!$this->orders->contains($order)) {
  39.             $this->orders->add($order);
  40.             $order->setVoucherCode($this);
  41.         }
  42.         return $this;
  43.     }
  44.     public function removeOrder(Order $order): static
  45.     {
  46.         if ($this->orders->removeElement($order)) {
  47.             if ($order->getVoucherCode() === $this) {
  48.                 $order->setVoucherCode(null);
  49.             }
  50.         }
  51.         return $this;
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getVoucher(): ?Voucher
  58.     {
  59.         return $this->voucher;
  60.     }
  61.     public function setVoucher(?Voucher $voucher): self
  62.     {
  63.         $this->voucher $voucher;
  64.         return $this;
  65.     }
  66.     public function getCode(): string
  67.     {
  68.         return $this->code;
  69.     }
  70.     public function setCode(string $code): self
  71.     {
  72.         $this->code $code;
  73.         return $this;
  74.     }
  75. }