src/Entity/Page.php line 273

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 Gedmo\Mapping\Annotation as Gedmo;
  11. use App\Entity\Traits\ImageUploadTrait;
  12. use App\Entity\Traits\SitemapableTrait;
  13. use App\Entity\Traits\SecondContentTrait;
  14. use App\Entity\Traits\TitleAndContentTrait;
  15. use Doctrine\Common\Collections\Collection;
  16. use App\Entity\Interfaces\DefaultLinkedEntity;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Gedmo\Timestampable\Traits\TimestampableEntity;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. /**
  22. * @Gedmo\Loggable
  23. *
  24. * @Gedmo\TranslationEntity(class="App\Entity\PageTranslations")
  25. */
  26. #[UniqueEntity(fields: ['slug'], errorPath: 'slug', message: 'A page has already be created with that title.')]
  27. #[ORM\Entity(repositoryClass: \App\Repository\PageRepository::class)]
  28. #[ORM\HasLifecycleCallbacks]
  29. #[ORM\Table(name: 'page')]
  30. class Page implements DefaultLinkedEntity
  31. {
  32. use TitleAndContentTrait;
  33. use SubTitleTrait;
  34. use LinkTrait;
  35. use MetaTrait;
  36. use ActiveTrait;
  37. use DeleteTrait;
  38. use ImageUploadTrait;
  39. use TimestampableEntity;
  40. use TranslateTrait;
  41. use SecondContentTrait;
  42. use SitemapableTrait;
  43. /**
  44. * @var \DateTime
  45. */
  46. public $deletedAt;
  47. public ?string $createdBy = null;
  48. #[ORM\Column(name: 'components', type: 'array', nullable: true)]
  49. protected array $components = [];
  50. #[ORM\Column(name: 'extraUrlsegments', type: 'array', nullable: true)]
  51. protected array $extraUrlsegments = [];
  52. #[ORM\Column(name: 'htmlblocks', type: 'array', nullable: true)]
  53. protected array $htmlblocks = [];
  54. /*
  55. SPECIFICALLY OVERRIDING SLUG PROPERTY AS NEEDS
  56. TO NOT BE CREATED AUTOMATICALLY
  57. */
  58. /**
  59. * @Gedmo\Translatable
  60. *
  61. * @Gedmo\Versioned
  62. */
  63. #[ORM\Column(length: 255, unique: true)]
  64. private ?string $slug = null;
  65. #[ORM\Id]
  66. #[ORM\GeneratedValue]
  67. #[ORM\Column(type: 'integer')]
  68. private readonly int $id;
  69. /**
  70. * @Gedmo\Translatable
  71. *
  72. * @Gedmo\Versioned
  73. */
  74. #[Assert\NotBlank(message: 'The menu title should not be blank')]
  75. #[ORM\Column(name: 'navtitle', type: 'string', length: 128)]
  76. private ?string $navtitle = null;
  77. /**
  78. * @Gedmo\Translatable
  79. *
  80. * @Gedmo\Versioned
  81. */
  82. #[ORM\Column(name: 'url', type: 'string', length: 128, nullable: true)]
  83. private ?string $url = null;
  84. #[ORM\Column(name: 'viewable_from', type: 'datetime')]
  85. private ?\DateTimeInterface $viewable_from = null;
  86. #[ORM\ManyToOne(targetEntity: \App\Entity\User::class, inversedBy: 'pagesupdated')]
  87. #[ORM\JoinColumn(name: 'update_by', referencedColumnName: 'id')]
  88. private $updatedBy;
  89. #[ORM\ManyToOne(targetEntity: 'Page')]
  90. #[ORM\JoinColumn(name: 'parent', unique: false, referencedColumnName: 'id', nullable: true)]
  91. private ?Page $parent = null;
  92. #[Assert\NotBlank(message: 'You must select a template')]
  93. #[ORM\ManyToOne(targetEntity: \App\Entity\Templates::class, inversedBy: 'pagetemplate')]
  94. private ?Templates $template = null;
  95. #[ORM\OneToMany(targetEntity: \App\Entity\MenuItems::class, mappedBy: 'pageId')]
  96. private ?Collection $menupage;
  97. #[ORM\ManyToMany(targetEntity: \App\Entity\Slider::class, mappedBy: 'pages')]
  98. private ?Collection $slider = null;
  99. #[ORM\OneToMany(targetEntity: \App\Entity\PagePreview::class, mappedBy: 'page')]
  100. private ?Collection $pagePreviews = null;
  101. #[ORM\Column(name: 'content3', type: 'text', nullable: true)]
  102. private ?string $content3 = null;
  103. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  104. private $cta_text;
  105. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  106. private $cta_link;
  107. #[ORM\ManyToOne(targetEntity: Testimonial::class)]
  108. #[ORM\JoinColumn(nullable: true)]
  109. private $testimonial;
  110. #[ORM\Column(type: 'json', nullable: true)]
  111. private $landingPageBlocks = [];
  112. #[ORM\OneToOne(targetEntity: AreasWeCover::class, mappedBy: 'page')]
  113. private ?AreasWeCover $areasWeCover = null;
  114. /**
  115. * Constructor.
  116. */
  117. public function __construct()
  118. {
  119. $this->menupage = 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 \App\Entity\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 \App\Entity\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 \App\Entity\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 \Doctrine\Common\Collections\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 \Doctrine\Common\Collections\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 getContent3(): ?string
  432. {
  433. return $this->content3;
  434. }
  435. public function setContent3(?string $content3): self
  436. {
  437. $this->content3 = $content3;
  438. return $this;
  439. }
  440. public function getCtaText(): ?string
  441. {
  442. return $this->cta_text;
  443. }
  444. public function setCtaText(?string $cta_text): self
  445. {
  446. $this->cta_text = $cta_text;
  447. return $this;
  448. }
  449. public function getCtaLink(): ?string
  450. {
  451. return $this->cta_link;
  452. }
  453. public function setCtaLink(?string $cta_link): self
  454. {
  455. $this->cta_link = $cta_link;
  456. return $this;
  457. }
  458. public function getTestimonial(): ?Testimonial
  459. {
  460. return $this->testimonial;
  461. }
  462. public function setTestimonial(?Testimonial $testimonial): self
  463. {
  464. $this->testimonial = $testimonial;
  465. return $this;
  466. }
  467. /**
  468. * @return array
  469. */
  470. public function getLandingPageBlocks(): array
  471. {
  472. return $this->landingPageBlocks ?: [];
  473. }
  474. /**
  475. * @param array $landingPageBlocks
  476. * @return $this
  477. */
  478. public function setLandingPageBlocks(array $landingPageBlocks): self
  479. {
  480. $this->landingPageBlocks = $landingPageBlocks;
  481. return $this;
  482. }
  483. public function getAreasWeCover(): ?AreasWeCover
  484. {
  485. return $this->areasWeCover;
  486. }
  487. public function setAreasWeCover(?AreasWeCover $areasWeCover): self
  488. {
  489. $this->areasWeCover = $areasWeCover;
  490. return $this;
  491. }
  492. public function getSitemapRouteParams(): array
  493. {
  494. return ['slug' => $this->getSlug()];
  495. }
  496. public function isIncludedInSitemap(): bool
  497. {
  498. return $this->isActive() &&
  499. $this->isDeleted() === false &&
  500. $this->getViewableFrom() < new \DateTime() &&
  501. $this->getSlug() !== 'home' &&
  502. !str_contains($this->getSlug(), '{')
  503. ;
  504. }
  505. public function isIncludedInSitemapForEntity(): bool
  506. {
  507. return $this->isActive() &&
  508. $this->isDeleted() === false &&
  509. $this->getViewableFrom() < new \DateTime() &&
  510. str_contains($this->getSlug(), '{')
  511. ;
  512. }
  513. }