<?php
namespace App\Entity\Gos;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="App\Repository\Gos\ProductVariantPackRepository")
*/
class ProductVariantPack
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\ManyToMany(targetEntity="ProductVariant", inversedBy="productVariantPacks")
* @ORM\JoinTable(name="product_variant_in_pack")
*/
private $productVariants;
/**
* @ORM\ManyToMany(targetEntity="Coupon", mappedBy="productVariantPacks")
*/
private $coupons;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Country", inversedBy="productVariantPacks")
*/
private $countries;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\PortalSettings", inversedBy="productVariantPacks")
*/
private $portalSettings;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\ClientType", inversedBy="productVariantPacks")
*/
private $clientTypes;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private $autoUpdate = false;
public function __construct()
{
$this->productVariants = new ArrayCollection();
$this->coupons = new ArrayCollection();
$this->countries = new ArrayCollection();
$this->portalSettings = new ArrayCollection();
$this->clientTypes = new ArrayCollection();
}
/** @ORM\PrePersist() */
public function onPrePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function onPreUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return $this->getName();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|ProductVariant[]
*/
public function getProductVariants(): Collection
{
return $this->productVariants;
}
public function addProductVariant(ProductVariant $productVariant): self
{
if (!$this->productVariants->contains($productVariant)) {
$this->productVariants[] = $productVariant;
$productVariant->addProductVariantPack($this);
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): self
{
if ($this->productVariants->contains($productVariant)) {
$this->productVariants->removeElement($productVariant);
$productVariant->removeProductVariantPack($this);
}
return $this;
}
/**
* @return Collection|Coupon[]
*/
public function getCoupons(): Collection
{
return $this->coupons;
}
public function addCoupon(Coupon $coupon): self
{
if (!$this->coupons->contains($coupon)) {
$this->coupons[] = $coupon;
$coupon->addProductVariantPack($this);
}
return $this;
}
public function removeCoupon(Coupon $coupon): self
{
if ($this->coupons->contains($coupon)) {
$this->coupons->removeElement($coupon);
$coupon->removeProductVariantPack($this);
}
return $this;
}
/**
* @return Collection|Country[]
*/
public function getCountries(): Collection
{
return $this->countries;
}
public function addCountry(Country $country): self
{
if (!$this->countries->contains($country)) {
$this->countries[] = $country;
}
return $this;
}
public function removeCountry(Country $country): self
{
if ($this->countries->contains($country)) {
$this->countries->removeElement($country);
}
return $this;
}
/**
* @return Collection|PortalSettings[]
*/
public function getPortalSettings(): Collection
{
return $this->portalSettings;
}
public function addPortalSetting(PortalSettings $portalSetting): self
{
if (!$this->portalSettings->contains($portalSetting)) {
$this->portalSettings[] = $portalSetting;
}
return $this;
}
public function removePortalSetting(PortalSettings $portalSetting): self
{
if ($this->portalSettings->contains($portalSetting)) {
$this->portalSettings->removeElement($portalSetting);
}
return $this;
}
/**
* @return Collection|ClientType[]
*/
public function getClientTypes(): Collection
{
return $this->clientTypes;
}
public function addClientType(ClientType $clientType): self
{
if (!$this->clientTypes->contains($clientType)) {
$this->clientTypes[] = $clientType;
}
return $this;
}
public function removeClientType(ClientType $clientType): self
{
if ($this->clientTypes->contains($clientType)) {
$this->clientTypes->removeElement($clientType);
}
return $this;
}
/**
* Returns an array of all unique masterProductsIds for the given productVariantPack
*
* @return array
*/
public function getMasterProductsIds(): array
{
$masterProducts = new ArrayCollection();
foreach ($this->getProductVariants() as $productVariant)
{
if (!$masterProducts->contains($productVariant->getMasterProduct()->getId()))
{
$masterProducts->add($productVariant->getMasterProduct()->getId());
}
}
return $masterProducts->toArray();
}
public function getAutoUpdate(): ?bool
{
return $this->autoUpdate;
}
public function setAutoUpdate(bool $autoUpdate): self
{
$this->autoUpdate = $autoUpdate;
return $this;
}
}