<?php
/**
* This file is part of Symfony Keen Template Project.
* (c) 2021 One AM SRL
*/
namespace App\Entity;
use App\Entity\Component\ComponentCallToAction;
use App\Entity\Embeddable\File\CoverFile;
use App\Repository\ComponentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\String\Slugger\AsciiSlugger;
#[ORM\Entity(repositoryClass: ComponentRepository::class)]
class Component implements SluggableInterface, TimestampableInterface
{
use TimestampableTrait;
use SluggableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['ajax'])]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['ajax'])]
private $content;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['ajax'])]
private $introduction;
#[ORM\Column(type: 'boolean')]
#[Groups(['ajax'])]
private $visible;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $metaTitle;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $metaDescription;
#[ORM\Embedded(class: CoverFile::class)]
#[Groups(['ajax'])]
private $cover;
#[ORM\Embedded(class: CoverFile::class)]
#[Groups(['ajax'])]
private $background;
#[ORM\OneToMany(mappedBy: 'component', targetEntity: ComponentCallToAction::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['position' => 'ASC'])]
private $componentCallToActions;
public function __construct()
{
$this->visible = false;
$this->cover = new CoverFile();
$this->background = new CoverFile();
$this->componentCallToActions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getIntroduction(): ?string
{
return $this->introduction;
}
public function setIntroduction(?string $introduction): self
{
$this->introduction = $introduction;
return $this;
}
public function shouldGenerateUniqueSlugs(): bool
{
return true;
}
public function generateSlugValue($values): string
{
return (new AsciiSlugger())->slug($this->getName(), $this->getSlugDelimiter())->lower()->toString();
}
public function getSluggableFields(): array
{
return ['name'];
}
public function getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(?string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
public function setMetaDescription(?string $metaDescription): self
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getCover(): ?CoverFile
{
return $this->cover;
}
public function setCover(?CoverFile $cover): self
{
$this->cover = $cover;
return $this;
}
public function getBackground(): ?CoverFile
{
return $this->background;
}
public function setBackground(?CoverFile $background): self
{
$this->background = $background;
return $this;
}
public function getVisible(): bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
/**
* @return Collection<int, ComponentCallToAction>
*/
public function getComponentCallToActions(): Collection
{
return $this->componentCallToActions;
}
public function addComponentCallToAction(ComponentCallToAction $componentCallToAction): self
{
if (!$this->componentCallToActions->contains($componentCallToAction)) {
$this->componentCallToActions[] = $componentCallToAction;
$componentCallToAction->setComponent($this);
}
return $this;
}
public function removeComponentCallToAction(ComponentCallToAction $componentCallToAction): self
{
if ($this->componentCallToActions->removeElement($componentCallToAction)) {
// set the owning side to null (unless already changed)
if ($componentCallToAction->getComponent() === $this) {
$componentCallToAction->setComponent(null);
}
}
return $this;
}
#[Groups(['ajax'])]
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
public function __toString(): string
{
return $this->getName();
}
}