src/Entity/Item.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Enum\ItemType;
  4. use App\Entity\Traits\Identifiable;
  5. use App\Entity\Traits\Sortable;
  6. use App\Repository\ItemRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. #[ORM\Entity(repositoryClassItemRepository::class)]
  11. class Item
  12. {
  13.     use Identifiable;
  14.     use Sortable;
  15.     #[ORM\Column(type'string'length10enumTypeItemType::class)]
  16.     private $type;
  17.     #[ORM\Column(type'string'length100)]
  18.     private $name;
  19.     #[ORM\Column(type'smallint')]
  20.     private $price;
  21.     #[ORM\OneToMany(mappedBy'item'targetEntityItemVariation::class, cascade: ['persist'])]
  22.     private $variations;
  23.     #[ORM\OneToOne(targetEntityFileItem::class, cascade: ['persist''remove'])]
  24.     private $file;
  25.     #[ORM\Column(type'boolean')]
  26.     private $isDisplayed true;
  27.     public function __construct()
  28.     {
  29.         $this->variations = new ArrayCollection();
  30.     }
  31.     public function getType(): ?ItemType
  32.     {
  33.         return $this->type;
  34.     }
  35.     public function setType(ItemType $type): self
  36.     {
  37.         $this->type $type;
  38.         return $this;
  39.     }
  40.     public function getName(): ?string
  41.     {
  42.         return $this->name;
  43.     }
  44.     public function setName(string $name): self
  45.     {
  46.         $this->name $name;
  47.         return $this;
  48.     }
  49.     public function getPrice(): ?int
  50.     {
  51.         return $this->price;
  52.     }
  53.     public function setPrice(int $price): self
  54.     {
  55.         $this->price $price;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, ItemVariation>
  60.      */
  61.     public function getVariations(): Collection
  62.     {
  63.         return $this->variations;
  64.     }
  65.     public function addVariation(ItemVariation $variation): self
  66.     {
  67.         if (!$this->variations->contains($variation)) {
  68.             $this->variations[] = $variation;
  69.             $variation->setItem($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeVariation(ItemVariation $variation): self
  74.     {
  75.         if ($this->variations->removeElement($variation)) {
  76.             // set the owning side to null (unless already changed)
  77.             if ($variation->getItem() === $this) {
  78.                 $variation->setItem(null);
  79.             }
  80.         }
  81.         return $this;
  82.     }
  83.     public function getFile(): ?FileItem
  84.     {
  85.         return $this->file;
  86.     }
  87.     public function setFile(?FileItem $file): self
  88.     {
  89.         $this->file $file;
  90.         return $this;
  91.     }
  92.     public function getIsDisplayed(): ?bool
  93.     {
  94.         return $this->isDisplayed;
  95.     }
  96.     public function setIsDisplayed(bool $isDisplayed): self
  97.     {
  98.         $this->isDisplayed $isDisplayed;
  99.         return $this;
  100.     }
  101. }