src/ProductBundle/Entity/Occasion.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\OccasionTranslation;
  5. use App\SeoBundle\Entity\Seo;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use PN\LocaleBundle\Model\LocaleTrait;
  10. use PN\LocaleBundle\Model\Translatable;
  11. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  12. use PN\ServiceBundle\Model\DateTimeTrait;
  13. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  14. /**
  15. * @ORM\HasLifecycleCallbacks
  16. * @ORM\Table("occasion")
  17. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\OccasionRepository")
  18. */
  19. class Occasion 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. * @ORM\Column(name="title", type="string", length=45)
  40. */
  41. private ?string $title = null;
  42. /**
  43. * @ORM\Column(name="active", type="boolean")
  44. */
  45. private bool $active = false;
  46. /**
  47. * @ORM\Column(name="publish", type="boolean")
  48. */
  49. private bool $publish = true;
  50. /**
  51. * @ORM\Column(name="no_of_products", type="smallint", nullable=true, options={"default" : 0})
  52. */
  53. private int $noOfProducts = 0;
  54. /**
  55. * @ORM\Column(name="no_of_publish_products", type="smallint", nullable=true, options={"default" : 0})
  56. */
  57. private int $noOfPublishProducts = 0;
  58. /**
  59. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\Translation\OccasionTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  60. */
  61. private Collection $translations;
  62. /**
  63. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\ProductHasOccasion", mappedBy="occasion", cascade={"persist"})
  64. */
  65. private Collection $productHasOccasions;
  66. public function __clone()
  67. {
  68. if ($this->id) {
  69. $this->id = null;
  70. $this->active = false;
  71. $this->seo = clone $this->seo;
  72. $this->post = clone $this->post;
  73. $translationsClone = new ArrayCollection();
  74. foreach ($this->getTranslations() as $translation) {
  75. $itemClone = clone $translation;
  76. $itemClone->setTranslatable($this);
  77. $translationsClone->add($itemClone);
  78. }
  79. $this->translations = $translationsClone;
  80. }
  81. }
  82. public function __construct()
  83. {
  84. $this->translations = new ArrayCollection();
  85. $this->productHasOccasions = new ArrayCollection();
  86. }
  87. public function getTitle(): ?string
  88. {
  89. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  90. }
  91. public function getId(): ?int
  92. {
  93. return $this->id;
  94. }
  95. public function setTitle(string $title): self
  96. {
  97. $this->title = $title;
  98. return $this;
  99. }
  100. public function isActive(): ?bool
  101. {
  102. return $this->active;
  103. }
  104. public function setActive(bool $active): self
  105. {
  106. $this->active = $active;
  107. return $this;
  108. }
  109. public function isPublish(): ?bool
  110. {
  111. return $this->publish;
  112. }
  113. public function setPublish(bool $publish): self
  114. {
  115. $this->publish = $publish;
  116. return $this;
  117. }
  118. public function getNoOfProducts(): ?int
  119. {
  120. return $this->noOfProducts;
  121. }
  122. public function setNoOfProducts(?int $noOfProducts): self
  123. {
  124. $this->noOfProducts = $noOfProducts;
  125. return $this;
  126. }
  127. public function getNoOfPublishProducts(): ?int
  128. {
  129. return $this->noOfPublishProducts;
  130. }
  131. public function setNoOfPublishProducts(?int $noOfPublishProducts): self
  132. {
  133. $this->noOfPublishProducts = $noOfPublishProducts;
  134. return $this;
  135. }
  136. public function getSeo(): ?Seo
  137. {
  138. return $this->seo;
  139. }
  140. public function setSeo(?Seo $seo): self
  141. {
  142. $this->seo = $seo;
  143. return $this;
  144. }
  145. public function getPost(): ?Post
  146. {
  147. return $this->post;
  148. }
  149. public function setPost(?Post $post): self
  150. {
  151. $this->post = $post;
  152. return $this;
  153. }
  154. /**
  155. * @return Collection<int, OccasionTranslation>
  156. */
  157. public function getTranslations(): Collection
  158. {
  159. return $this->translations;
  160. }
  161. public function addTranslation(OccasionTranslation $translation): self
  162. {
  163. if (!$this->translations->contains($translation)) {
  164. $this->translations->add($translation);
  165. $translation->setTranslatable($this);
  166. }
  167. return $this;
  168. }
  169. public function removeTranslation(OccasionTranslation $translation): self
  170. {
  171. if ($this->translations->removeElement($translation)) {
  172. // set the owning side to null (unless already changed)
  173. if ($translation->getTranslatable() === $this) {
  174. $translation->setTranslatable(null);
  175. }
  176. }
  177. return $this;
  178. }
  179. /**
  180. * @return Collection<int, ProductHasOccasion>
  181. */
  182. public function getProductHasOccasions(): Collection
  183. {
  184. return $this->productHasOccasions;
  185. }
  186. public function addProductHasOccasion(ProductHasOccasion $productHasOccasion): self
  187. {
  188. if (!$this->productHasOccasions->contains($productHasOccasion)) {
  189. $this->productHasOccasions->add($productHasOccasion);
  190. $productHasOccasion->setOccasion($this);
  191. }
  192. return $this;
  193. }
  194. public function removeProductHasOccasion(ProductHasOccasion $productHasOccasion): self
  195. {
  196. if ($this->productHasOccasions->removeElement($productHasOccasion)) {
  197. // set the owning side to null (unless already changed)
  198. if ($productHasOccasion->getOccasion() === $this) {
  199. $productHasOccasion->setOccasion(null);
  200. }
  201. }
  202. return $this;
  203. }
  204. }