src/Entity/Product/ProductBoughtTogether.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Product;
  3. use App\Repository\Product\ProductBoughtTogetherRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassProductBoughtTogetherRepository::class)]
  6. class ProductBoughtTogether
  7. {
  8.     #[ORM\Id]
  9.     #[ORM\GeneratedValue]
  10.     #[ORM\Column]
  11.     private ?int $id null;
  12.     #[ORM\ManyToOne(inversedBy'productBoughtTogethers')]
  13.     private ?Product $product null;
  14.     #[ORM\ManyToOne(targetEntityProduct::class)]
  15.     private ?Product $boughtWith null;
  16.     #[ORM\Column(type'integer')]
  17.     private int $timesBoughtTogether 1;
  18.     #[ORM\Column(type'boolean')]
  19.     private bool $isManual false;
  20.     #[ORM\Column(type'datetime_immutable')]
  21.     private \DateTimeImmutable $createdAt;
  22.     public function getId(): ?int
  23.     {
  24.         return $this->id;
  25.     }
  26.     public function getProduct(): ?Product
  27.     {
  28.         return $this->product;
  29.     }
  30.     public function setProduct(?Product $product): static
  31.     {
  32.         $this->product $product;
  33.         return $this;
  34.     }
  35.     public function getBoughtWith(): ?Product
  36.     {
  37.         return $this->boughtWith;
  38.     }
  39.     public function setBoughtWith(?Product $boughtWith): static
  40.     {
  41.         if ($this->product && $boughtWith && $this->product === $boughtWith) {
  42.             throw new \InvalidArgumentException("Un produit ne peut pas être acheté avec lui-même.");
  43.         }
  44.         $this->boughtWith $boughtWith;
  45.         return $this;
  46.     }
  47.     public function getTimesBoughtTogether(): int
  48.     {
  49.         return $this->timesBoughtTogether;
  50.     }
  51.     public function setTimesBoughtTogether(int $timesBoughtTogether): static
  52.     {
  53.         if ($timesBoughtTogether 1) {
  54.             throw new \InvalidArgumentException("Le nombre de fois où les produits ont été achetés ensemble doit être au moins 1.");
  55.         }
  56.         $this->timesBoughtTogether $timesBoughtTogether;
  57.         return $this;
  58.     }
  59.     public function isManual(): bool
  60.     {
  61.         return $this->isManual;
  62.     }
  63.     public function setIsManual(bool $isManual): static
  64.     {
  65.         $this->isManual $isManual;
  66.         return $this;
  67.     }
  68.     public function getCreatedAt(): \DateTimeImmutable
  69.     {
  70.         return $this->createdAt;
  71.     }
  72.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  73.     {
  74.         $this->createdAt $createdAt;
  75.         return $this;
  76.     }
  77. }