src/Entity/Slider.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\ActiveTrait;
  4. use App\Entity\Traits\DeleteTrait;
  5. use App\Entity\Traits\LinkTrait;
  6. use App\Entity\Traits\MetaTrait;
  7. use App\Entity\Traits\TitleAndContentTrait;
  8. use App\Entity\Traits\TranslateTrait;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Gedmo\Timestampable\Traits\TimestampableEntity;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. /**
  16. * Slider.
  17. *
  18. * @Gedmo\Loggable
  19. *
  20. * @Gedmo\TranslationEntity(class="App\Entity\SliderTranslations")
  21. */
  22. #[UniqueEntity(fields: ['identifier'], errorPath: 'identifier', message: 'A slider has already be created with that identifier.')]
  23. #[ORM\Entity(repositoryClass: \App\Repository\SliderRepository::class)]
  24. #[ORM\HasLifecycleCallbacks]
  25. #[ORM\Table(name: 'slider')]
  26. class Slider
  27. {
  28. use TitleAndContentTrait;
  29. use LinkTrait;
  30. use MetaTrait;
  31. use ActiveTrait;
  32. use DeleteTrait;
  33. use TimestampableEntity;
  34. use TranslateTrait;
  35. #[ORM\Column(name: 'id', type: 'integer')]
  36. #[ORM\Id]
  37. #[ORM\GeneratedValue(strategy: 'AUTO')]
  38. private int $id;
  39. #[ORM\Column(name: 'identifier', type: 'string', length: 255)]
  40. private ?string $identifier = null;
  41. #[ORM\OneToMany(targetEntity: 'SliderImages', mappedBy: 'slider')]
  42. #[ORM\OrderBy(['position' => 'ASC'])]
  43. private Collection $images;
  44. #[ORM\ManyToMany(targetEntity: Page::class, inversedBy: 'slider')]
  45. private Collection $pages;
  46. /**
  47. * Constructor.
  48. */
  49. public function __construct()
  50. {
  51. $this->images = new ArrayCollection();
  52. $this->pages = new ArrayCollection();
  53. }
  54. public function getFilePath(): string
  55. {
  56. return 'userfiles/images/slider';
  57. }
  58. /**
  59. * Get id.
  60. *
  61. * @return int
  62. */
  63. public function getId()
  64. {
  65. return $this->id;
  66. }
  67. /**
  68. * Set identifier.
  69. *
  70. * @param string $identifier
  71. *
  72. * @return Slider
  73. */
  74. public function setIdentifier($identifier)
  75. {
  76. $this->identifier = $identifier;
  77. return $this;
  78. }
  79. /**
  80. * Get identifier.
  81. *
  82. * @return string
  83. */
  84. public function getIdentifier()
  85. {
  86. return $this->identifier;
  87. }
  88. /**
  89. * Add images.
  90. *
  91. * @return Slider
  92. */
  93. public function addImage(SliderImages $images)
  94. {
  95. $this->images[] = $images;
  96. return $this;
  97. }
  98. /**
  99. * Remove images.
  100. */
  101. public function removeImage(SliderImages $images)
  102. {
  103. $this->images->removeElement($images);
  104. }
  105. /**
  106. * Get images.
  107. *
  108. * @return ArrayCollection
  109. */
  110. public function getImages()
  111. {
  112. $activeImages = [];
  113. foreach ($this->images as $image) {
  114. if (!$image->isDeleted()) {
  115. $activeImages[] = $image;
  116. }
  117. }
  118. return $this->images;
  119. }
  120. public function getActiveImages()
  121. {
  122. return $this->images;
  123. }
  124. /**
  125. * Add pages.
  126. *
  127. * @return Slider
  128. */
  129. public function addPage(Page $page)
  130. {
  131. $this->pages[] = $page;
  132. return $this;
  133. }
  134. /**
  135. * Remove pages.
  136. */
  137. public function removePage(Page $page)
  138. {
  139. $this->pages->removeElement($page);
  140. }
  141. /**
  142. * Get pages.
  143. *
  144. * @return ArrayCollection
  145. */
  146. public function getPages()
  147. {
  148. return $this->pages;
  149. }
  150. // REQUIRED BY THE META LINKS TRAIT - NOT REALLY NEEDED HERE BUT WHATEVS :)
  151. public function getLinkedPageId(): int
  152. {
  153. return 1;
  154. }
  155. }