src/Entity/ProductFamily.php line 32

Open in your IDE?
  1. <?php
  2. // src/Acme/UserBundle/Entity/User.php
  3. namespace App\Entity;
  4. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  5. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  6. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  7. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  8. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  10. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  11. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  12. use App\Model\LangParamInterface;
  13. use App\Model\LangParamRelationInterface;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. /**
  20.  * @Doctrine\ORM\Mapping\Entity
  21.  * @Doctrine\ORM\Mapping\Table(name="product_family")
  22.  * @Doctrine\ORM\Mapping\Entity()
  23.  */
  24. class ProductFamily implements TranslatableInterfaceLangParamInterface
  25. BlameableInterfaceTimestampableInterfaceSoftDeletableInterface {
  26.     use BlameableTrait;
  27.     use TimestampableTrait;
  28.     use TranslatableTrait;
  29.     use SoftDeletableTrait;
  30.     
  31.     
  32.     
  33.     /**
  34.      * @var integer
  35.      *
  36.      * @ORM\Column(name="id", type="integer", nullable=false)
  37.      * @ORM\Id
  38.      * @ORM\GeneratedValue(strategy="IDENTITY")
  39.      */
  40.     private $id;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="productFamily", cascade={"persist"})
  43.      */
  44.     protected $products;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity="App\Entity\ProductFamilyLangParam", mappedBy="productFamily", cascade={"all"})
  47.      */
  48.     protected $langParams;
  49.     public function __construct()
  50.     {
  51.         $this->products = new ArrayCollection();
  52.         $this->langParams = new ArrayCollection();
  53.     }
  54.     
  55.     /**
  56.      * Obsługa tłumaczeń
  57.      * @param $method
  58.      * @param $arguments
  59.      * @return mixed
  60.      */
  61.     public function __call($method$arguments)
  62.     {
  63.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  64.     }
  65.     public function getName(){
  66.         return $this->translate()->getName();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     /**
  73.      * @return Collection|Product[]
  74.      */
  75.     public function getProducts(): Collection
  76.     {
  77.         return $this->products;
  78.     }
  79.     public function addProduct(Product $product): self
  80.     {
  81.         if (!$this->products->contains($product)) {
  82.             $this->products[] = $product;
  83.             $product->setProductFamily($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeProduct(Product $product): self
  88.     {
  89.         if ($this->products->contains($product)) {
  90.             $this->products->removeElement($product);
  91.             // set the owning side to null (unless already changed)
  92.             if ($product->getProductFamily() === $this) {
  93.                 $product->setProductFamily(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection|ProductFamilyLangParam[]
  100.      */
  101.     public function getLangParams(): Collection
  102.     {
  103.         return $this->langParams;
  104.     }
  105.     public function addLangParam(LangParamRelationInterface $langParam): self
  106.     {
  107.         if (!$this->langParams->contains($langParam)) {
  108.             $this->langParams[] = $langParam;
  109.             $langParam->setProductFamily($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeLangParam(ProductFamilyLangParam $langParam): self
  114.     {
  115.         if ($this->langParams->contains($langParam)) {
  116.             $this->langParams->removeElement($langParam);
  117.             // set the owning side to null (unless already changed)
  118.             if ($langParam->getProductFamily() === $this) {
  119.                 $langParam->setProductFamily(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124. }