<?php
namespace App\Entity;
use App\Repository\LandingPageRepository;
use Cofondateur\SocleTechniqueBundle\Annotation\CrudField;
use Cofondateur\SocleTechniqueBundle\Traits\SEOInterface;
use Cofondateur\SocleTechniqueBundle\Traits\SEOTrait;
use Cofondateur\SocleTechniqueBundle\Traits\SluggableInterface;
use Cofondateur\SocleTechniqueBundle\Traits\SluggableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
use App\Form\LandingPageSectionFormType;
use App\Form\LandingPagePartnerFormType;
use App\Form\LandingPageFaqFormType;
/**
* @ORM\Entity(repositoryClass=LandingPageRepository::class)
* @Uploadable()
*/
class LandingPage implements SEOInterface, SluggableInterface
{
use SEOTrait;
use SluggableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(index=true, label="Titre (mettre entre étoiles pour rendre le titre avec le surlignage Exemple : 'ceci est en bleu *ceci est surligné*')")
*/
private string $title;
/**
* @ORM\Column(type="text")
* @CrudField(label="Description", ckeditor=true)
*/
private $description;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $coverName;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $coverSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $coverUpdatedAt;
/**
* @Vich\UploadableField(mapping="default", fileNameProperty="coverName", size="coverSize")
* @CrudField(label="Visuel principal (bandeau top)")
*/
private $coverFile;
/**
* @ORM\Column(type="string", nullable=true)
* @CrudField(label="Alt")
*/
private $coverAlt;
/**
* @ORM\Column(type="boolean")
* @CrudField(label="Publié", index=true)
*/
private bool $published = true;
/**
* @ORM\OneToMany(targetEntity=LandingPageSection::class, mappedBy="landingPage", cascade={"persist", "remove"}, orphanRemoval=true)
* @CrudField(label="Sections", formType=LandingPageSectionFormType::class, tab="Sections")
*/
private $sections;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Sur-titre", tab="Citation")
*/
private $citationOverTitle;
/**
* @ORM\Column(type="text", nullable=true)
* @CrudField(label="Citation (mettre entre étoiles pour rendre le titre avec le surlignage Exemple : 'ceci est en bleu *ceci est surligné*')", tab="Citation")
*/
private $citation;
/**
* @ORM\OneToMany(targetEntity=LandingPagePartner::class, mappedBy="landingPage", cascade={"persist", "remove"}, orphanRemoval=true)
* @CrudField(label="Partenaires", formType=LandingPagePartnerFormType::class, tab="Partenaires")
*/
private $partners;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Sur-titre de la section FAQ", tab="FAQ")
*/
private $faqOverTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Titre de la section FAQ", tab="FAQ")
*/
private $faqTitle;
/**
* @ORM\OneToMany(targetEntity=LandingPageFaq::class, mappedBy="landingPage", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
* @CrudField(label="Questions / Réponses", formType=LandingPageFaqFormType::class, tab="FAQ")
*/
private $faqItems;
public function isPublished(): bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function __construct()
{
$this->sections = new ArrayCollection();
$this->partners = new ArrayCollection();
$this->faqItems = new ArrayCollection();
$this->setCreatedAt(new \DateTimeImmutable());
}
public function __toString(): string
{
return (string) ($this->getId() ?? 'N/A');
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function getTitleWithoutStars(): ?string
{
return $this->title ? str_replace('*', '', $this->title) : null;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCoverName(): ?string
{
return $this->coverName;
}
public function setCoverName(?string $coverName): self
{
$this->coverName = $coverName;
return $this;
}
public function getCoverSize(): ?int
{
return $this->coverSize;
}
public function setCoverSize(?int $coverSize): self
{
$this->coverSize = $coverSize;
return $this;
}
public function getCoverUpdatedAt(): ?\DateTimeInterface
{
return $this->coverUpdatedAt;
}
public function setCoverUpdatedAt(?\DateTimeInterface $coverUpdatedAt): self
{
$this->coverUpdatedAt = $coverUpdatedAt;
return $this;
}
public function getCoverFile(): ?File
{
return $this->coverFile;
}
public function setCoverFile(?File $coverFile): self
{
$this->coverFile = $coverFile;
if (null !== $this->coverFile) {
$this->coverUpdatedAt = new \DateTimeImmutable();
}
return $this;
}
public function getCoverAlt(): ?string
{
return $this->coverAlt;
}
public function setCoverAlt(?string $coverAlt): self
{
$this->coverAlt = $coverAlt;
return $this;
}
/**
* @return Collection<int, LandingPageSection>
*/
public function getSections(): Collection
{
return $this->sections;
}
public function addSection(LandingPageSection $section): self
{
if (!$this->sections->contains($section)) {
$this->sections[] = $section;
$section->setLandingPage($this);
}
return $this;
}
public function removeSection(LandingPageSection $section): self
{
if ($this->sections->removeElement($section)) {
if ($section->getLandingPage() === $this) {
$section->setLandingPage(null);
}
}
return $this;
}
public function getCitationOverTitle(): ?string
{
return $this->citationOverTitle;
}
public function setCitationOverTitle(?string $citationOverTitle): self
{
$this->citationOverTitle = $citationOverTitle;
return $this;
}
public function getCitation(): ?string
{
return $this->citation;
}
public function setCitation(?string $citation): self
{
$this->citation = $citation;
return $this;
}
/**
* @return Collection<int, LandingPagePartner>
*/
public function getPartners(): Collection
{
return $this->partners;
}
public function addPartner(LandingPagePartner $partner): self
{
if (!$this->partners->contains($partner)) {
$this->partners[] = $partner;
$partner->setLandingPage($this);
}
return $this;
}
public function removePartner(LandingPagePartner $partner): self
{
if ($this->partners->removeElement($partner)) {
if ($partner->getLandingPage() === $this) {
$partner->setLandingPage(null);
}
}
return $this;
}
public function getFaqOverTitle(): ?string
{
return $this->faqOverTitle;
}
public function setFaqOverTitle(?string $faqOverTitle): self
{
$this->faqOverTitle = $faqOverTitle;
return $this;
}
public function getFaqTitle(): ?string
{
return $this->faqTitle;
}
public function setFaqTitle(?string $faqTitle): self
{
$this->faqTitle = $faqTitle;
return $this;
}
/**
* @return Collection<int, LandingPageFaq>
*/
public function getFaqItems(): Collection
{
return $this->faqItems;
}
public function addFaqItem(LandingPageFaq $faqItem): self
{
if (!$this->faqItems->contains($faqItem)) {
$this->faqItems[] = $faqItem;
$faqItem->setLandingPage($this);
}
return $this;
}
public function removeFaqItem(LandingPageFaq $faqItem): self
{
if ($this->faqItems->removeElement($faqItem)) {
if ($faqItem->getLandingPage() === $this) {
$faqItem->setLandingPage(null);
}
}
return $this;
}
}