<?php
namespace App\CMSBundle\Entity;
use App\CMSBundle\Entity\Translation\DynamicPageTranslation;
use App\ContentBundle\Entity\Post;
use App\SeoBundle\Entity\Seo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;
use PN\LocaleBundle\Model\LocaleTrait;
use PN\LocaleBundle\Model\Translatable;
use PN\ServiceBundle\Interfaces\DateTimeInterface;
use PN\ServiceBundle\Model\DateTimeTrait;
/**
* @ORM\Table(name="dynamic_page")
* @ORM\Entity(repositoryClass="App\CMSBundle\Repository\DynamicPageRepository")
*/
class DynamicPage implements Translatable, DateTimeInterface
{
use DateTimeTrait,
LocaleTrait;
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @ORM\OneToOne(targetEntity="\App\SeoBundle\Entity\Seo", cascade={"persist", "remove" })
*/
private ?Seo $seo = null;
/**
* @ORM\OneToOne(targetEntity="App\ContentBundle\Entity\Post", cascade={"persist", "remove" })
*/
private ?Post $post = null;
/**
* @ORM\Column(name="title", type="string", length=255)
*/
private ?string $title = null;
/**
* @ORM\OneToMany(targetEntity="App\CMSBundle\Entity\Translation\DynamicPageTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
*/
private Collection $translations;
/**
* Constructor
*/
#[Pure] public function __construct()
{
$this->translations = new ArrayCollection();
}
public function getTitle(): ?string
{
return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
}
public function getId(): ?int
{
return $this->id;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSeo(): ?Seo
{
return $this->seo;
}
public function setSeo(?Seo $seo): self
{
$this->seo = $seo;
return $this;
}
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): self
{
$this->post = $post;
return $this;
}
/**
* @return Collection<int, DynamicPageTranslation>
*/
public function getTranslations(): Collection
{
return $this->translations;
}
public function addTranslation(DynamicPageTranslation $translation): self
{
if (!$this->translations->contains($translation)) {
$this->translations->add($translation);
$translation->setTranslatable($this);
}
return $this;
}
public function removeTranslation(DynamicPageTranslation $translation): self
{
if ($this->translations->removeElement($translation)) {
// set the owning side to null (unless already changed)
if ($translation->getTranslatable() === $this) {
$translation->setTranslatable(null);
}
}
return $this;
}
}