<?php
namespace App\Entity;
use App\Entity\Translation\Page as Translation;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatableTrait;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Table(name="page", indexes={@ORM\Index(name="idx_page_slug", columns={"slug"})})
* @Gedmo\Tree(type="nested")
* @Gedmo\TranslationEntity(class="App\Entity\Translation\Page")
* @Vich\Uploadable
* @ORM\Entity(repositoryClass="App\Repository\PageRepository")
*/
class Page
{
use PersonalTranslatableTrait;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\Translation\Page",
* mappedBy="object",
* cascade={"persist", "remove"}
* )
*/
protected $translations;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(name="id", type="integer")
*/
private $id;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
*/
private $uniqueTitle;
/**
* @Gedmo\TreeLeft
* @ORM\Column(name="lft", type="integer", nullable=true)
*/
private $lft;
/**
* @Gedmo\TreeRight
* @ORM\Column(name="rgt", type="integer", nullable=true)
*/
private $rgt;
/**
* @Gedmo\TreeLevel
* @ORM\Column(name="lvl", type="integer", nullable=true)
*/
private $lvl;
/**
* @Gedmo\TreeRoot
* @ORM\Column(name="root", type="integer")
*/
private $root;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $parent;
/**
* @ORM\Column(name="parent_id", type="integer", nullable=true)
*/
private $parentId;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
*/
private $children;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $intro;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $content;
/**
* @ORM\Column(name="headerType", type="integer", options={"default" : 1})
*/
private $headerType = 1;
/**
* @Assert\Image(
* maxSize = "1024768",
* allowPortrait = true
* )
* @Vich\UploadableField(mapping="page_image", fileNameProperty="imageName")
*
* @var File
*/
private $image;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $imageName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaKeywords;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaDescription;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $active;
/**
* @var datetime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime", options={"default" : "CURRENT_TIMESTAMP"})
*/
private $createdAt;
/**
* @var datetime
*
* @ORM\Column(type="datetime", options={"default" : "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $contentEng;
/**
* @ORM\Column(type="string", length=255)
*/
private $titleEng;
/**
* Constructor.
*/
public function __construct()
{
$this->children = new ArrayCollection();
$this->translations = new ArrayCollection();
}
public function __toString()
{
return '' != $this->title ? $this->title : 'New Page';
}
public function isDescendantOfOrEqualTo($page)
{
return ($this->lft >= $page->getLft())
&& ($this->rgt <= $page->getRgt())
&& ($this->root == $page->getRoot());
}
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getIntro(): ?string
{
return $this->intro;
}
public function setIntro(?string $intro): self
{
$this->intro = $intro;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImage(?File $image = null): void
{
$this->image = $image;
if (null !== $image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImage(): ?File
{
return $this->image;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): self
{
$this->imageName = $imageName;
return $this;
}
public function getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(?string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaKeywords(): ?string
{
return $this->metaKeywords;
}
public function setMetaKeywords(?string $metaKeywords): self
{
$this->metaKeywords = $metaKeywords;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
public function setMetaDescription(?string $metaDescription): self
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getLft(): ?int
{
return $this->lft;
}
public function setLft(?int $lft): self
{
$this->lft = $lft;
return $this;
}
public function getRgt(): ?int
{
return $this->rgt;
}
public function setRgt(?int $rgt): self
{
$this->rgt = $rgt;
return $this;
}
public function getLvl(): ?int
{
return $this->lvl;
}
public function setLvl(?int $lvl): self
{
$this->lvl = $lvl;
return $this;
}
public function getRoot(): ?int
{
return $this->root;
}
public function setRoot(int $root): self
{
$this->root = $root;
return $this;
}
public function getParentId(): ?int
{
return $this->parentId;
}
public function setParentId(?int $parentId): self
{
$this->parentId = $parentId;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|Page[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Page $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(Page $child): self
{
if ($this->children->contains($child)) {
$this->children->removeElement($child);
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getUniqueTitle(): ?string
{
return $this->uniqueTitle;
}
public function setUniqueTitle(string $uniqueTitle): self
{
$this->uniqueTitle = $uniqueTitle;
return $this;
}
/**
* @return Collection|Translation[]
*/
public function getTranslations(): Collection
{
return $this->translations;
}
public function addTranslation(Translation $translation): self
{
if (!$this->translations->contains($translation)) {
$this->translations[] = $translation;
$translation->setObject($this);
}
return $this;
}
public function removeTranslation(Translation $translation): self
{
if ($this->translations->contains($translation)) {
$this->translations->removeElement($translation);
// set the owning side to null (unless already changed)
if ($translation->getObject() === $this) {
$translation->setObject(null);
}
}
return $this;
}
public function getHeaderType(): ?int
{
return $this->headerType;
}
public function setHeaderType(int $headerType): self
{
$this->headerType = $headerType;
return $this;
}
public function getContentEng(): ?string
{
return $this->contentEng;
}
public function setContentEng(?string $contentEng): self
{
$this->contentEng = contentEng;
return $this;
}
public function getTitleEng(): ?string
{
return $this->titleEng;
}
public function setTitleEng(string $titleEng): self
{
$this->titleEng = titleEng;
return $this;
}
}