<?php
namespace App\Entity;
use App\Entity\Traits\LinkTrait;
use App\Entity\Traits\MetaTrait;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Traits\ActiveTrait;
use App\Entity\Traits\DeleteTrait;
use App\Entity\Traits\SubTitleTrait;
use App\Entity\Traits\TranslateTrait;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Entity\Traits\ImageUploadTrait;
use App\Entity\Traits\SitemapableTrait;
use App\Entity\Traits\SecondContentTrait;
use App\Entity\Traits\TitleAndContentTrait;
use Doctrine\Common\Collections\Collection;
use App\Entity\Interfaces\DefaultLinkedEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @Gedmo\Loggable
*
* @Gedmo\TranslationEntity(class="App\Entity\PageTranslations")
*/
#[UniqueEntity(fields: ['slug'], errorPath: 'slug', message: 'A page has already be created with that title.')]
#[ORM\Entity(repositoryClass: \App\Repository\PageRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: 'page')]
class Page implements DefaultLinkedEntity
{
use TitleAndContentTrait;
use SubTitleTrait;
use LinkTrait;
use MetaTrait;
use ActiveTrait;
use DeleteTrait;
use ImageUploadTrait;
use TimestampableEntity;
use TranslateTrait;
use SecondContentTrait;
use SitemapableTrait;
/**
* @var \DateTime
*/
public $deletedAt;
public ?string $createdBy = null;
#[ORM\Column(name: 'components', type: 'array', nullable: true)]
protected array $components = [];
#[ORM\Column(name: 'extraUrlsegments', type: 'array', nullable: true)]
protected array $extraUrlsegments = [];
#[ORM\Column(name: 'htmlblocks', type: 'array', nullable: true)]
protected array $htmlblocks = [];
/*
SPECIFICALLY OVERRIDING SLUG PROPERTY AS NEEDS
TO NOT BE CREATED AUTOMATICALLY
*/
/**
* @Gedmo\Translatable
*
* @Gedmo\Versioned
*/
#[ORM\Column(length: 255, unique: true)]
private ?string $slug = null;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private readonly int $id;
/**
* @Gedmo\Translatable
*
* @Gedmo\Versioned
*/
#[Assert\NotBlank(message: 'The menu title should not be blank')]
#[ORM\Column(name: 'navtitle', type: 'string', length: 128)]
private ?string $navtitle = null;
/**
* @Gedmo\Translatable
*
* @Gedmo\Versioned
*/
#[ORM\Column(name: 'url', type: 'string', length: 128, nullable: true)]
private ?string $url = null;
#[ORM\Column(name: 'viewable_from', type: 'datetime')]
private ?\DateTimeInterface $viewable_from = null;
#[ORM\ManyToOne(targetEntity: \App\Entity\User::class, inversedBy: 'pagesupdated')]
#[ORM\JoinColumn(name: 'update_by', referencedColumnName: 'id')]
private $updatedBy;
#[ORM\ManyToOne(targetEntity: 'Page')]
#[ORM\JoinColumn(name: 'parent', unique: false, referencedColumnName: 'id', nullable: true)]
private ?Page $parent = null;
#[Assert\NotBlank(message: 'You must select a template')]
#[ORM\ManyToOne(targetEntity: \App\Entity\Templates::class, inversedBy: 'pagetemplate')]
private ?Templates $template = null;
#[ORM\OneToMany(targetEntity: \App\Entity\MenuItems::class, mappedBy: 'pageId')]
private ?Collection $menupage;
#[ORM\ManyToMany(targetEntity: \App\Entity\Slider::class, mappedBy: 'pages')]
private ?Collection $slider = null;
#[ORM\OneToMany(targetEntity: \App\Entity\PagePreview::class, mappedBy: 'page')]
private ?Collection $pagePreviews = null;
#[ORM\Column(name: 'content3', type: 'text', nullable: true)]
private ?string $content3 = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cta_text;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cta_link;
#[ORM\ManyToOne(targetEntity: Testimonial::class)]
#[ORM\JoinColumn(nullable: true)]
private $testimonial;
#[ORM\Column(type: 'json', nullable: true)]
private $landingPageBlocks = [];
#[ORM\OneToOne(targetEntity: AreasWeCover::class, mappedBy: 'page')]
private ?AreasWeCover $areasWeCover = null;
/**
* Constructor.
*/
public function __construct()
{
$this->menupage = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set navtitle.
*
* @param string $navtitle
*
* @return Page
*/
public function setNavtitle($navtitle)
{
$this->navtitle = $navtitle;
return $this;
}
/**
* Get navtitle.
*
* @return string
*/
public function getNavtitle()
{
return $this->navtitle;
}
/**
* Set url.
*
* @param string $url
*
* @return Page
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url.
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set deletedAt.
*
* @param \DateTime|\DateTimeImmutable $deletedAt
*
* @return Page
*/
public function setDeletedAt(\DateTimeInterface $deletedAt)
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Set createdBy.
*
* @param string $createdBy
*
* @return Page
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* Get createdBy.
*
* @return string
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Set updatedBy.
*
* @param string $updatedBy
*
* @return Page
*/
public function setUpdatedBy($updatedBy)
{
$this->updatedBy = $updatedBy;
return $this;
}
/**
* Get updatedBy.
*
* @return \App\Entity\User
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* Set parent.
*
* @return Page
*/
public function setParent(Page $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent.
*
* @return \App\Entity\Page
*/
public function getParent()
{
return $this->parent;
}
/**
* Set template.
*
* @return Page
*/
public function setTemplate(Templates $template = null)
{
$this->template = $template;
return $this;
}
/**
* Get template.
*
* @return \App\Entity\Templates
*/
public function getTemplate()
{
return $this->template;
}
/**
* Set components.
*
* @param array $components
*
* @return Page
*/
public function setComponents($components)
{
$this->components = $components;
return $this;
}
/**
* Get components.
*
* @return array
*/
public function getComponents()
{
return $this->components;
}
/**
* Set extraUrlsegments.
*
* @param array $extraUrlsegments
*
* @return Page
*/
public function setExtraUrlsegments($extraUrlsegments)
{
$this->extraUrlsegments = $extraUrlsegments;
return $this;
}
/**
* Get extraUrlsegments.
*
* @return array
*/
public function getExtraUrlsegments()
{
return $this->extraUrlsegments;
}
/**
* Set viewable_from.
*
* @param \DateTime|\DateTimeImmutable $viewableFrom
*
* @return Page
*/
public function setViewableFrom(\DateTimeInterface $viewableFrom)
{
$this->viewable_from = $viewableFrom;
return $this;
}
/**
* Get viewable_from.
*
* @return \DateTime
*/
public function getViewableFrom()
{
return $this->viewable_from;
}
/**
* Add menupage.
*
* @return Page
*/
public function addMenupage(MenuItems $menupage)
{
$this->menupage[] = $menupage;
return $this;
}
/**
* Remove menupage.
*/
public function removeMenupage(MenuItems $menupage)
{
$this->menupage->removeElement($menupage);
}
/**
* Get menupage.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMenupage()
{
return $this->menupage;
}
/**
* Add slider.
*
* @return Page
*/
public function addSlider(Slider $slider)
{
$this->slider[] = $slider;
return $this;
}
/**
* Remove slider.
*/
public function removeSlider(Slider $slider)
{
$this->slider->removeElement($slider);
}
/**
* Get slider.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSlider()
{
return $this->slider;
}
/**
* Set htmlblocks.
*
* @param array $htmlblocks
*
* @return Page
*/
public function setHtmlblocks($htmlblocks)
{
$this->htmlblocks = $htmlblocks;
return $this;
}
/**
* Get htmlblocks.
*
* @return array
*/
public function getHtmlblocks()
{
return $this->htmlblocks;
}
/**
* Add pagePreviews.
*
* @return Page
*/
public function addPagePreview(PagePreview $pagePreviews)
{
$this->pagePreviews[] = $pagePreviews;
return $this;
}
/**
* Remove pagePreviews.
*/
public function removePagePreview(PagePreview $pagePreviews)
{
$this->pagePreviews->removeElement($pagePreviews);
}
/**
* Get pagePreviews.
*
* @return ArrayCollection
*/
public function getPagePreviews()
{
return $this->pagePreviews;
}
// REQUIRED BY THE META LINKS TRAIT - NOT REALLY NEEDED HERE BUT WHATEVS :)
public function getLinkedPageId(): int
{
return 1;
}
public function getContent3(): ?string
{
return $this->content3;
}
public function setContent3(?string $content3): self
{
$this->content3 = $content3;
return $this;
}
public function getCtaText(): ?string
{
return $this->cta_text;
}
public function setCtaText(?string $cta_text): self
{
$this->cta_text = $cta_text;
return $this;
}
public function getCtaLink(): ?string
{
return $this->cta_link;
}
public function setCtaLink(?string $cta_link): self
{
$this->cta_link = $cta_link;
return $this;
}
public function getTestimonial(): ?Testimonial
{
return $this->testimonial;
}
public function setTestimonial(?Testimonial $testimonial): self
{
$this->testimonial = $testimonial;
return $this;
}
/**
* @return array
*/
public function getLandingPageBlocks(): array
{
return $this->landingPageBlocks ?: [];
}
/**
* @param array $landingPageBlocks
* @return $this
*/
public function setLandingPageBlocks(array $landingPageBlocks): self
{
$this->landingPageBlocks = $landingPageBlocks;
return $this;
}
public function getAreasWeCover(): ?AreasWeCover
{
return $this->areasWeCover;
}
public function setAreasWeCover(?AreasWeCover $areasWeCover): self
{
$this->areasWeCover = $areasWeCover;
return $this;
}
public function getSitemapRouteParams(): array
{
return ['slug' => $this->getSlug()];
}
public function isIncludedInSitemap(): bool
{
return $this->isActive() &&
$this->isDeleted() === false &&
$this->getViewableFrom() < new \DateTime() &&
$this->getSlug() !== 'home' &&
!str_contains($this->getSlug(), '{')
;
}
public function isIncludedInSitemapForEntity(): bool
{
return $this->isActive() &&
$this->isDeleted() === false &&
$this->getViewableFrom() < new \DateTime() &&
str_contains($this->getSlug(), '{')
;
}
}