<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\Table;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ProductContainer
*
* @Entity
* @Table(name="product_container")
* @HasLifecycleCallbacks
*/
class ProductContainer extends AbstractEntity
{
/**
* @var Product
*
* @ManyToOne(targetEntity="Product", inversedBy="productContainers")
* @JoinColumn(name="product_id", referencedColumnName="id", nullable=true)
*/
private $product;
/**
* @var Product
*
* @ManyToOne(targetEntity="Product", inversedBy="childContainers")
* @JoinColumn(name="child_id", referencedColumnName="id")
*/
private $child;
/**
* @var integer
*
* @Assert\NotNull
*
* @Column(name="multiplier", type="integer")
*/
private $multiplier = 0;
/**
* @var ArrayCollection
*
* @Assert\Valid
*
* @OneToMany(targetEntity="ProductContainerMeta", mappedBy="productContainer", cascade={"persist", "remove"})
**/
private $metas;
/**
* @var bool
*
* @Column(name="allow_price_sync_from_child_product", type="boolean")
*/
private $allowPriceSyncFromChildProduct = false;
/**
* @var ProductTag
*
* @ManyToOne(targetEntity="ProductTag", inversedBy="productContainers")
* @JoinColumn(name="product_tag_id", referencedColumnName="id", nullable=true)
*/
private $productTag;
public function getDomainMeta(Domain $domain)
{
foreach ($this->getMetas() as $meta) {
if ($meta->getDomain()->getId() == $domain->getId()) {
return $meta;
}
}
return null;
}
public function __construct()
{
parent::__construct();
$this->metas = new ArrayCollection();
}
/**
* @return Product|null
*/
public function getProduct(): ?Product
{
return $this->product;
}
/**
* @param Product|null $product
*/
public function setProduct(?Product $product)
{
$this->product = $product;
}
/**
* @return Product
*/
public function getChild()
{
return $this->child;
}
/**
* @param Product $child
*/
public function setChild($child)
{
$this->child = $child;
}
/**
* @return number
*/
public function getMultiplier()
{
return $this->multiplier;
}
/**
* @param number $multiplier
*/
public function setMultiplier($multiplier)
{
$this->multiplier = $multiplier;
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getMetas()
{
return $this->metas;
}
private $metasSorted;
public function getMetasSorted()
{
if ($this->metasSorted == null) {
$this->metasSorted = $this->metas->getValues();
usort($this->metasSorted, function ($a, $b) {
return $a->getDomain()->getSortIndex() - $b->getDomain()->getSortIndex();
});
}
return $this->metasSorted;
}
/**
* @param \Doctrine\Common\Collections\ArrayCollection $metas
*/
public function setMetas($metas)
{
$this->metas = $metas;
}
/**
* @return boolean
*/
public function isPriceSyncAllowedFromChildProduct()
{
return $this->allowPriceSyncFromChildProduct;
}
/**
* @param boolean $allowPriceSyncFromChildProduct
*/
public function setPriceSyncFromChildProduct($allowPriceSyncFromChildProduct)
{
$this->allowPriceSyncFromChildProduct = $allowPriceSyncFromChildProduct;
}
/**
* @return ProductTag|null
*/
public function getProductTag(): ?ProductTag
{
return $this->productTag;
}
/**
* @param ProductTag|null $productTag
* @return void
*/
public function setProductTag(?ProductTag $productTag): void
{
$this->productTag = $productTag;
}
}