src/Entity/Component.php line 24

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of Symfony Keen Template Project.
  4.  * (c) 2021 One AM SRL
  5.  */
  6. namespace App\Entity;
  7. use App\Entity\Component\ComponentCallToAction;
  8. use App\Entity\Embeddable\File\CoverFile;
  9. use App\Repository\ComponentRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
  14. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  15. use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
  16. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\String\Slugger\AsciiSlugger;
  19. #[ORM\Entity(repositoryClassComponentRepository::class)]
  20. class Component implements SluggableInterfaceTimestampableInterface
  21. {
  22.     use TimestampableTrait;
  23.     use SluggableTrait;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     private $id;
  28.     #[ORM\Column(type'string'length255)]
  29.     #[Groups(['ajax'])]
  30.     private $name;
  31.     #[ORM\Column(type'text'nullabletrue)]
  32.     #[Groups(['ajax'])]
  33.     private $content;
  34.     #[ORM\Column(type'text'nullabletrue)]
  35.     #[Groups(['ajax'])]
  36.     private $introduction;
  37.     #[ORM\Column(type'boolean')]
  38.     #[Groups(['ajax'])]
  39.     private $visible;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     private $metaTitle;
  42.     #[ORM\Column(type'string'length255nullabletrue)]
  43.     private $metaDescription;
  44.     #[ORM\Embedded(class: CoverFile::class)]
  45.     #[Groups(['ajax'])]
  46.     private $cover;
  47.     #[ORM\Embedded(class: CoverFile::class)]
  48.     #[Groups(['ajax'])]
  49.     private $background;
  50.     #[ORM\OneToMany(mappedBy'component'targetEntityComponentCallToAction::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  51.     #[ORM\OrderBy(['position' => 'ASC'])]
  52.     private $componentCallToActions;
  53.     public function __construct()
  54.     {
  55.         $this->visible false;
  56.         $this->cover = new CoverFile();
  57.         $this->background = new CoverFile();
  58.         $this->componentCallToActions = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getName(): ?string
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName(string $name): self
  69.     {
  70.         $this->name $name;
  71.         return $this;
  72.     }
  73.     public function getContent(): ?string
  74.     {
  75.         return $this->content;
  76.     }
  77.     public function setContent(?string $content): self
  78.     {
  79.         $this->content $content;
  80.         return $this;
  81.     }
  82.     public function getIntroduction(): ?string
  83.     {
  84.         return $this->introduction;
  85.     }
  86.     public function setIntroduction(?string $introduction): self
  87.     {
  88.         $this->introduction $introduction;
  89.         return $this;
  90.     }
  91.     public function shouldGenerateUniqueSlugs(): bool
  92.     {
  93.         return true;
  94.     }
  95.     public function generateSlugValue($values): string
  96.     {
  97.         return (new AsciiSlugger())->slug($this->getName(), $this->getSlugDelimiter())->lower()->toString();
  98.     }
  99.     public function getSluggableFields(): array
  100.     {
  101.         return ['name'];
  102.     }
  103.     public function getMetaTitle(): ?string
  104.     {
  105.         return $this->metaTitle;
  106.     }
  107.     public function setMetaTitle(?string $metaTitle): self
  108.     {
  109.         $this->metaTitle $metaTitle;
  110.         return $this;
  111.     }
  112.     public function getMetaDescription(): ?string
  113.     {
  114.         return $this->metaDescription;
  115.     }
  116.     public function setMetaDescription(?string $metaDescription): self
  117.     {
  118.         $this->metaDescription $metaDescription;
  119.         return $this;
  120.     }
  121.     public function getCover(): ?CoverFile
  122.     {
  123.         return $this->cover;
  124.     }
  125.     public function setCover(?CoverFile $cover): self
  126.     {
  127.         $this->cover $cover;
  128.         return $this;
  129.     }
  130.     public function getBackground(): ?CoverFile
  131.     {
  132.         return $this->background;
  133.     }
  134.     public function setBackground(?CoverFile $background): self
  135.     {
  136.         $this->background $background;
  137.         return $this;
  138.     }
  139.     public function getVisible(): bool
  140.     {
  141.         return $this->visible;
  142.     }
  143.     public function setVisible(bool $visible): self
  144.     {
  145.         $this->visible $visible;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, ComponentCallToAction>
  150.      */
  151.     public function getComponentCallToActions(): Collection
  152.     {
  153.         return $this->componentCallToActions;
  154.     }
  155.     public function addComponentCallToAction(ComponentCallToAction $componentCallToAction): self
  156.     {
  157.         if (!$this->componentCallToActions->contains($componentCallToAction)) {
  158.             $this->componentCallToActions[] = $componentCallToAction;
  159.             $componentCallToAction->setComponent($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeComponentCallToAction(ComponentCallToAction $componentCallToAction): self
  164.     {
  165.         if ($this->componentCallToActions->removeElement($componentCallToAction)) {
  166.             // set the owning side to null (unless already changed)
  167.             if ($componentCallToAction->getComponent() === $this) {
  168.                 $componentCallToAction->setComponent(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173.     #[Groups(['ajax'])]
  174.     public function getCreatedAt(): \DateTimeInterface
  175.     {
  176.         return $this->createdAt;
  177.     }
  178.     public function __toString(): string
  179.     {
  180.         return $this->getName();
  181.     }
  182. }