<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PageRepository::class)]
class Page implements Translatable
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255, unique: true, nullable: false)]
#[Assert\NotBlank]
#[Assert\Length(min: 5, max: 50)]
#[Gedmo\Translatable]
private ?string $title = '';
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Gedmo\Translatable]
private ?string $subtitle;
#[ORM\Column(type: 'string', length: 255, unique: true)]
#[Gedmo\Slug(fields: ['title'])]
private ?string $slug;
#[ORM\Column(type: 'text', nullable: true)]
#[Gedmo\Translatable]
private ?string $content;
#[ORM\Column(type: 'boolean')]
private bool $online = false;
#[ORM\Column(type: 'integer', nullable: false)]
#[Assert\Positive]
private ?int $position;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private $parent;
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
private Collection $children;
#[ORM\OneToMany(mappedBy: 'page', targetEntity: Media::class)]
#[OrderBy(["position" => "ASC"])]
private $medias;
#[Gedmo\Locale]
private $locale;
public function __construct()
{
$this->children = new ArrayCollection();
$this->medias = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @param string $title
* @return $this
*/
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return string|null
*/
public function getSubtitle(): ?string
{
return $this->subtitle;
}
/**
* @param string|null $subtitle
* @return $this
*/
public function setSubtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
/**
* @return string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @param string $slug
* @return $this
*/
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return string|null
*/
public function getContent(): ?string
{
return $this->content;
}
/**
* @param string $content
* @return $this
*/
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
/**
* @return bool|null
*/
public function getOnline(): ?bool
{
return $this->online;
}
/**
* @param bool $online
* @return $this
*/
public function setOnline(bool $online): self
{
$this->online = $online;
return $this;
}
/**
* @return int|null
*/
public function getPosition(): ?int
{
return $this->position;
}
/**
* @param int $position
* @return $this
*/
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $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;
}
/**
* @return Collection<int, Media>
*/
public function getMedias(): Collection
{
return $this->medias;
}
public function addMedia(Media $media): self
{
if (!$this->medias->contains($media)) {
$this->medias[] = $media;
$media->setPage($this);
}
return $this;
}
public function removeMedia(Media $media): self
{
if ($this->medias->removeElement($media)) {
// set the owning side to null (unless already changed)
if ($media->getPage() === $this) {
$media->setPage(null);
}
}
return $this;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->title;
}
}