<?php
namespace App\Entity;
use App\Repository\ProductArticleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\SerializedName;
use App\Annotation\DashboardAnnotation as Dashboard;
use App\Annotation\FormBuildAnnotation as FormBuild;
/**
* @ORM\Entity(repositoryClass=ProductArticleRepository::class)
* @Dashboard(generation=true, name="Артикул")
* @ORM\Table(indexes={
* @ORM\Index(name="product_article_title_idx", columns={"title"})
* })
*/
class ProductArticle
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"collection", "selection/data", "selection/id"})
* @Dashboard(label="Номер", only=true)
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Groups({"collection", "selection/data", "selection/id"})
* @Dashboard(label="Название артикула")
* @FormBuild(component="input")
*/
private $title;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="productArticles")
* @ORM\JoinColumn(nullable=false)
* @Serializer\Groups({"collection"})
* @Dashboard(label="Продукция")
* @FormBuild(component="autocomplete", bindField="product", field="title", params={"nullable": false})
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity=Position::class, inversedBy="productArticles")
* @Serializer\Groups({"collection", "selection/data", "selection/id"})
* @ORM\JoinColumn(nullable=true)
* @Dashboard(label="Расположение")
* @FormBuild(component="autocomplete", bindField="position", field="title", params={"nullable": true})
*/
private $position;
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"collection"})
* @FormBuild(component="switch")
* @Dashboard(label="Скрыть на сайте", only=true, inverse=true)
*/
private $public = true;
/**
* @ORM\OneToMany(targetEntity=SelectionWiper::class, mappedBy="productArticle", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $selectionWipers;
/**
* @ORM\OneToMany(targetEntity=ProductOem::class, mappedBy="productArticle", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $productOems;
/**
* Текущие параметры подбора для артикула после приведения к формату API (один артикул - одни параметры подбора)
* \App\Repository\SelectionWiperRepository::createResponseAPI();
* @Serializer\Groups({"selection/data"})
*/
private $selection;
public function __construct()
{
$this->selectionWipers = new ArrayCollection();
$this->productOems = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function isPublic(): ?bool
{
return $this->public;
}
public function setPublic(bool $public): self
{
$this->public = $public;
return $this;
}
public function getPosition(): ?Position
{
return $this->position;
}
public function setPosition(?Position $position): self
{
$this->position = $position;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
/**
* @return Collection<int, Selection>
*/
public function getSelectionWipers(): Collection
{
return $this->selectionWipers;
}
public function addSelectionWipers(SelectionWiper $selectionWiper): self
{
if (!$this->selectionWipers->contains($selectionWiper)) {
$this->selectionWipers[] = $selectionWiper;
$selectionWiper->setProductArticle($this);
}
return $this;
}
public function removeSelectionWipers(SelectionWiper $selectionWiper): self
{
if ($this->selectionWipers->removeElement($selectionWiper)) {
// set the owning side to null (unless already changed)
if ($selectionWiper->getProductArticle() === $this) {
$selectionWiper->setProductArticle(null);
}
}
return $this;
}
/**
* @return Collection<int, Selection>
*/
public function getProductOems(): Collection
{
return $this->productOems;
}
/**
* @Serializer\Groups({"selection/data", "selection/id"})
* @SerializedName("oem")
*/
public function getProductOemsAsArray(): array
{
$result = [];
foreach($this->getProductOems() as $oem) {
$result[] = $oem->getOem();
}
return $result;
}
public function addProductOem(ProductOem $productOem): self
{
if (!$this->productOems->contains($productOem)) {
$this->productOems[] = $productOem;
$productOem->setProductArticle($this);
}
return $this;
}
public function removeProductOem(ProductOem $productOem): self
{
if ($this->productOems->removeElement($productOem)) {
// set the owning side to null (unless already changed)
if ($productOem->getProductArticle() === $this) {
$productOem->setProductArticle(null);
}
}
return $this;
}
public function clearProductOems(): self
{
$this->productOems = new ArrayCollection();
return $this;
}
public function setSelection(SelectionWiper $selection): self
{
$this->selection = $selection;
return $this;
}
public function getSelection(): ?SelectionWiper
{
return $this->selection;
}
}