src/Entity/ProductArticle.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductArticleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation as Serializer;
  8. use Symfony\Component\Serializer\Annotation\SerializedName;
  9. use App\Annotation\DashboardAnnotation as Dashboard;
  10. use App\Annotation\FormBuildAnnotation as FormBuild;
  11. /**
  12.  * @ORM\Entity(repositoryClass=ProductArticleRepository::class)
  13.  * @Dashboard(generation=true, name="Артикул")
  14.  * @ORM\Table(indexes={
  15.  *     @ORM\Index(name="product_article_title_idx", columns={"title"})
  16.  * })
  17.  */
  18. class ProductArticle
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      * @Serializer\Groups({"collection", "selection/data", "selection/id"})
  25.      * @Dashboard(label="Номер", only=true)
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      * @Serializer\Groups({"collection", "selection/data", "selection/id"})
  31.      * @Dashboard(label="Название артикула")
  32.      * @FormBuild(component="input")
  33.      */
  34.     private $title;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="productArticles")
  37.      * @ORM\JoinColumn(nullable=false)
  38.      * @Serializer\Groups({"collection"}) 
  39.      * @Dashboard(label="Продукция")
  40.      * @FormBuild(component="autocomplete", bindField="product", field="title",  params={"nullable": false})
  41.      */
  42.     private $product;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Position::class, inversedBy="productArticles")
  45.      * @Serializer\Groups({"collection", "selection/data", "selection/id"})
  46.      * @ORM\JoinColumn(nullable=true)
  47.      * @Dashboard(label="Расположение")
  48.      * @FormBuild(component="autocomplete", bindField="position", field="title",  params={"nullable": true})
  49.      */
  50.     private $position;
  51.     /**
  52.      * @ORM\Column(type="boolean")
  53.      * @Serializer\Groups({"collection"}) 
  54.      * @FormBuild(component="switch")
  55.      * @Dashboard(label="Скрыть на сайте", only=true, inverse=true)
  56.      */
  57.     private $public true;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity=SelectionWiper::class, mappedBy="productArticle", cascade={"persist", "remove"}, orphanRemoval=true)
  60.      */
  61.     private $selectionWipers;
  62.     
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=ProductOem::class, mappedBy="productArticle", cascade={"persist", "remove"}, orphanRemoval=true)
  65.      */
  66.     private $productOems;
  67.     /**
  68.      * Текущие параметры подбора для артикула после приведения к формату API (один артикул - одни параметры подбора)
  69.      * \App\Repository\SelectionWiperRepository::createResponseAPI();
  70.      * @Serializer\Groups({"selection/data"}) 
  71.      */
  72.     private $selection;
  73.     public function __construct()
  74.     {
  75.         $this->selectionWipers = new ArrayCollection();
  76.         $this->productOems = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getTitle(): ?string
  83.     {
  84.         return $this->title;
  85.     }
  86.     public function setTitle(string $title): self
  87.     {
  88.         $this->title $title;
  89.         return $this;
  90.     }
  91.     public function isPublic(): ?bool
  92.     {
  93.         return $this->public;
  94.     }
  95.     public function setPublic(bool $public): self
  96.     {
  97.         $this->public $public;
  98.         return $this;
  99.     }
  100.     public function getPosition(): ?Position
  101.     {
  102.         return $this->position;
  103.     }
  104.     public function setPosition(?Position $position): self
  105.     {
  106.         $this->position $position;
  107.         return $this;
  108.     }
  109.     public function getProduct(): ?Product
  110.     {
  111.         return $this->product;
  112.     }
  113.     public function setProduct(?Product $product): self
  114.     {
  115.         $this->product $product;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, Selection>
  120.      */
  121.     public function getSelectionWipers(): Collection
  122.     {
  123.         return $this->selectionWipers;
  124.     }
  125.     public function addSelectionWipers(SelectionWiper $selectionWiper): self
  126.     {
  127.         if (!$this->selectionWipers->contains($selectionWiper)) {
  128.             $this->selectionWipers[] = $selectionWiper;
  129.             $selectionWiper->setProductArticle($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeSelectionWipers(SelectionWiper $selectionWiper): self
  134.     {
  135.         if ($this->selectionWipers->removeElement($selectionWiper)) {
  136.             // set the owning side to null (unless already changed)
  137.             if ($selectionWiper->getProductArticle() === $this) {
  138.                 $selectionWiper->setProductArticle(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, Selection>
  145.      */
  146.     public function getProductOems(): Collection
  147.     {
  148.         return $this->productOems;
  149.     }
  150.     /**
  151.      * @Serializer\Groups({"selection/data", "selection/id"}) 
  152.      * @SerializedName("oem") 
  153.      */
  154.     public function getProductOemsAsArray(): array
  155.     {
  156.         $result = [];
  157.         foreach($this->getProductOems() as $oem) {
  158.             $result[] = $oem->getOem();
  159.         }
  160.         return $result;
  161.     }
  162.     public function addProductOem(ProductOem $productOem): self
  163.     {
  164.         if (!$this->productOems->contains($productOem)) {
  165.             $this->productOems[] = $productOem;
  166.             $productOem->setProductArticle($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeProductOem(ProductOem $productOem): self
  171.     {
  172.         if ($this->productOems->removeElement($productOem)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($productOem->getProductArticle() === $this) {
  175.                 $productOem->setProductArticle(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     public function clearProductOems(): self 
  181.     {
  182.         $this->productOems = new ArrayCollection();
  183.         return $this;
  184.     }
  185.     public function setSelection(SelectionWiper $selection): self 
  186.     {
  187.         $this->selection $selection;
  188.         return $this;
  189.     }
  190.     public function getSelection(): ?SelectionWiper 
  191.     {
  192.         return $this->selection;
  193.     }
  194. }