<?php
namespace App\ProductBundle\Entity;
use App\ContentBundle\Entity\Post;
use App\ProductBundle\Entity\Translation\CollectionTranslation;
use App\SeoBundle\Entity\Seo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use PN\LocaleBundle\Model\LocaleTrait;
use PN\LocaleBundle\Model\Translatable;
use PN\ServiceBundle\Interfaces\DateTimeInterface;
use PN\ServiceBundle\Model\DateTimeTrait;
use PN\ServiceBundle\Model\VirtualDeleteTrait;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\HasLifecycleCallbacks
* @ORM\Table("collection")
* @ORM\Entity(repositoryClass="App\ProductBundle\Repository\CollectionRepository")
*/
class Collection implements Translatable, DateTimeInterface
{
use VirtualDeleteTrait,
DateTimeTrait,
LocaleTrait;
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @ORM\OneToOne(targetEntity="\App\SeoBundle\Entity\Seo", cascade={"persist", "remove"})
*/
private ?Seo $seo = null;
/**
* @ORM\OneToOne(targetEntity="\App\ContentBundle\Entity\Post", cascade={"persist", "remove"})
*/
private ?Post $post = null;
/**
* @Assert\NotBlank()
* @ORM\Column(name="title", type="string", length=45)
*/
private ?string $title = null;
/**
* @ORM\Column(name="publish", type="boolean")
*/
private bool $publish = true;
/**
* @ORM\Column(name="featured", type="boolean")
*/
private bool $featured = true;
/**
* @ORM\Column(name="tarteb", type="smallint", nullable=true, options={"default":0}))
*/
private ?int $tarteb = 0;
/**
* @ORM\Column(name="no_of_products", type="smallint", nullable=true, options={"default" : 0})
*/
private int $noOfProducts = 0;
/**
* @ORM\Column(name="no_of_publish_products", type="smallint", nullable=true, options={"default" : 0})
*/
private int $noOfPublishProducts = 0;
/**
* @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\Translation\CollectionTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
*/
private \Doctrine\Common\Collections\Collection $translations;
/**
* @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\ProductHasCollection", mappedBy="collection", cascade={"persist"})
*/
private \Doctrine\Common\Collections\Collection $productHasCollections;
public function __clone()
{
if ($this->id) {
$this->id = null;
$this->seo = clone $this->seo;
$this->post = clone $this->post;
$translationsClone = new ArrayCollection();
foreach ($this->getTranslations() as $translation) {
$itemClone = clone $translation;
$itemClone->setTranslatable($this);
$translationsClone->add($itemClone);
}
$this->translations = $translationsClone;
}
}
public function __construct()
{
$this->translations = new ArrayCollection();
$this->productHasCollections = new ArrayCollection();
}
public function __toString()
{
return $this->getTitle();
}
public function getTitle(): ?string
{
return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
}
public function getId(): ?int
{
return $this->id;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function isPublish(): ?bool
{
return $this->publish;
}
public function setPublish(bool $publish): self
{
$this->publish = $publish;
return $this;
}
public function isFeatured(): ?bool
{
return $this->featured;
}
public function setFeatured(bool $featured): self
{
$this->featured = $featured;
return $this;
}
public function getTarteb(): ?int
{
return $this->tarteb;
}
public function setTarteb(?int $tarteb): self
{
$this->tarteb = $tarteb;
return $this;
}
public function getNoOfProducts(): ?int
{
return $this->noOfProducts;
}
public function setNoOfProducts(?int $noOfProducts): self
{
$this->noOfProducts = $noOfProducts;
return $this;
}
public function getNoOfPublishProducts(): ?int
{
return $this->noOfPublishProducts;
}
public function setNoOfPublishProducts(?int $noOfPublishProducts): self
{
$this->noOfPublishProducts = $noOfPublishProducts;
return $this;
}
public function getSeo(): ?Seo
{
return $this->seo;
}
public function setSeo(?Seo $seo): self
{
$this->seo = $seo;
return $this;
}
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): self
{
$this->post = $post;
return $this;
}
/**
* @return Collection<int, CollectionTranslation>
*/
public function getTranslations(): \Doctrine\Common\Collections\Collection
{
return $this->translations;
}
public function addTranslation(CollectionTranslation $translation): self
{
if (!$this->translations->contains($translation)) {
$this->translations->add($translation);
$translation->setTranslatable($this);
}
return $this;
}
public function removeTranslation(CollectionTranslation $translation): self
{
if ($this->translations->removeElement($translation)) {
// set the owning side to null (unless already changed)
if ($translation->getTranslatable() === $this) {
$translation->setTranslatable(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductHasCollection>
*/
public function getProductHasCollections(): \Doctrine\Common\Collections\Collection
{
return $this->productHasCollections;
}
public function addProductHasCollection(ProductHasCollection $productHasCollection): self
{
if (!$this->productHasCollections->contains($productHasCollection)) {
$this->productHasCollections->add($productHasCollection);
$productHasCollection->setCollection($this);
}
return $this;
}
public function removeProductHasCollection(ProductHasCollection $productHasCollection): self
{
if ($this->productHasCollections->removeElement($productHasCollection)) {
// set the owning side to null (unless already changed)
if ($productHasCollection->getCollection() === $this) {
$productHasCollection->setCollection(null);
}
}
return $this;
}
}