<?php
namespace App\CmsBundle\Entity;
use App\CasinoBundle\Entity\Author;
use App\CmsBundle\Enum\PrimeImagePositionEnum;
use App\CmsBundle\Enum\RobotsValue;
use App\CmsBundle\Enum\StatusCodeEnum;
use App\CmsBundle\Helper\StringHelper;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Google\Type\DateTime;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\CmsBundle\Repository\PageRepository")
* @ORM\Table(
* name="page",
* indexes={
* @ORM\Index(name="page_site_idx", columns={"site_id"}),
* @ORM\Index(name="page_path_idx", columns={"path"}),
* @ORM\Index(name="page_published_idx", columns={"published"}),
* @ORM\Index(name="page_canonical_url_idx", columns={"canonical_url"}),
* @ORM\Index(name="page_slug_idx", columns={"slug"}),
* @ORM\Index(name="page_hreflang_idx", columns={"hreflang_published"}),
* @ORM\Index(name="page_ctr_updated", columns={"ctr_updated"}),
* @ORM\Index(name="page_related_to_idx", columns={"related_to_id"}),
* @ORM\Index(name="page_redirect_url_idx", columns={"redirect_url"}),
* @ORM\Index(name="page_author_idx", columns={"author_id"}),
* @ORM\Index(name="page_reviewer_idx", columns={"reviewer_id"})
* },
* uniqueConstraints={
* @ORM\UniqueConstraint(name="page_uindex", columns={"route_id","path"}),
* @ORM\UniqueConstraint(name="page_site_path_uindex", columns={"site_id","path"})
* }
* )
* @ORM\HasLifecycleCallbacks()
*/
class Page
{
use IdTrait, TitleTrait, AlternativeTitleTrait, PathTrait, DescriptionTrait, PublishedTrait, SiteTrait, ParametersTrait, TimeStampedTrait, SlugTrait;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site")
* @ORM\JoinColumn(name="site_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $site;
/**
* @ORM\OneToOne(targetEntity="App\CmsBundle\Entity\DirectoryItem", inversedBy="page")
* @ORM\JoinColumn(name="directory_item_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private $directoryItem;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Route", inversedBy="pages")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $route;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Template", inversedBy="pages")
* @ORM\JoinColumn(nullable=true)
*/
private $template;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $h1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $alternativeH1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $breadcrumbsTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $breadcrumbsPattern;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $summaryTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $canonicalUrl;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $redirectUrl;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $robots;
/**
* @ORM\Column(type="string", options={"default" : "D"})
* @Assert\Regex("/\b[A-D]\b/")
*/
private $seoPriority = 'D';
/**
* @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\StaticContent", fetch="EXTRA_LAZY", mappedBy="page")
* @ORM\JoinColumn(nullable=true)
*/
private $staticContents;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $alternativeDescription;
/**
* @ORM\Column(
* type="boolean", options={"default":"0"}, nullable=true
* )
*/
private $crawl;
private $syncPage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $backgroundUrlDesktop;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $backgroundUrlMobile;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default" : false})
*/
private $displayPrimeImages = false;
/**
* @ORM\Column(type="integer", nullable=true, options={"default" : 1})
*/
private $primeImagePosition = PrimeImagePositionEnum::RIGHT;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $primeImageDesktop;
private $removePrimeImageDesktop;
private $removePrimeImageMobile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $primeImageMobile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $primeImageAlt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $primeGradient;
/**
* @ORM\Column(type="integer", options={"default" : "200"})
*/
private $statusCode = 200;
/**
*
* @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Bullet", mappedBy="page", cascade={"persist"}, orphanRemoval=true)
* @ORM\JoinColumn(nullable=true)
*/
private Collection $bullet;
/**
* @ORM\Column(
* type="boolean", options={"default":"1"}, nullable=true
* )
*/
private $hreflangPublished;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mainKeyword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $altKeywords;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Page", inversedBy="relates", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(nullable=true)
*/
private $relatedTo;
/**
* @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Page", mappedBy="relatedTo", cascade={"persist","remove"})
*/
private $relates;
/**
* @ORM\OneToMany(
* targetEntity=PageTag::class,
* mappedBy="page",
* cascade={"persist"},
* orphanRemoval=true
* )
*/
private Collection $pageTags;
/**
* @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Ctr", mappedBy="page", fetch="EXTRA_LAZY")
*/
private $ctr;
/**
* @var DateTime
*
* @ORM\Column(name="ctr_updated", type="google_datetime", nullable=true)
*/
private $ctrUpdated;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Locale", inversedBy="pages")
* @ORM\JoinColumn(nullable=true)
*/
private $htmlLang;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $hreflangUrl;
/**
* @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=true)
*/
private ?Author $author = null;
/**
* @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author")
* @ORM\JoinColumn(name="reviewer_id", referencedColumnName="id", nullable=true)
*/
private ?Author $reviewer = null;
public function __construct()
{
$this->staticContents = new ArrayCollection();
$this->bullet = new ArrayCollection();
$this->relates = new ArrayCollection();
$this->pageTags = new ArrayCollection();
$this->ctr = new ArrayCollection();
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getPath();
}
public function getParameters(): array
{
return array_merge(
json_decode($this->parameters ?? '', true) ?? [],
[
'id' => (string)$this->id,
'backgroundUrlDesktop' => $this->getBackgroundUrlDesktop(),
'backgroundUrlMobile' => $this->getBackgroundUrlMobile(),
'displayPrimeImages' => $this->getDisplayPrimeImages(),
'primeImagePosition' => $this->getPrimeImagePosition(),
'primeImageDesktop' => $this->getPrimeImageDesktop(),
'primeImageMobile' => $this->getPrimeImageMobile(),
'primeImageAlt' => $this->getPrimeImageAlt(),
'primeGradient' => $this->getPrimeGradient(),
'canonicalUrl' => $this->getCanonicalUrl()
]
);
}
/**
* @return array
*/
public function getAutoReplacedVariables(): array
{
return [
'{pageTitle}' => $this->alternativeTitle ?? $this->title,
'{description}' => $this->alternativeDescription ?? $this->description,
'{h1}' => $this->alternativeH1 ?? $this->h1,
'{breadcrumbsTitle}' => $this->breadcrumbsTitle,
'{summaryTitle}' => $this->summaryTitle
];
}
/**
* @return string|null
*/
public function getPageUrl(): ?string
{
if (is_null($this->getSite())) return null;
return $this->getSite()->getDomain() . $this->getPath();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getH1(): ?string
{
return $this->h1;
}
/**
* @param string|null $h1
* @return $this
*/
public function setH1(?string $h1): self
{
$this->h1 = StringHelper::emptyToNull($h1);
return $this;
}
/**
* @return string|null
*/
public function getAlternativeH1(): ?string
{
return $this->alternativeH1;
}
/**
* @param string|null $alternativeH1
* @return $this
*/
public function setAlternativeH1(?string $alternativeH1): self
{
$this->alternativeH1 = StringHelper::emptyToNull($alternativeH1);
return $this;
}
/**
* @return string|null
*/
public function getBreadcrumbsPattern(): ?string
{
return $this->breadcrumbsPattern;
}
/**
* @param string|null $breadcrumbsPattern
* @return $this
*/
public function setBreadcrumbsPattern(?string $breadcrumbsPattern): self
{
$this->breadcrumbsPattern = StringHelper::emptyToNull($breadcrumbsPattern);
return $this;
}
/**
* @return string|null
*/
public function getBreadcrumbsTitle(): ?string
{
return $this->breadcrumbsTitle;
}
/**
* @param string|null $breadcrumbsTitle
* @return $this
*/
public function setBreadcrumbsTitle(?string $breadcrumbsTitle): self
{
$this->breadcrumbsTitle = StringHelper::emptyToNull($breadcrumbsTitle);
return $this;
}
/**
* @return string|null
*/
public function getSummaryTitle(): ?string
{
return $this->summaryTitle;
}
/**
* @param string|null $summaryTitle
* @return $this
*/
public function setSummaryTitle(?string $summaryTitle): self
{
$this->summaryTitle = StringHelper::emptyToNull($summaryTitle);
return $this;
}
/**
* @return string|null
*/
public function getCanonicalUrl(): ?string
{
return $this->canonicalUrl;
}
/**
* @return string|null
*/
public function getCanonical(): ?string
{
return $this->getCanonicalUrl();
}
/**
* @return string|null
*/
public function getSeoPriority(): ?string
{
return $this->seoPriority;
}
/**
* @param string|null $seoPriority
* @return $this
*/
public function setSeoPriority(?string $seoPriority = null): self
{
$this->seoPriority = $seoPriority;
return $this;
}
/**
* @param string|null $canonicalUrl
* @return $this
*/
public function setCanonicalUrl(?string $canonicalUrl = null): self
{
$this->canonicalUrl = StringHelper::emptyToNull($canonicalUrl);
return $this;
}
/**
* @return string|null
*/
public function getHreflangUrl(): ?string
{
return $this->hreflangUrl;
}
/**
* @param string|null $hreflangUrl
* @return $this
*/
public function setHreflangUrl(?string $hreflangUrl = null): self
{
$this->hreflangUrl = StringHelper::emptyToNull($hreflangUrl);
return $this;
}
/**
* @return string|null
*/
public function getRedirectUrl(): ?string
{
return $this->redirectUrl;
}
/**
* @param string|null $redirectUrl
* @return $this
*/
public function setRedirectUrl(?string $redirectUrl = null): self
{
if (!is_null($redirectUrl) && !empty($redirectUrl)) {
$this->statusCode = StatusCodeEnum::STATUS_301;
}
$this->redirectUrl = StringHelper::emptyToNull($redirectUrl);
return $this;
}
/**
* @return int|null
*/
public function getRobots(): ?int
{
return $this->robots;
}
/**
* @param int|null $robots
* @return $this
*/
public function setRobots(?int $robots = null): self
{
$this->robots = $robots;
return $this;
}
/**
* @return int|null
*/
public function getPrimeImagePosition(): ?int
{
return $this->primeImagePosition;
}
/**
* @param int|null $primeImagePosition
* @return $this
*/
public function setPrimeImagePosition(?int $primeImagePosition = PrimeImagePositionEnum::RIGHT): self
{
$this->primeImagePosition = $primeImagePosition;
return $this;
}
/**
* @return int|null
*/
public function getStatusCode(): ?int
{
return $this->statusCode;
}
/**
* @param int|null $statusCode
* @return $this
*/
public function setStatusCode(?int $statusCode = StatusCodeEnum::STATUS_200): self
{
$this->statusCode = $statusCode;
return $this;
}
/**
* @return string|null
*/
public function getRobotsValue(): ?string
{
return ($this->robots) ? RobotsValue::getValue($this->robots) : null;
}
/**
* @return Route|null
*/
public function getRoute(): ?Route
{
return $this->route;
}
/**
* @param Route|null $route
* @return $this
*/
public function setRoute(?Route $route): self
{
$this->route = $route;
if ($route) $route->addPage($this);
return $this;
}
/**
* @return Template|null
*/
public function getTemplate(): ?Template
{
return $this->template;
}
/**
* @param Template|null $template
* @return $this
*/
public function setTemplate(?Template $template): self
{
$this->template = $template;
if ($template) {
$template->addPage($this);
$this->setRoute($template->getRoute());
$this->setSite($template->getRoute()->getSite());
} else {
$this->setRoute(null);
$this->setSite(null);
}
return $this;
}
/**
* @return Collection
*/
public function getStaticContents(): Collection
{
if (!$this->staticContents) $this->staticContents = new ArrayCollection();
return $this->staticContents;
}
/**
* @param StaticContent $staticContent
* @return $this
*/
public function addStaticContent(StaticContent $staticContent): self
{
if (!$this->staticContents->contains($staticContent)) {
$this->staticContents[] = $staticContent;
$staticContent->setPage($this);
}
return $this;
}
/**
* @param StaticContent $staticContent
* @return $this
*/
public function removeStaticContent(StaticContent $staticContent): self
{
if ($this->staticContents->contains($staticContent)) {
$this->staticContents->removeElement($staticContent);
// set the owning side to null (unless already changed)
if ($staticContent->getPage() === $this) {
$staticContent->setPage(null);
}
}
return $this;
}
/**
* @return string|null
*/
public function getAlternativeDescription(): ?string
{
return $this->alternativeDescription;
}
/**
* @param string|null $alternativeDescription
* @return $this
*/
public function setAlternativeDescription(?string $alternativeDescription): self
{
$this->alternativeDescription = StringHelper::emptyToNull($alternativeDescription);
return $this;
}
/**
* @return bool
*/
public function getHreflangPublished(): bool
{
return (bool)$this->hreflangPublished;
}
/**
* @param bool $hreflangPublished
* @return $this
*/
public function setHreflangPublished(bool $hreflangPublished): self
{
$this->hreflangPublished = $hreflangPublished;
return $this;
}
/**
* @return bool
*/
public function getCrawl(): bool
{
return (bool)$this->crawl;
}
/**
* @param bool $crawl
* @return $this
*/
public function setCrawl(bool $crawl): self
{
$this->crawl = $crawl;
return $this;
}
/**
* @return string|null
*/
public function getBackgroundUrlDesktop(): ?string
{
return $this->backgroundUrlDesktop;
}
/**
* @param string|null $backgroundUrlDesktop
* @return $this
*/
public function setBackgroundUrlDesktop(?string $backgroundUrlDesktop): self
{
$this->backgroundUrlDesktop = $backgroundUrlDesktop;
return $this;
}
/**
* @return string|null
*/
public function getBackgroundUrlMobile(): ?string
{
return $this->backgroundUrlMobile;
}
/**
* @param string|null $backgroundUrlMobile
* @return $this
*/
public function setBackgroundUrlMobile(?string $backgroundUrlMobile): self
{
$this->backgroundUrlMobile = $backgroundUrlMobile;
return $this;
}
/**
* @return bool|null
*/
public function getDisplayPrimeImages(): ?bool
{
return $this->displayPrimeImages;
}
/**
* @param bool|null $displayPrimeImages
* @return $this
*/
public function setDisplayPrimeImages(?bool $displayPrimeImages): self
{
$this->displayPrimeImages = $displayPrimeImages;
return $this;
}
/**
* @return string|null
*/
public function getPrimeImageDesktop(): ?string
{
return $this->primeImageDesktop;
}
/**
* @param string|null $primeImageDesktop
* @return $this
*/
public function setPrimeImageDesktop(?string $primeImageDesktop): self
{
$this->primeImageDesktop = $primeImageDesktop;
return $this;
}
/**
* @return bool|null
*/
public function getRemovePrimeImageDesktop(): ?bool
{
return $this->removePrimeImageDesktop;
}
/**
* @param bool|null $removePrimeImageDesktop
* @return $this
*/
public function setRemovePrimeImageDesktop(?bool $removePrimeImageDesktop): self
{
$this->removePrimeImageDesktop = $removePrimeImageDesktop;
return $this;
}
/**
* @return bool|null
*/
public function getRemovePrimeImageMobile(): ?bool
{
return $this->removePrimeImageMobile;
}
/**
* @param bool|null $removePrimeImageMobile
* @return $this
*/
public function setRemovePrimeImageMobile(?bool $removePrimeImageMobile): self
{
$this->removePrimeImageMobile = $removePrimeImageMobile;
return $this;
}
/**
* @return string|null
*/
public function getPrimeImageMobile(): ?string
{
return $this->primeImageMobile;
}
/**
* @param string|null $primeImageMobile
* @return $this
*/
public function setPrimeImageMobile(?string $primeImageMobile): self
{
$this->primeImageMobile = $primeImageMobile;
return $this;
}
/**
* @return string|null
*/
public function getPrimeImageAlt(): ?string
{
return $this->primeImageAlt;
}
/**
* @param string|null $primeImageAlt
* @return $this
*/
public function setPrimeImageAlt(?string $primeImageAlt): self
{
$this->primeImageAlt = $primeImageAlt;
return $this;
}
/**
* @return string|null
*/
public function getPrimeGradient(): ?string
{
return $this->primeGradient;
}
/**
* @param string|null $primeGradient
* @return $this
*/
public function setPrimeGradient(?string $primeGradient): self
{
$this->primeGradient = $primeGradient;
return $this;
}
/**
* @param DirectoryItem|null $directoryItem
* @return $this
*/
public function setDirectoryItem(?DirectoryItem $directoryItem): self
{
$this->directoryItem = $directoryItem;
return $this;
}
/**
* @return DirectoryItem|null
*/
public function getDirectoryItem(): ?DirectoryItem
{
return $this->directoryItem;
}
/**
* @return Collection
*/
public function getBullet(): Collection
{
return $this->bullet ?? new ArrayCollection();
}
/**
* @param Bullet $bullet
* @return $this
*/
public function addBullet(Bullet $bullet): self
{
$this->bullet[] = $bullet;
$bullet->setPage($this);
return $this;
}
/**
* @param Bullet $bullet
* @return void
*/
public function removeBullet(Bullet $bullet): void
{
$this->bullet->removeElement($bullet);
}
/**
* @param string $path
* @return $this
*/
public function setPath(string $path): self
{
$this->path = $path;
$pathExpl = explode('/', $path);
$this->setSlug(end($pathExpl));
return $this;
}
/**
* @return string|null
*/
public function getMainKeyword(): ?string
{
return $this->mainKeyword;
}
/**
* @param string|null $mainKeyword
* @return $this
*/
public function setMainKeyword(?string $mainKeyword): self
{
$this->mainKeyword = $mainKeyword;
return $this;
}
/**
* @return string|null
*/
public function getAltKeywords(): ?string
{
return $this->altKeywords;
}
/**
* @param string|null $altKeywords
* @return $this
*/
public function setAltKeywords(?string $altKeywords): self
{
$this->altKeywords = $altKeywords;
return $this;
}
/**
* @return Page|null
*/
public function getRelatedTo(): ?Page
{
return $this->relatedTo;
}
/**
* @param Page|null $relatedTo
* @return $this
*/
public function setRelatedTo(?Page $relatedTo): self
{
$this->relatedTo = $relatedTo;
return $this;
}
/**
* @return Collection|Page[]
*/
public function getRelates(): Collection
{
return $this->relates;
}
/**
* @param Page $relate
* @return $this
*/
public function addRelates(Page $relate): self
{
if (!$this->relates->contains($relate)) {
$this->relates[] = $relate;
$relate->setRelatedTo($this);
}
return $this;
}
/**
* @param Page $relate
* @return $this
*/
public function removeRelates(Page $relate): self
{
if ($this->relates->contains($relate)) {
$this->relates->removeElement($relate);
// set the owning side to null (unless already changed)
if ($relate->getRelatedTo() === $this) {
$relate->setRelatedTo(null);
}
}
return $this;
}
/**
* @return Collection
*/
public function getPageTags(): Collection
{
return $this->pageTags;
}
/**
* @return int
*/
public function getPageTagsCount(): int
{
return $this->pageTags->count();
}
/**
* @return int
*/
public function getWidgetIntent(): int
{
if (!$this->getTemplate()) {
return 0;
}
foreach ($this->getTemplate()->getWidgets() as $widget) {
if ($widget->getParameter('intentFit')) {
return 1;
}
}
return 0;
}
/**
* @param PageTag $pageTag
* @return $this
*/
public function addPageTag(PageTag $pageTag): self
{
if (!$this->pageTags->contains($pageTag)) {
$this->pageTags[] = $pageTag;
$pageTag->setPage($this);
}
return $this;
}
/**
* @param PageTag $pageTag
* @return $this
*/
public function removePageTag(PageTag $pageTag): self
{
if ($this->pageTags->contains($pageTag)) {
$this->pageTags->removeElement($pageTag);
}
return $this;
}
/**
* @return Collection|Ctr[]
*/
public function getCtr(): Collection
{
return $this->ctr;
}
/**
* @param Ctr $ctr
* @return $this
*/
public function addCtr(Ctr $ctr): self
{
if (!$this->ctr->contains($ctr)) {
$this->ctr[] = $ctr;
$ctr->setPage($this);
}
return $this;
}
/**
* @param Ctr $ctr
* @return $this
*/
public function removeCtr(Ctr $ctr): self
{
if ($this->ctr->contains($ctr)) {
$this->ctr->removeElement($ctr);
}
return $this;
}
/**
* Get updated
*
* @return DateTime|null
*/
public function getCtrUpdated():?DateTime
{
return $this->ctrUpdated;
}
/**
* @return Locale|null
*/
public function getHtmlLang(): ?Locale
{
return $this->htmlLang;
}
/**
* @param Locale|null $htmlLang
* @return $this
*/
public function setHtmlLang(?Locale $htmlLang): self
{
$this->htmlLang = $htmlLang;
return $this;
}
/**
* @return Author|null
*/
public function getAuthor(): ?Author
{
return $this->author;
}
/**
* @param Author|null $author
* @return $this
*/
public function setAuthor(?Author $author): self
{
$this->author = $author;
return $this;
}
/**
* @return Author|null
*/
public function getReviewer(): ?Author
{
return $this->reviewer;
}
/**
* @param Author|null $reviewer
* @return self
*/
public function setReviewer(?Author $reviewer): self
{
$this->reviewer = $reviewer;
return $this;
}
}