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", "subdomain"},
  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)
  74. *
  75. * @Expose
  76. * @Groups({"slider:subDomain", "slider"})
  77. */
  78. private $subdomain;
  79. /**
  80. * @ORM\Column(type="string", length=255, nullable=true)
  81. *
  82. * @Expose
  83. * @Groups({"slider:type", "slider"})
  84. */
  85. private $type;
  86. /**
  87. * @ORM\ManyToOne(targetEntity=Catalogue::class, inversedBy="sliders")
  88. * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  89. */
  90. private $catalog;
  91. use DateTrait;
  92. public function __construct()
  93. {
  94. $this->items = new ArrayCollection();
  95. }
  96. public function __toString()
  97. {
  98. return $this->title;
  99. }
  100. /*
  101. * ============================================================================================
  102. * =============================== FONCTIONS CUSTOM ===========================================
  103. * ============================================================================================
  104. */
  105. public function getItemsNumber()
  106. {
  107. return count( $this->getItems() );
  108. }
  109. /*
  110. * ============================================================================================
  111. * ============================== FIN FONCTIONS CUSTOM ========================================
  112. * ============================================================================================
  113. */
  114. /**
  115. * @return Collection|SliderItem[]
  116. */
  117. public function getItems(): Collection
  118. {
  119. return $this->items;
  120. }
  121. public function getId(): ?int
  122. {
  123. return $this->id;
  124. }
  125. public function getTitle(): ?string
  126. {
  127. return $this->title;
  128. }
  129. public function setTitle( string $title ): self
  130. {
  131. $this->title = $title;
  132. return $this;
  133. }
  134. public function addSliderItem( SliderItem $sliderItem ): self
  135. {
  136. if ( !$this->items->contains( $sliderItem ) ) {
  137. $this->items[] = $sliderItem;
  138. $sliderItem->setSlider( $this );
  139. }
  140. return $this;
  141. }
  142. public function removeSliderItem( SliderItem $sliderItem ): self
  143. {
  144. if ( $this->items->removeElement( $sliderItem ) ) {
  145. // set the owning side to null (unless already changed)
  146. if ( $sliderItem->getSlider() === $this ) {
  147. $sliderItem->setSlider( NULL );
  148. }
  149. }
  150. return $this;
  151. }
  152. public function addItem( SliderItem $item ): self
  153. {
  154. if ( !$this->items->contains( $item ) ) {
  155. $this->items[] = $item;
  156. $item->setSlider( $this );
  157. }
  158. return $this;
  159. }
  160. public function removeItem( SliderItem $item ): self
  161. {
  162. if ( $this->items->removeElement( $item ) ) {
  163. // set the owning side to null (unless already changed)
  164. if ( $item->getSlider() === $this ) {
  165. $item->setSlider( NULL );
  166. }
  167. }
  168. return $this;
  169. }
  170. public function getDateStart(): ?DateTimeInterface
  171. {
  172. return $this->dateStart;
  173. }
  174. public function setDateStart( ?DateTimeInterface $dateStart ): self
  175. {
  176. $this->dateStart = $dateStart;
  177. return $this;
  178. }
  179. public function getDateEnd(): ?DateTimeInterface
  180. {
  181. return $this->dateEnd;
  182. }
  183. public function setDateEnd( ?DateTimeInterface $dateEnd ): self
  184. {
  185. $this->dateEnd = $dateEnd;
  186. return $this;
  187. }
  188. public function getSlug(): ?string
  189. {
  190. return $this->slug;
  191. }
  192. public function setSlug( string $slug ): self
  193. {
  194. $this->slug = $slug;
  195. return $this;
  196. }
  197. public function getSubdomain(): ?string
  198. {
  199. return $this->subdomain;
  200. }
  201. public function setSubdomain(string $subdomain): self
  202. {
  203. $this->subdomain = $subdomain;
  204. return $this;
  205. }
  206. public function getType(): ?string
  207. {
  208. return $this->type;
  209. }
  210. public function setType(?string $type): self
  211. {
  212. $this->type = $type;
  213. return $this;
  214. }
  215. public function getCatalog(): ?Catalogue
  216. {
  217. return $this->catalog;
  218. }
  219. public function setCatalog(?Catalogue $catalog): self
  220. {
  221. $this->catalog = $catalog;
  222. return $this;
  223. }
  224. }