src/Entity/Page.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\Embeddable\File\CoverFile;
  8. use App\Entity\Page\PageCallToAction;
  9. use App\Repository\PageRepository;
  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(repositoryClassPageRepository::class)]
  20. class Page 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')]
  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'page'targetEntityPageCallToAction::class, cascade: ['persist'])]
  51.     #[ORM\OrderBy(['position' => 'ASC'])]
  52.     private $pageCallToActions;
  53.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'pages')]
  54.     #[ORM\JoinColumn(nullablefalse)]
  55.     #[Groups(['ajax'])]
  56.     private $product;
  57.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'children')]
  58.     private $parent;
  59.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  60.     private $children;
  61.     public function __construct()
  62.     {
  63.         $this->visible false;
  64.         $this->cover = new CoverFile();
  65.         $this->pageCallToActions = new ArrayCollection();
  66.         $this->children = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getName(): ?string
  73.     {
  74.         return $this->name;
  75.     }
  76.     public function setName(string $name): self
  77.     {
  78.         $this->name $name;
  79.         return $this;
  80.     }
  81.     public function getContent(): ?string
  82.     {
  83.         return $this->content;
  84.     }
  85.     public function setContent(?string $content): self
  86.     {
  87.         $this->content $content;
  88.         return $this;
  89.     }
  90.     public function getIntroduction(): ?string
  91.     {
  92.         return $this->introduction;
  93.     }
  94.     public function setIntroduction(?string $introduction): self
  95.     {
  96.         $this->introduction $introduction;
  97.         return $this;
  98.     }
  99.     public function shouldGenerateUniqueSlugs(): bool
  100.     {
  101.         return true;
  102.     }
  103.     public function generateSlugValue($values): string
  104.     {
  105.         if ($this->getParent()) {
  106.             return
  107.                 (new AsciiSlugger())->slug($this->getParent()->getName(), $this->getSlugDelimiter())->lower()->toString().'/'.
  108.                 (new AsciiSlugger())->slug($this->getName(), $this->getSlugDelimiter())->lower()->toString()
  109.                 ;
  110.         }
  111.         return (new AsciiSlugger())->slug($this->getName(), $this->getSlugDelimiter())->lower()->toString();
  112.     }
  113.     public function getSluggableFields(): array
  114.     {
  115.         return ['name'];
  116.     }
  117.     public function getMetaTitle(): ?string
  118.     {
  119.         return $this->metaTitle;
  120.     }
  121.     public function setMetaTitle(?string $metaTitle): self
  122.     {
  123.         $this->metaTitle $metaTitle;
  124.         return $this;
  125.     }
  126.     public function getMetaDescription(): ?string
  127.     {
  128.         return $this->metaDescription;
  129.     }
  130.     public function setMetaDescription(?string $metaDescription): self
  131.     {
  132.         $this->metaDescription $metaDescription;
  133.         return $this;
  134.     }
  135.     public function getCover(): ?CoverFile
  136.     {
  137.         return $this->cover;
  138.     }
  139.     public function setCover(?CoverFile $cover): self
  140.     {
  141.         $this->cover $cover;
  142.         return $this;
  143.     }
  144.     public function getBackground(): ?CoverFile
  145.     {
  146.         return $this->background;
  147.     }
  148.     public function setBackground(?CoverFile $background): self
  149.     {
  150.         $this->background $background;
  151.         return $this;
  152.     }
  153.     public function getVisible(): bool
  154.     {
  155.         return $this->visible;
  156.     }
  157.     public function setVisible(bool $visible): self
  158.     {
  159.         $this->visible $visible;
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection<int, PageCallToAction>
  164.      */
  165.     public function getPageCallToActions(): Collection
  166.     {
  167.         return $this->pageCallToActions;
  168.     }
  169.     public function addPageCallToAction(PageCallToAction $pageCallToAction): self
  170.     {
  171.         if (!$this->pageCallToActions->contains($pageCallToAction)) {
  172.             $this->pageCallToActions[] = $pageCallToAction;
  173.             $pageCallToAction->setPage($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removePageCallToAction(PageCallToAction $pageCallToAction): self
  178.     {
  179.         if ($this->pageCallToActions->removeElement($pageCallToAction)) {
  180.             // set the owning side to null (unless already changed)
  181.             if ($pageCallToAction->getPage() === $this) {
  182.                 $pageCallToAction->setPage(null);
  183.             }
  184.         }
  185.         return $this;
  186.     }
  187.     public function getProduct(): ?Product
  188.     {
  189.         return $this->product;
  190.     }
  191.     public function setProduct(?Product $product): self
  192.     {
  193.         $this->product $product;
  194.         return $this;
  195.     }
  196.     #[Groups(['ajax'])]
  197.     public function getCreatedAt(): \DateTimeInterface
  198.     {
  199.         return $this->createdAt;
  200.     }
  201.     public function __toString(): string
  202.     {
  203.         return $this->getName();
  204.     }
  205.     public function getParent(): ?self
  206.     {
  207.         return $this->parent;
  208.     }
  209.     public function setParent(?self $parent): self
  210.     {
  211.         $this->parent $parent;
  212.         return $this;
  213.     }
  214.     /**
  215.      * @return Collection<int, self>
  216.      */
  217.     public function getChildren(): Collection
  218.     {
  219.         return $this->children;
  220.     }
  221.     public function addChild(self $child): self
  222.     {
  223.         if (!$this->children->contains($child)) {
  224.             $this->children[] = $child;
  225.             $child->setParent($this);
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeChild(self $child): self
  230.     {
  231.         if ($this->children->removeElement($child)) {
  232.             // set the owning side to null (unless already changed)
  233.             if ($child->getParent() === $this) {
  234.                 $child->setParent(null);
  235.             }
  236.         }
  237.         return $this;
  238.     }
  239. }