src/ProductBundle/Entity/Collection.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\ProductBundle\Entity;
  3. use App\ContentBundle\Entity\Post;
  4. use App\ProductBundle\Entity\Translation\CollectionTranslation;
  5. use App\SeoBundle\Entity\Seo;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use PN\LocaleBundle\Model\LocaleTrait;
  9. use PN\LocaleBundle\Model\Translatable;
  10. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  11. use PN\ServiceBundle\Model\DateTimeTrait;
  12. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * @ORM\HasLifecycleCallbacks
  16. * @ORM\Table("collection")
  17. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\CollectionRepository")
  18. */
  19. class Collection implements Translatable, DateTimeInterface
  20. {
  21. use VirtualDeleteTrait,
  22. DateTimeTrait,
  23. LocaleTrait;
  24. /**
  25. * @ORM\Column(name="id", type="integer")
  26. * @ORM\Id
  27. * @ORM\GeneratedValue(strategy="AUTO")
  28. */
  29. private ?int $id = null;
  30. /**
  31. * @ORM\OneToOne(targetEntity="\App\SeoBundle\Entity\Seo", cascade={"persist", "remove"})
  32. */
  33. private ?Seo $seo = null;
  34. /**
  35. * @ORM\OneToOne(targetEntity="\App\ContentBundle\Entity\Post", cascade={"persist", "remove"})
  36. */
  37. private ?Post $post = null;
  38. /**
  39. * @Assert\NotBlank()
  40. * @ORM\Column(name="title", type="string", length=45)
  41. */
  42. private ?string $title = null;
  43. /**
  44. * @ORM\Column(name="publish", type="boolean")
  45. */
  46. private bool $publish = true;
  47. /**
  48. * @ORM\Column(name="featured", type="boolean")
  49. */
  50. private bool $featured = true;
  51. /**
  52. * @ORM\Column(name="tarteb", type="smallint", nullable=true, options={"default":0}))
  53. */
  54. private ?int $tarteb = 0;
  55. /**
  56. * @ORM\Column(name="no_of_products", type="smallint", nullable=true, options={"default" : 0})
  57. */
  58. private int $noOfProducts = 0;
  59. /**
  60. * @ORM\Column(name="no_of_publish_products", type="smallint", nullable=true, options={"default" : 0})
  61. */
  62. private int $noOfPublishProducts = 0;
  63. /**
  64. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\Translation\CollectionTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  65. */
  66. private \Doctrine\Common\Collections\Collection $translations;
  67. /**
  68. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\ProductHasCollection", mappedBy="collection", cascade={"persist"})
  69. */
  70. private \Doctrine\Common\Collections\Collection $productHasCollections;
  71. public function __clone()
  72. {
  73. if ($this->id) {
  74. $this->id = null;
  75. $this->seo = clone $this->seo;
  76. $this->post = clone $this->post;
  77. $translationsClone = new ArrayCollection();
  78. foreach ($this->getTranslations() as $translation) {
  79. $itemClone = clone $translation;
  80. $itemClone->setTranslatable($this);
  81. $translationsClone->add($itemClone);
  82. }
  83. $this->translations = $translationsClone;
  84. }
  85. }
  86. public function __construct()
  87. {
  88. $this->translations = new ArrayCollection();
  89. $this->productHasCollections = new ArrayCollection();
  90. }
  91. public function __toString()
  92. {
  93. return $this->getTitle();
  94. }
  95. public function getTitle(): ?string
  96. {
  97. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  98. }
  99. public function getId(): ?int
  100. {
  101. return $this->id;
  102. }
  103. public function setTitle(string $title): self
  104. {
  105. $this->title = $title;
  106. return $this;
  107. }
  108. public function isPublish(): ?bool
  109. {
  110. return $this->publish;
  111. }
  112. public function setPublish(bool $publish): self
  113. {
  114. $this->publish = $publish;
  115. return $this;
  116. }
  117. public function isFeatured(): ?bool
  118. {
  119. return $this->featured;
  120. }
  121. public function setFeatured(bool $featured): self
  122. {
  123. $this->featured = $featured;
  124. return $this;
  125. }
  126. public function getTarteb(): ?int
  127. {
  128. return $this->tarteb;
  129. }
  130. public function setTarteb(?int $tarteb): self
  131. {
  132. $this->tarteb = $tarteb;
  133. return $this;
  134. }
  135. public function getNoOfProducts(): ?int
  136. {
  137. return $this->noOfProducts;
  138. }
  139. public function setNoOfProducts(?int $noOfProducts): self
  140. {
  141. $this->noOfProducts = $noOfProducts;
  142. return $this;
  143. }
  144. public function getNoOfPublishProducts(): ?int
  145. {
  146. return $this->noOfPublishProducts;
  147. }
  148. public function setNoOfPublishProducts(?int $noOfPublishProducts): self
  149. {
  150. $this->noOfPublishProducts = $noOfPublishProducts;
  151. return $this;
  152. }
  153. public function getSeo(): ?Seo
  154. {
  155. return $this->seo;
  156. }
  157. public function setSeo(?Seo $seo): self
  158. {
  159. $this->seo = $seo;
  160. return $this;
  161. }
  162. public function getPost(): ?Post
  163. {
  164. return $this->post;
  165. }
  166. public function setPost(?Post $post): self
  167. {
  168. $this->post = $post;
  169. return $this;
  170. }
  171. /**
  172. * @return Collection<int, CollectionTranslation>
  173. */
  174. public function getTranslations(): \Doctrine\Common\Collections\Collection
  175. {
  176. return $this->translations;
  177. }
  178. public function addTranslation(CollectionTranslation $translation): self
  179. {
  180. if (!$this->translations->contains($translation)) {
  181. $this->translations->add($translation);
  182. $translation->setTranslatable($this);
  183. }
  184. return $this;
  185. }
  186. public function removeTranslation(CollectionTranslation $translation): self
  187. {
  188. if ($this->translations->removeElement($translation)) {
  189. // set the owning side to null (unless already changed)
  190. if ($translation->getTranslatable() === $this) {
  191. $translation->setTranslatable(null);
  192. }
  193. }
  194. return $this;
  195. }
  196. /**
  197. * @return Collection<int, ProductHasCollection>
  198. */
  199. public function getProductHasCollections(): \Doctrine\Common\Collections\Collection
  200. {
  201. return $this->productHasCollections;
  202. }
  203. public function addProductHasCollection(ProductHasCollection $productHasCollection): self
  204. {
  205. if (!$this->productHasCollections->contains($productHasCollection)) {
  206. $this->productHasCollections->add($productHasCollection);
  207. $productHasCollection->setCollection($this);
  208. }
  209. return $this;
  210. }
  211. public function removeProductHasCollection(ProductHasCollection $productHasCollection): self
  212. {
  213. if ($this->productHasCollections->removeElement($productHasCollection)) {
  214. // set the owning side to null (unless already changed)
  215. if ($productHasCollection->getCollection() === $this) {
  216. $productHasCollection->setCollection(null);
  217. }
  218. }
  219. return $this;
  220. }
  221. }