src/Entity/Slider.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SliderRepository;
  4. use App\Traits\DateTrait;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as Serializer;
  10. use JMS\Serializer\Annotation\Expose;
  11. use JMS\Serializer\Annotation\Groups;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * @ORM\Entity(repositoryClass=SliderRepository::class)
  16. *
  17. * @UniqueEntity(
  18. * fields={"slug"},
  19. * errorPath="slug",
  20. * message="Le slug doit ĂȘtre unique sur le domaine actuel"
  21. * )
  22. *
  23. * @Serializer\ExclusionPolicy("ALL")
  24. */
  25. class Slider
  26. {
  27. public const SLIDER_TYPE_IMAGE = 'slider_image';
  28. public const SLIDER_TYPE_PRODUCT = 'slider_product';
  29. public const SLIDER_TYPE_INVESTIGATION = 'slider_investigation';
  30. /**
  31. * @ORM\Id
  32. * @ORM\GeneratedValue
  33. * @ORM\Column(type="integer")
  34. *
  35. * @Expose
  36. * @Groups({"slider:id", "slider"})
  37. */
  38. private $id;
  39. /**
  40. * @ORM\Column(type="string", length=255)
  41. *
  42. * @Expose
  43. * @Groups({"slider:title", "slider"})
  44. */
  45. private $title;
  46. /**
  47. * @ORM\OneToMany(targetEntity=SliderItem::class, mappedBy="slider", cascade={"persist","remove"})
  48. * @ORM\OrderBy({"orderItem" = "ASC"})
  49. */
  50. private $items;
  51. /**
  52. * @ORM\Column(type="datetime", nullable=true)
  53. *
  54. * @Expose
  55. * @Groups({"slider:dateStart", "slider"})
  56. */
  57. private $dateStart;
  58. /**
  59. * @ORM\Column(type="datetime", nullable=true)
  60. *
  61. * @Expose
  62. * @Groups({"slider:dateEnd", "slider"})
  63. */
  64. private $dateEnd;
  65. /**
  66. * @ORM\Column(type="string", length=64)
  67. * @Assert\NotBlank()
  68. * @Expose
  69. * @Groups({"slider:slug", "slider"})
  70. */
  71. private $slug;
  72. /**
  73. * @ORM\Column(type="string", length=255, nullable=true)
  74. *
  75. * @Expose
  76. * @Groups({"slider:type", "slider"})
  77. */
  78. private $type;
  79. /**
  80. * @ORM\ManyToOne(targetEntity=Catalogue::class, inversedBy="sliders")
  81. * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  82. */
  83. private $catalog;
  84. use DateTrait;
  85. public function __construct()
  86. {
  87. $this->items = new ArrayCollection();
  88. }
  89. public function __toString()
  90. {
  91. return $this->title;
  92. }
  93. /*
  94. * ============================================================================================
  95. * =============================== FONCTIONS CUSTOM ===========================================
  96. * ============================================================================================
  97. */
  98. public function getItemsNumber()
  99. {
  100. return count($this->getItems());
  101. }
  102. /*
  103. * ============================================================================================
  104. * ============================== FIN FONCTIONS CUSTOM ========================================
  105. * ============================================================================================
  106. */
  107. /**
  108. * @return Collection|SliderItem[]
  109. */
  110. public function getItems(): Collection
  111. {
  112. return $this->items;
  113. }
  114. public function getId(): ?int
  115. {
  116. return $this->id;
  117. }
  118. public function getTitle(): ?string
  119. {
  120. return $this->title;
  121. }
  122. public function setTitle(string $title): self
  123. {
  124. $this->title = $title;
  125. return $this;
  126. }
  127. public function addSliderItem(SliderItem $sliderItem): self
  128. {
  129. if (!$this->items->contains($sliderItem)) {
  130. $this->items[] = $sliderItem;
  131. $sliderItem->setSlider($this);
  132. }
  133. return $this;
  134. }
  135. public function removeSliderItem(SliderItem $sliderItem): self
  136. {
  137. if ($this->items->removeElement($sliderItem)) {
  138. // set the owning side to null (unless already changed)
  139. if ($sliderItem->getSlider() === $this) {
  140. $sliderItem->setSlider(null);
  141. }
  142. }
  143. return $this;
  144. }
  145. public function addItem(SliderItem $item): self
  146. {
  147. if (!$this->items->contains($item)) {
  148. $this->items[] = $item;
  149. $item->setSlider($this);
  150. }
  151. return $this;
  152. }
  153. public function removeItem(SliderItem $item): self
  154. {
  155. if ($this->items->removeElement($item)) {
  156. // set the owning side to null (unless already changed)
  157. if ($item->getSlider() === $this) {
  158. $item->setSlider(null);
  159. }
  160. }
  161. return $this;
  162. }
  163. public function getDateStart(): ?DateTimeInterface
  164. {
  165. return $this->dateStart;
  166. }
  167. public function setDateStart(?DateTimeInterface $dateStart): self
  168. {
  169. $this->dateStart = $dateStart;
  170. return $this;
  171. }
  172. public function getDateEnd(): ?DateTimeInterface
  173. {
  174. return $this->dateEnd;
  175. }
  176. public function setDateEnd(?DateTimeInterface $dateEnd): self
  177. {
  178. $this->dateEnd = $dateEnd;
  179. return $this;
  180. }
  181. public function getSlug(): ?string
  182. {
  183. return $this->slug;
  184. }
  185. public function setSlug(string $slug): self
  186. {
  187. $this->slug = $slug;
  188. return $this;
  189. }
  190. public function getType(): ?string
  191. {
  192. return $this->type;
  193. }
  194. public function setType(?string $type): self
  195. {
  196. $this->type = $type;
  197. return $this;
  198. }
  199. public function getCatalog(): ?Catalogue
  200. {
  201. return $this->catalog;
  202. }
  203. public function setCatalog(?Catalogue $catalog): self
  204. {
  205. $this->catalog = $catalog;
  206. return $this;
  207. }
  208. }