<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation\Slug;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\String\Slugger\AsciiSlugger;
use Symfony\Component\String\Slugger\SluggerInterface;
#[ORM\Entity(repositoryClass: PageRepository::class)]
class Page
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $titre = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $slug = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $contenu = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $contenuBrut = null;
#[ORM\ManyToMany(targetEntity: Tarif::class)]
#[ORM\OrderBy(['rang'=>'ASC'])]
private Collection $tarifs;
#[ORM\Column(length: 255, nullable: true)]
private ?string $banniere = null;
#[ORM\OneToMany(mappedBy: 'page', targetEntity: Section::class, cascade: ['persist'], fetch: "EAGER", orphanRemoval: true)]
private Collection $section;
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
private ?int $template = null;
public function __construct()
{
$this->tarifs = new ArrayCollection();
$this->sliders = new ArrayCollection();
$this->section = new ArrayCollection();
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug = null): self
{
if ($slug) {
$this->slug = $slug;
} else {
$slug = new AsciiSlugger();
$this->slug = strtolower($slug->slug($this->titre).'.html');
}
return $this;
}
public function getContenu(): ?string
{
return $this->contenu;
}
public function setContenu(string $contenu): self
{
$this->contenu = $contenu;
return $this;
}
public function getContenuBrut(): ?string
{
return $this->contenuBrut;
}
public function setContenuBrut(string $contenuBrut = null): self
{
if ($contenuBrut) {
$this->contenuBrut = $contenuBrut;
} else {
$this->contenuBrut = strip_tags($this->contenu);
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function isAccueil() :bool
{
if ($this->slug === 'index.html')
{
return true;
}
return false;
}
/**
* @return Collection<int, Tarif>
*/
public function getTarifs(): Collection
{
return $this->tarifs;
}
public function addTarif(Tarif $tarif): self
{
if (!$this->tarifs->contains($tarif)) {
$this->tarifs->add($tarif);
}
return $this;
}
public function setTarifs(array $tarifs): self
{
$this->tarifs = new ArrayCollection();
foreach ($tarifs as $tarif) {
$this->tarifs->add($tarif);
}
return $this;
}
public function removeTarif(Tarif $tarif): self
{
$this->tarifs->removeElement($tarif);
return $this;
}
/**
* @return Collection<int, Slider>
*/
public function getSliders(): Collection
{
return $this->sliders;
}
public function addSlider(Slider $slider): self
{
if (!$this->sliders->contains($slider)) {
$this->sliders->add($slider);
$slider->addPage($this);
}
return $this;
}
public function removeSlider(Slider $slider): self
{
if ($this->sliders->removeElement($slider)) {
$slider->removePage($this);
}
return $this;
}
public function getBanniere(): ?string
{
return $this->banniere;
}
public function setBanniere(?string $banniere): self
{
$this->banniere = $banniere;
return $this;
}
/**
* @return Collection<int, Section>
*/
public function getSection(): Collection
{
return $this->section;
}
public function addSection(Section $section): self
{
if (!$this->section->contains($section)) {
$this->section->add($section);
$section->setPage($this);
}
return $this;
}
public function removeSection(Section $section): self
{
if ($this->section->removeElement($section)) {
// set the owning side to null (unless already changed)
if ($section->getPage() === $this) {
$section->setPage(null);
}
}
return $this;
}
public function getTemplate(): ?int
{
return $this->template;
}
public function setTemplate(?int $template): self
{
$this->template = $template;
return $this;
}
}