<?php
// src/Acme/UserBundle/Entity/User.php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use App\Model\LangParamInterface;
use App\Model\LangParamRelationInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @Doctrine\ORM\Mapping\Entity
* @Doctrine\ORM\Mapping\Table(name="product_family")
* @Doctrine\ORM\Mapping\Entity()
*/
class ProductFamily implements TranslatableInterface, LangParamInterface
, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="productFamily", cascade={"persist"})
*/
protected $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductFamilyLangParam", mappedBy="productFamily", cascade={"all"})
*/
protected $langParams;
public function __construct()
{
$this->products = new ArrayCollection();
$this->langParams = new ArrayCollection();
}
/**
* Obsługa tłumaczeń
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function getName(){
return $this->translate()->getName();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setProductFamily($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getProductFamily() === $this) {
$product->setProductFamily(null);
}
}
return $this;
}
/**
* @return Collection|ProductFamilyLangParam[]
*/
public function getLangParams(): Collection
{
return $this->langParams;
}
public function addLangParam(LangParamRelationInterface $langParam): self
{
if (!$this->langParams->contains($langParam)) {
$this->langParams[] = $langParam;
$langParam->setProductFamily($this);
}
return $this;
}
public function removeLangParam(ProductFamilyLangParam $langParam): self
{
if ($this->langParams->contains($langParam)) {
$this->langParams->removeElement($langParam);
// set the owning side to null (unless already changed)
if ($langParam->getProductFamily() === $this) {
$langParam->setProductFamily(null);
}
}
return $this;
}
}