<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=PageRepository::class)
* @UniqueEntity("uri")
* @ORM\HasLifecycleCallbacks()
*/
class Page
{
use RemoveImageTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
*/
private $uri;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $data;
/**
* @ORM\ManyToOne(targetEntity=PageTemplate::class, inversedBy="pages")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank
*/
private $template;
/**
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @ORM\Column(type="boolean")
*/
private $published = false;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publishedDate;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $meta = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $menuTitle;
/**
* @ORM\Column(type="integer")
*/
private $menuPosition = 0;
/**
* @ORM\Column(type="json")
*/
private $extraFields = [];
/**
* @ORM\PostRemove()
*/
public function postRemove()
{
$extraFields = $this->getExtraFields();
if (!empty($extraFields['image'])) {
$this->removeImage($extraFields['image']);
}
}
public function __construct()
{
$this->setUpdated(new \DateTime());
$this->setCreated(new \DateTime());
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getUri(): ?string
{
return $this->uri;
}
public function setUri(string $uri): self
{
$this->uri = $uri;
return $this;
}
public function getData(): ?string
{
return $this->data;
}
public function setData(?string $data): self
{
$this->data = $data;
return $this;
}
public function getTemplate(): ?PageTemplate
{
return $this->template;
}
public function setTemplate(?PageTemplate $template): self
{
$this->template = $template;
return $this;
}
public function getUpdated(): ?\DateTimeInterface
{
return $this->updated;
}
public function setUpdated(\DateTimeInterface $updated): self
{
$this->updated = $updated;
return $this;
}
public function getPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function __toString(): string
{
return $this->getTitle();
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getPublishedDate(): ?\DateTimeInterface
{
return $this->publishedDate;
}
public function setPublishedDate(?\DateTimeInterface $publishedDate): self
{
$this->publishedDate = $publishedDate ?? new \DateTime();
return $this;
}
public function getMeta(): ?array
{
return $this->meta;
}
public function setMeta(?array $meta): self
{
$this->meta = $meta;
return $this;
}
public function getMenuTitle(): ?string
{
return $this->menuTitle;
}
public function setMenuTitle(?string $menuTitle): self
{
$this->menuTitle = $menuTitle;
return $this;
}
public function getMenuPosition(): ?int
{
return $this->menuPosition;
}
public function setMenuPosition(int $menuPosition): self
{
$this->menuPosition = $menuPosition;
return $this;
}
public function getExtraFields(): ?array
{
return $this->extraFields;
}
public function setExtraFields(array $extraFields): self
{
$this->extraFields = $extraFields;
return $this;
}
}