src/AtechNet/CoreBundle/Entity/ProductContainer.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping\Column;
  5. use Doctrine\ORM\Mapping\Entity;
  6. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Doctrine\ORM\Mapping\ManyToOne;
  9. use Doctrine\ORM\Mapping\OneToMany;
  10. use Doctrine\ORM\Mapping\Table;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * ProductContainer
  14.  *
  15.  * @Entity
  16.  * @Table(name="product_container")
  17.  * @HasLifecycleCallbacks
  18.  */
  19. class ProductContainer extends AbstractEntity
  20. {
  21.     /**
  22.      * @var Product
  23.      *
  24.      * @ManyToOne(targetEntity="Product", inversedBy="productContainers")
  25.      * @JoinColumn(name="product_id", referencedColumnName="id", nullable=true)
  26.      */
  27.     private $product;
  28.     /**
  29.      * @var Product
  30.      *
  31.      * @ManyToOne(targetEntity="Product", inversedBy="childContainers")
  32.      * @JoinColumn(name="child_id", referencedColumnName="id")
  33.      */
  34.     private $child;
  35.     /**
  36.      * @var integer
  37.      *
  38.      * @Assert\NotNull
  39.      *
  40.      * @Column(name="multiplier", type="integer")
  41.      */
  42.     private $multiplier = 0;
  43.     /**
  44.      * @var ArrayCollection
  45.      *
  46.      * @Assert\Valid
  47.      *
  48.      * @OneToMany(targetEntity="ProductContainerMeta", mappedBy="productContainer", cascade={"persist", "remove"})
  49.      **/
  50.     private $metas;
  51.     /**
  52.      * @var bool
  53.      *
  54.      * @Column(name="allow_price_sync_from_child_product", type="boolean")
  55.      */
  56.     private $allowPriceSyncFromChildProduct = false;
  57.     /**
  58.      * @var ProductTag
  59.      *
  60.      * @ManyToOne(targetEntity="ProductTag", inversedBy="productContainers")
  61.      * @JoinColumn(name="product_tag_id", referencedColumnName="id", nullable=true)
  62.      */
  63.     private $productTag;
  64.     public function getDomainMeta(Domain $domain)
  65.     {
  66.         foreach ($this->getMetas() as $meta) {
  67.             if ($meta->getDomain()->getId() == $domain->getId()) {
  68.                 return $meta;
  69.             }
  70.         }
  71.         return null;
  72.     }
  73.     public function __construct()
  74.     {
  75.         parent::__construct();
  76.         
  77.         $this->metas = new ArrayCollection();
  78.     }
  79.     /**
  80.      * @return Product|null
  81.      */
  82.     public function getProduct(): ?Product
  83.     {
  84.         return $this->product;
  85.     }
  86.     /**
  87.      * @param Product|null $product
  88.      */
  89.     public function setProduct(?Product $product)
  90.     {
  91.         $this->product = $product;
  92.     }
  93.     /**
  94.      * @return Product
  95.      */
  96.     public function getChild()
  97.     {
  98.         return $this->child;
  99.     }
  100.     /**
  101.      * @param Product $child
  102.      */
  103.     public function setChild($child)
  104.     {
  105.         $this->child = $child;
  106.     }
  107.     /**
  108.      * @return number
  109.      */
  110.     public function getMultiplier()
  111.     {
  112.         return $this->multiplier;
  113.     }
  114.     /**
  115.      * @param number $multiplier
  116.      */
  117.     public function setMultiplier($multiplier)
  118.     {
  119.         $this->multiplier = $multiplier;
  120.     }
  121.     /**
  122.      * @return \Doctrine\Common\Collections\ArrayCollection
  123.      */
  124.     public function getMetas()
  125.     {
  126.         return $this->metas;
  127.     }
  128.     private $metasSorted;
  129.     public function getMetasSorted()
  130.     {
  131.         if ($this->metasSorted == null) {
  132.             $this->metasSorted = $this->metas->getValues();
  133.             usort($this->metasSorted, function ($a, $b) {
  134.                 return $a->getDomain()->getSortIndex() - $b->getDomain()->getSortIndex();
  135.             });
  136.         }
  137.         return $this->metasSorted;
  138.     }
  139.     /**
  140.      * @param \Doctrine\Common\Collections\ArrayCollection $metas
  141.      */
  142.     public function setMetas($metas)
  143.     {
  144.         $this->metas = $metas;
  145.     }
  146.     /**
  147.      * @return boolean
  148.      */
  149.     public function isPriceSyncAllowedFromChildProduct()
  150.     {
  151.         return $this->allowPriceSyncFromChildProduct;
  152.     }
  153.     /**
  154.      * @param boolean $allowPriceSyncFromChildProduct
  155.      */
  156.     public function setPriceSyncFromChildProduct($allowPriceSyncFromChildProduct)
  157.     {
  158.         $this->allowPriceSyncFromChildProduct = $allowPriceSyncFromChildProduct;
  159.     }
  160.     /**
  161.      * @return ProductTag|null
  162.      */
  163.     public function getProductTag(): ?ProductTag
  164.     {
  165.         return $this->productTag;
  166.     }
  167.     /**
  168.      * @param ProductTag|null $productTag
  169.      * @return void
  170.      */
  171.     public function setProductTag(?ProductTag $productTag): void
  172.     {
  173.         $this->productTag = $productTag;
  174.     }
  175. }