src/Entity/Product.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\Helper\NormalizerHelper;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use \Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * @ORM\Table(name="products__products", uniqueConstraints={
  9.  *     @ORM\UniqueConstraint(name="unique_product", columns={"article_search", "brand_id"})}
  10.  * )
  11.  * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
  12.  */
  13. class Product
  14. {
  15.     use IdTrait;
  16.     /**
  17.      * @ORM\ManyToOne(targetEntity="App\Entity\Brand")
  18.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  19.      */
  20.     private Brand $brand;
  21.     /**
  22.      * @ORM\Column(name="article_search", type="string", nullable=false)
  23.      */
  24.     private string $articleSearch;
  25.     /**
  26.      * @ORM\Column(name="article_original", type="string", nullable=false)
  27.      */
  28.     private string $articleOriginal;
  29.     /**
  30.      * @ORM\Column(name="description", type="text", nullable=false)
  31.      */
  32.     private string $description;
  33.     /**
  34.      * @var Item[]|Collection
  35.      * @ORM\OneToMany(targetEntity="App\Entity\Item", mappedBy="product")
  36.      */
  37.     private $items;
  38.     /**
  39.      * @var SupplierItem[]|Collection
  40.      * @ORM\OneToMany(targetEntity="SupplierItem", mappedBy="product")
  41.      */
  42.     private $supplierItems;
  43.     /**
  44.      * @var ProductImage[]|Collection
  45.      * @ORM\OneToMany(targetEntity="App\Entity\ProductImage", mappedBy="product")
  46.      */
  47.     private $images;
  48.     /**
  49.      * @var Collection|Analog[]
  50.      * @ORM\OneToMany(targetEntity="App\Entity\Analog", mappedBy="owner", cascade={"all"})
  51.      */
  52.     private $analogs;
  53.     /**
  54.      * @ORM\OneToOne(targetEntity="Storage", mappedBy="product")
  55.      */
  56.     private ?Storage $storage null;
  57.     public function __construct(Brand $brandstring $articlestring $description)
  58.     {
  59.         $this->brand $brand;
  60.         $this->articleOriginal $article;
  61.         $this->description $description;
  62.         $this->articleSearch NormalizerHelper::transformToArticleSearch($article);
  63.         $this->items = new ArrayCollection();
  64.         $this->supplierItems = new ArrayCollection();
  65.         $this->images = new ArrayCollection();
  66.         $this->analogs = new ArrayCollection();
  67.     }
  68.     /**
  69.      * @return Collection|ProductImage[]
  70.      */
  71.     public function getImages()
  72.     {
  73.         return $this->images;
  74.     }
  75.     public function getDefaultImageSrc(): ?string
  76.     {
  77.         $src $this->getImages()->count() ? $this->getImages()->first()->getHash() : null;
  78.         return !$src || !file_exists($src) ? '/assets/img/nopic.jpg' $src;
  79.     }
  80.     public function addImage(ProductImage $image): Product
  81.     {
  82.         $this->images->add($image);
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection|Item[]
  87.      */
  88.     public function getItems()
  89.     {
  90.         return $this->items;
  91.     }
  92.     /**
  93.      * @return Collection|SupplierItem[]
  94.      */
  95.     public function getSupplierItems()
  96.     {
  97.         return $this->supplierItems;
  98.     }
  99.     public function addItem(Item $item): Product
  100.     {
  101.         $this->items->add($item);
  102.         return $this;
  103.     }
  104.     public function getArticleSearch(): string
  105.     {
  106.         return $this->articleSearch;
  107.     }
  108.     public function getBrand(): Brand
  109.     {
  110.         return $this->brand;
  111.     }
  112.     public function getBrandName(): string
  113.     {
  114.         return $this->getBrand()->getName();
  115.     }
  116.     public function setBrand(Brand $brand): Product
  117.     {
  118.         $this->brand $brand;
  119.         return $this;
  120.     }
  121.     public function getArticleOriginal(): string
  122.     {
  123.         return $this->articleOriginal;
  124.     }
  125.     public function getDescription(): string
  126.     {
  127.         return $this->description;
  128.     }
  129.     public function setDescription(string $description): Product
  130.     {
  131.         $this->description $description;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Analog[]|Collection
  136.      */
  137.     public function getAnalogs()
  138.     {
  139.         return $this->analogs;
  140.     }
  141.     public function getStorage(): ?Storage
  142.     {
  143.         return $this->storage;
  144.     }
  145. }