src/Entity/Page.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\LinkTrait;
  4. use App\Entity\Traits\MetaTrait;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\Traits\ActiveTrait;
  7. use App\Entity\Traits\DeleteTrait;
  8. use App\Entity\Traits\SubTitleTrait;
  9. use App\Entity\Traits\TranslateTrait;
  10. use App\Entity\Traits\FileUploadTrait;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use App\Entity\Traits\ImageUploadTrait;
  13. use App\Entity\Traits\SitemapableTrait;
  14. use App\Entity\Traits\TitleAndContentTrait;
  15. use Doctrine\Common\Collections\Collection;
  16. use App\Entity\Traits\ThirdImageUploadTrait;
  17. use App\Entity\Traits\SecondImageUploadTrait;
  18. use App\Entity\Interfaces\DefaultLinkedEntity;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Gedmo\Timestampable\Traits\TimestampableEntity;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  23. /**
  24. * @Gedmo\Loggable
  25. *
  26. * @Gedmo\TranslationEntity(class="App\Entity\PageTranslations")
  27. */
  28. #[UniqueEntity(fields: ['slug'], errorPath: 'slug', message: 'A page has already be created with that title.')]
  29. #[ORM\Entity(repositoryClass: \App\Repository\PageRepository::class)]
  30. #[ORM\HasLifecycleCallbacks]
  31. #[ORM\Table(name: 'page')]
  32. class Page implements DefaultLinkedEntity
  33. {
  34. use TitleAndContentTrait;
  35. use SubTitleTrait;
  36. use LinkTrait;
  37. use MetaTrait;
  38. use ActiveTrait;
  39. use DeleteTrait;
  40. use ImageUploadTrait;
  41. use SecondImageUploadTrait;
  42. use ThirdImageUploadTrait;
  43. use FileUploadTrait;
  44. use TimestampableEntity;
  45. use TranslateTrait;
  46. use SitemapableTrait;
  47. /**
  48. * @var \DateTime
  49. */
  50. public $deletedAt;
  51. public ?string $createdBy = null;
  52. #[ORM\Column(name: 'components', type: 'array', nullable: true)]
  53. protected array $components = [];
  54. #[ORM\Column(name: 'extraUrlsegments', type: 'array', nullable: true)]
  55. protected array $extraUrlsegments = [];
  56. #[ORM\Column(name: 'htmlblocks', type: 'array', nullable: true)]
  57. protected array $htmlblocks = [];
  58. /*
  59. SPECIFICALLY OVERRIDING SLUG PROPERTY AS NEEDS
  60. TO NOT BE CREATED AUTOMATICALLY
  61. */
  62. /**
  63. * @Gedmo\Translatable
  64. *
  65. * @Gedmo\Versioned
  66. */
  67. #[ORM\Column(length: 255, unique: true)]
  68. private ?string $slug = null;
  69. #[ORM\Id]
  70. #[ORM\GeneratedValue]
  71. #[ORM\Column(type: 'integer')]
  72. private int $id;
  73. /**
  74. * @Gedmo\Translatable
  75. *
  76. * @Gedmo\Versioned
  77. */
  78. #[Assert\NotBlank(message: 'The menu title should not be blank')]
  79. #[ORM\Column(name: 'navtitle', type: 'string', length: 128)]
  80. private ?string $navtitle = null;
  81. /**
  82. * @Gedmo\Translatable
  83. *
  84. * @Gedmo\Versioned
  85. */
  86. #[ORM\Column(name: 'url', type: 'string', length: 128, nullable: true)]
  87. private ?string $url = null;
  88. #[ORM\Column(name: 'viewable_from', type: 'datetime')]
  89. private ?\DateTimeInterface $viewable_from = null;
  90. #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'pagesupdated')]
  91. #[ORM\JoinColumn(name: 'update_by', referencedColumnName: 'id')]
  92. private $updatedBy;
  93. #[ORM\ManyToOne(targetEntity: 'Page')]
  94. #[ORM\JoinColumn(name: 'parent', unique: false, referencedColumnName: 'id', nullable: true)]
  95. private ?Page $parent = null;
  96. #[Assert\NotBlank(message: 'You must select a template')]
  97. #[ORM\ManyToOne(targetEntity: Templates::class, inversedBy: 'pagetemplate')]
  98. private ?Templates $template = null;
  99. #[ORM\OneToMany(targetEntity: MenuItems::class, mappedBy: 'pageId')]
  100. private ?Collection $menupage;
  101. #[ORM\ManyToMany(targetEntity: Slider::class, mappedBy: 'pages')]
  102. private ?Collection $slider = null;
  103. #[ORM\OneToMany(targetEntity: PagePreview::class, mappedBy: 'page')]
  104. private ?Collection $pagePreviews = null;
  105. #[ORM\Column(type: 'text', nullable: true)]
  106. private ?string $content2 = null;
  107. #[ORM\Column(type: 'text', nullable: true)]
  108. private ?string $kicker = null;
  109. #[ORM\ManyToMany(targetEntity: ImageTextGrid::class, inversedBy: 'pages')]
  110. private $imageTextGrids;
  111. #[ORM\ManyToOne(targetEntity: Gallery::class)]
  112. private $gallery;
  113. /**
  114. * Constructor.
  115. */
  116. public function __construct()
  117. {
  118. $this->menupage = new ArrayCollection();
  119. $this->imageTextGrids = new ArrayCollection();
  120. }
  121. /**
  122. * Get id.
  123. *
  124. * @return int
  125. */
  126. public function getId()
  127. {
  128. return $this->id;
  129. }
  130. /**
  131. * Set navtitle.
  132. *
  133. * @param string $navtitle
  134. *
  135. * @return Page
  136. */
  137. public function setNavtitle($navtitle)
  138. {
  139. $this->navtitle = $navtitle;
  140. return $this;
  141. }
  142. /**
  143. * Get navtitle.
  144. *
  145. * @return string
  146. */
  147. public function getNavtitle()
  148. {
  149. return $this->navtitle;
  150. }
  151. /**
  152. * Set url.
  153. *
  154. * @param string $url
  155. *
  156. * @return Page
  157. */
  158. public function setUrl($url)
  159. {
  160. $this->url = $url;
  161. return $this;
  162. }
  163. /**
  164. * Get url.
  165. *
  166. * @return string
  167. */
  168. public function getUrl()
  169. {
  170. return $this->url;
  171. }
  172. /**
  173. * Set deletedAt.
  174. *
  175. * @param \DateTime|\DateTimeImmutable $deletedAt
  176. *
  177. * @return Page
  178. */
  179. public function setDeletedAt(\DateTimeInterface $deletedAt)
  180. {
  181. $this->deletedAt = $deletedAt;
  182. return $this;
  183. }
  184. /**
  185. * Set createdBy.
  186. *
  187. * @param string $createdBy
  188. *
  189. * @return Page
  190. */
  191. public function setCreatedBy($createdBy)
  192. {
  193. $this->createdBy = $createdBy;
  194. return $this;
  195. }
  196. /**
  197. * Get createdBy.
  198. *
  199. * @return string
  200. */
  201. public function getCreatedBy()
  202. {
  203. return $this->createdBy;
  204. }
  205. /**
  206. * Set updatedBy.
  207. *
  208. * @param string $updatedBy
  209. *
  210. * @return Page
  211. */
  212. public function setUpdatedBy($updatedBy)
  213. {
  214. $this->updatedBy = $updatedBy;
  215. return $this;
  216. }
  217. /**
  218. * Get updatedBy.
  219. *
  220. * @return User
  221. */
  222. public function getUpdatedBy()
  223. {
  224. return $this->updatedBy;
  225. }
  226. /**
  227. * Set parent.
  228. *
  229. * @return Page
  230. */
  231. public function setParent(?Page $parent = null)
  232. {
  233. $this->parent = $parent;
  234. return $this;
  235. }
  236. /**
  237. * Get parent.
  238. *
  239. * @return Page
  240. */
  241. public function getParent()
  242. {
  243. return $this->parent;
  244. }
  245. /**
  246. * Set template.
  247. *
  248. * @return Page
  249. */
  250. public function setTemplate(?Templates $template = null)
  251. {
  252. $this->template = $template;
  253. return $this;
  254. }
  255. /**
  256. * Get template.
  257. *
  258. * @return Templates
  259. */
  260. public function getTemplate()
  261. {
  262. return $this->template;
  263. }
  264. /**
  265. * Set components.
  266. *
  267. * @param array $components
  268. *
  269. * @return Page
  270. */
  271. public function setComponents($components)
  272. {
  273. $this->components = $components;
  274. return $this;
  275. }
  276. /**
  277. * Get components.
  278. *
  279. * @return array
  280. */
  281. public function getComponents()
  282. {
  283. return $this->components;
  284. }
  285. /**
  286. * Set extraUrlsegments.
  287. *
  288. * @param array $extraUrlsegments
  289. *
  290. * @return Page
  291. */
  292. public function setExtraUrlsegments($extraUrlsegments)
  293. {
  294. $this->extraUrlsegments = $extraUrlsegments;
  295. return $this;
  296. }
  297. /**
  298. * Get extraUrlsegments.
  299. *
  300. * @return array
  301. */
  302. public function getExtraUrlsegments()
  303. {
  304. return $this->extraUrlsegments;
  305. }
  306. /**
  307. * Set viewable_from.
  308. *
  309. * @param \DateTime|\DateTimeImmutable $viewableFrom
  310. *
  311. * @return Page
  312. */
  313. public function setViewableFrom(\DateTimeInterface $viewableFrom)
  314. {
  315. $this->viewable_from = $viewableFrom;
  316. return $this;
  317. }
  318. /**
  319. * Get viewable_from.
  320. *
  321. * @return \DateTime
  322. */
  323. public function getViewableFrom()
  324. {
  325. return $this->viewable_from;
  326. }
  327. /**
  328. * Add menupage.
  329. *
  330. * @return Page
  331. */
  332. public function addMenupage(MenuItems $menupage)
  333. {
  334. $this->menupage[] = $menupage;
  335. return $this;
  336. }
  337. /**
  338. * Remove menupage.
  339. */
  340. public function removeMenupage(MenuItems $menupage)
  341. {
  342. $this->menupage->removeElement($menupage);
  343. }
  344. /**
  345. * Get menupage.
  346. *
  347. * @return Collection
  348. */
  349. public function getMenupage()
  350. {
  351. return $this->menupage;
  352. }
  353. /**
  354. * Add slider.
  355. *
  356. * @return Page
  357. */
  358. public function addSlider(Slider $slider)
  359. {
  360. $this->slider[] = $slider;
  361. return $this;
  362. }
  363. /**
  364. * Remove slider.
  365. */
  366. public function removeSlider(Slider $slider)
  367. {
  368. $this->slider->removeElement($slider);
  369. }
  370. /**
  371. * Get slider.
  372. *
  373. * @return Collection
  374. */
  375. public function getSlider()
  376. {
  377. return $this->slider;
  378. }
  379. /**
  380. * Set htmlblocks.
  381. *
  382. * @param array $htmlblocks
  383. *
  384. * @return Page
  385. */
  386. public function setHtmlblocks($htmlblocks)
  387. {
  388. $this->htmlblocks = $htmlblocks;
  389. return $this;
  390. }
  391. /**
  392. * Get htmlblocks.
  393. *
  394. * @return array
  395. */
  396. public function getHtmlblocks()
  397. {
  398. return $this->htmlblocks;
  399. }
  400. /**
  401. * Add pagePreviews.
  402. *
  403. * @return Page
  404. */
  405. public function addPagePreview(PagePreview $pagePreviews)
  406. {
  407. $this->pagePreviews[] = $pagePreviews;
  408. return $this;
  409. }
  410. /**
  411. * Remove pagePreviews.
  412. */
  413. public function removePagePreview(PagePreview $pagePreviews)
  414. {
  415. $this->pagePreviews->removeElement($pagePreviews);
  416. }
  417. /**
  418. * Get pagePreviews.
  419. *
  420. * @return ArrayCollection
  421. */
  422. public function getPagePreviews()
  423. {
  424. return $this->pagePreviews;
  425. }
  426. // REQUIRED BY THE META LINKS TRAIT - NOT REALLY NEEDED HERE BUT WHATEVS :)
  427. public function getLinkedPageId(): int
  428. {
  429. return 1;
  430. }
  431. public function getContent2(): ?string
  432. {
  433. return $this->content2;
  434. }
  435. public function setContent2(?string $content2): self
  436. {
  437. $this->content2 = $content2;
  438. return $this;
  439. }
  440. public function getKicker(): ?string
  441. {
  442. return $this->kicker;
  443. }
  444. public function setKicker(?string $kicker): self
  445. {
  446. $this->kicker = $kicker;
  447. return $this;
  448. }
  449. /**
  450. * @return Collection<int, ImageTextGrid>
  451. */
  452. public function getImageTextGrids(): Collection
  453. {
  454. return $this->imageTextGrids;
  455. }
  456. public function addImageTextGrid(ImageTextGrid $imageTextGrid): self
  457. {
  458. if (!$this->imageTextGrids->contains($imageTextGrid)) {
  459. $this->imageTextGrids[] = $imageTextGrid;
  460. $imageTextGrid->addPage($this);
  461. }
  462. return $this;
  463. }
  464. public function removeImageTextGrid(ImageTextGrid $imageTextGrid): self
  465. {
  466. $this->imageTextGrids->removeElement($imageTextGrid);
  467. $imageTextGrid->removePage($this);
  468. return $this;
  469. }
  470. public function getGallery(): ?Gallery
  471. {
  472. return $this->gallery;
  473. }
  474. public function setGallery(?Gallery $gallery): self
  475. {
  476. $this->gallery = $gallery;
  477. return $this;
  478. }
  479. public function getSitemapRouteParams(): array
  480. {
  481. return ['slug' => $this->getSlug()];
  482. }
  483. public function isIncludedInSitemap(): bool
  484. {
  485. return $this->isActive() &&
  486. $this->isDeleted() === false &&
  487. $this->getViewableFrom() < new \DateTime() &&
  488. $this->getSlug() !== 'home' &&
  489. !str_contains($this->getSlug(), '{')
  490. ;
  491. }
  492. public function isIncludedInSitemapForEntity(): bool
  493. {
  494. return $this->isActive() &&
  495. $this->isDeleted() === false &&
  496. $this->getViewableFrom() < new \DateTime() &&
  497. str_contains($this->getSlug(), '{')
  498. ;
  499. }
  500. }