src/CMSBundle/Entity/Banner.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\CMSBundle\Entity;
  3. use App\CMSBundle\Entity\Translation\BannerTranslation;
  4. use App\CMSBundle\Enum\BannerActionButtonPositionEnum;
  5. use App\CMSBundle\Enum\BannerPlacementEnum;
  6. use App\MediaBundle\Entity\Image;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use PN\LocaleBundle\Model\LocaleTrait;
  11. use PN\LocaleBundle\Model\Translatable;
  12. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  13. use PN\ServiceBundle\Model\DateTimeTrait;
  14. /**
  15. * Banner
  16. *
  17. * @ORM\HasLifecycleCallbacks
  18. * @ORM\Table(name="banner")
  19. * @ORM\Entity(repositoryClass="App\CMSBundle\Repository\BannerRepository")
  20. */
  21. class Banner implements Translatable, DateTimeInterface
  22. {
  23. use DateTimeTrait,
  24. LocaleTrait;
  25. /**
  26. * @ORM\Column(name="id", type="integer")
  27. * @ORM\Id
  28. * @ORM\GeneratedValue(strategy="AUTO")
  29. */
  30. private ?int $id = null;
  31. /**
  32. * @ORM\OneToOne(targetEntity="App\MediaBundle\Entity\Image", cascade={"persist", "remove" })
  33. */
  34. private ?Image $image = null;
  35. /**
  36. * @ORM\Column(name="title", type="string", length=50)
  37. */
  38. private ?string $title = null;
  39. /**
  40. * @ORM\Column(name="sub_title", type="string", length=35,nullable=true)
  41. */
  42. private ?string $subTitle = null;
  43. /**
  44. * @ORM\Column(name="placement", enumType=BannerPlacementEnum::class, type="integer", length=255)
  45. */
  46. private ?BannerPlacementEnum $placement = null;
  47. /**
  48. * @ORM\Column(name="placementName", type="string", length=255, nullable=true)
  49. */
  50. private ?string $placementName = null;
  51. /**
  52. * @ORM\Column(name="url", type="string", length=255, nullable=true)
  53. */
  54. private ?string $url = null;
  55. /**
  56. * @ORM\Column(name="text", type="string", length=255, nullable=true)
  57. */
  58. private ?string $text = null;
  59. /**
  60. * @ORM\Column(name="action_button_name", type="string", length=20, nullable=true)
  61. */
  62. private string $actionButtonName = 'View';
  63. /**
  64. * @ORM\Column(name="action_button_position", enumType=BannerActionButtonPositionEnum::class, type="string", length=255, nullable=true)
  65. */
  66. private ?BannerActionButtonPositionEnum $actionButtonPosition = BannerActionButtonPositionEnum::CENTER;
  67. /**
  68. * @ORM\Column(name="tarteb", type="smallint", nullable=true)
  69. */
  70. private ?int $tarteb = null;
  71. /**
  72. * @var bool
  73. *
  74. * @ORM\Column(name="publish", type="boolean")
  75. */
  76. private bool $publish = true;
  77. /**
  78. * @var bool
  79. *
  80. * @ORM\Column(name="openInNewTab", type="boolean")
  81. */
  82. private bool $openInNewTab = false;
  83. /**
  84. * @ORM\OneToMany(targetEntity="App\CMSBundle\Entity\Translation\BannerTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  85. */
  86. private Collection $translations;
  87. /**
  88. * @ORM\PrePersist()
  89. * @ORM\PreUpdate()
  90. */
  91. public function updatePlaceholderName(): void
  92. {
  93. $this->setPlacementName($this->getPlacement()->name());
  94. }
  95. /**
  96. * Constructor
  97. */
  98. public function __construct()
  99. {
  100. $this->translations = new ArrayCollection();
  101. }
  102. public function getTitle()
  103. {
  104. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  105. }
  106. public function getSubTitle(): ?string
  107. {
  108. return !$this->currentTranslation ? $this->subTitle : $this->currentTranslation->getSubTitle();
  109. }
  110. public function getUrl(): ?string
  111. {
  112. return !$this->currentTranslation ? $this->url : $this->currentTranslation->getUrl();
  113. }
  114. public function getText(): ?string
  115. {
  116. return !$this->currentTranslation ? $this->text : $this->currentTranslation->getText();
  117. }
  118. public function getPlacement(): ?BannerPlacementEnum
  119. {
  120. return $this->placement;
  121. }
  122. public function setPlacement(BannerPlacementEnum $placement): self
  123. {
  124. $this->placement = $placement;
  125. return $this;
  126. }
  127. public function getActionButtonPosition(): ?BannerActionButtonPositionEnum
  128. {
  129. return $this->actionButtonPosition;
  130. }
  131. public function setActionButtonPosition(?BannerActionButtonPositionEnum $actionButtonPosition): self
  132. {
  133. $this->actionButtonPosition = $actionButtonPosition;
  134. return $this;
  135. }
  136. public function getId(): ?int
  137. {
  138. return $this->id;
  139. }
  140. public function setTitle(string $title): self
  141. {
  142. $this->title = $title;
  143. return $this;
  144. }
  145. public function setSubTitle(?string $subTitle): self
  146. {
  147. $this->subTitle = $subTitle;
  148. return $this;
  149. }
  150. public function setPlacementName(?string $placementName): self
  151. {
  152. $this->placementName = $placementName;
  153. return $this;
  154. }
  155. public function setUrl(?string $url): self
  156. {
  157. $this->url = $url;
  158. return $this;
  159. }
  160. public function setText(?string $text): self
  161. {
  162. $this->text = $text;
  163. return $this;
  164. }
  165. public function getActionButtonName(): ?string
  166. {
  167. return $this->actionButtonName;
  168. }
  169. public function setActionButtonName(?string $actionButtonName): self
  170. {
  171. $this->actionButtonName = $actionButtonName;
  172. return $this;
  173. }
  174. public function getTarteb(): ?int
  175. {
  176. return $this->tarteb;
  177. }
  178. public function setTarteb(?int $tarteb): self
  179. {
  180. $this->tarteb = $tarteb;
  181. return $this;
  182. }
  183. public function isPublish(): ?bool
  184. {
  185. return $this->publish;
  186. }
  187. public function setPublish(bool $publish): self
  188. {
  189. $this->publish = $publish;
  190. return $this;
  191. }
  192. public function isOpenInNewTab(): ?bool
  193. {
  194. return $this->openInNewTab;
  195. }
  196. public function setOpenInNewTab(bool $openInNewTab): self
  197. {
  198. $this->openInNewTab = $openInNewTab;
  199. return $this;
  200. }
  201. public function getImage(): ?Image
  202. {
  203. return $this->image;
  204. }
  205. public function setImage(?Image $image): self
  206. {
  207. $this->image = $image;
  208. return $this;
  209. }
  210. /**
  211. * @return Collection<int, BannerTranslation>
  212. */
  213. public function getTranslations(): Collection
  214. {
  215. return $this->translations;
  216. }
  217. public function addTranslation(BannerTranslation $translation): self
  218. {
  219. if (!$this->translations->contains($translation)) {
  220. $this->translations->add($translation);
  221. $translation->setTranslatable($this);
  222. }
  223. return $this;
  224. }
  225. public function removeTranslation(BannerTranslation $translation): self
  226. {
  227. if ($this->translations->removeElement($translation)) {
  228. // set the owning side to null (unless already changed)
  229. if ($translation->getTranslatable() === $this) {
  230. $translation->setTranslatable(null);
  231. }
  232. }
  233. return $this;
  234. }
  235. public function getPlacementName(): ?string
  236. {
  237. return $this->placementName;
  238. }
  239. }