src/Entity/StaticPage.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\CMS\CmsContentTrait;
  4. use App\Entity\Common\AnimationGroup;
  5. use App\Entity\EntityTrait\EntityBaseInformationTrait;
  6. use App\Entity\EntityTrait\EntityIdentityTrait;
  7. use App\Entity\EntityTrait\EntitySoftDeletableTrait;
  8. use App\Entity\EntityTrait\EntityTimestampableTrait;
  9. use App\Entity\EntityTrait\ImageTrait;
  10. use DateTimeImmutable;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. /**
  16.  * @ORM\Entity(repositoryClass="App\Repository\StaticPageRepository")
  17.  */
  18. class StaticPage
  19. {
  20.     use CmsContentTrait;
  21.     use EntityBaseInformationTrait;
  22.     use EntityIdentityTrait;
  23.     use EntitySoftDeletableTrait;
  24.     use EntityTimestampableTrait;
  25.     use ImageTrait;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity="App\Entity\Common\AnimationGroup", cascade={"persist", "remove"})
  28.      */
  29.     private $animationGroups;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity="App\Entity\StaticPage", mappedBy="parentPage", cascade={"persist", "remove"})
  32.      */
  33.     private $subPages;
  34.     
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity="App\Entity\StaticPage", inversedBy="subPages")
  37.      */
  38.     private $parentPage;
  39.     
  40.     /**
  41.      * @ORM\Column(type="string", nullable=true)
  42.      */
  43.     private $relativeUrl;
  44.     /**
  45.      * @ORM\Column(type="text", nullable=true)
  46.      */
  47.     private $shortDescription;
  48.     
  49.     public function __construct()
  50.     {
  51.         $this->animationGroups = new ArrayCollection();
  52.         $this->baseInformation = new BaseInformation();
  53.         $this->createdAt       = new DateTimeImmutable();
  54.         $this->updatedAt       = new DateTimeImmutable();
  55.         $this->subPages        = new ArrayCollection();
  56.     }
  57.     public function getAnimationGroups(): ?Collection
  58.     {
  59.         return $this->animationGroups;
  60.     }
  61.     public function setAnimationGroups(?Collection $animationGroups null): void
  62.     {
  63.         $this->animationGroups->clear();
  64.         $this->animationGroups $animationGroups;
  65.     }
  66.     public function addAnimationGroup(AnimationGroup $animationGroup): void
  67.     {
  68.         $this->animationGroups[] = $animationGroup;
  69.     }
  70.     public function removeAnimationGroup(AnimationGroup $animationGroup): void
  71.     {
  72.         $this->animationGroups->removeElement($animationGroup);
  73.     }
  74.     
  75.     public function getSubPages(): ?Collection
  76.     {
  77.         return $this->subPages;
  78.     }
  79.     
  80.     public function setSubPages(?Collection $subPages null): void
  81.     {
  82.         $subPages->removeElement($this);
  83.         
  84.         $this->subPages->clear();
  85.         
  86.         $this->subPages $subPages;
  87.         
  88.         foreach ($subPages as $subPage) {
  89.             if ($subPage->getParentPage() !== $this) {
  90.                 $subPage->setParentPage($this);
  91.             }
  92.         }
  93.     }
  94.     
  95.     public function addSubPage(StaticPage $subPage): void
  96.     {
  97.         if ($subPage !== $this) {
  98.             $this->subPages[] = $subPage;
  99.             
  100.             if ($subPage->getParentPage() !== $this) {
  101.                 $subPage->setParentPage($this);
  102.             }
  103.         }
  104.     }
  105.     
  106.     public function removeSubPage(StaticPage $subPage): void
  107.     {
  108.         $this->subPages->removeElement($subPage);
  109.     }
  110.     
  111.     public function getParentPage(): ?StaticPage
  112.     {
  113.         return $this->parentPage;
  114.     }
  115.     
  116.     public function setParentPage(?StaticPage  $parentPage null): void
  117.     {
  118.         $this->parentPage $parentPage;
  119.     }
  120.     public function setShortDescription(?string $shortDescription null): void
  121.     {
  122.         $this->shortDescription $shortDescription;
  123.     }
  124.     public function getShortDescription(): ?string
  125.     {
  126.         return $this->shortDescription;
  127.     }
  128.     
  129.     public function getRelativeUrl(): ?string
  130.     {
  131.         return $this->relativeUrl;
  132.     }
  133.     
  134.     public function setRelativeUrl(?string $relativeUrl null): void
  135.     {
  136.         $this->relativeUrl $relativeUrl;
  137.     }
  138.     public function getChilds (): ?Collection
  139.     {
  140.         return $this->subPages;
  141.     }
  142.     public function getBreadcrumbs() : ?array
  143.     {
  144.         $bread[$this->getBaseInformation()->getName()] = $this->getRelativeUrl();
  145.         if (!empty($this->getParentPage())) {
  146.             return array_merge($this->getParentPage()->getBreadcrumbs(), $bread);
  147.         }
  148.         return $bread;
  149.     }
  150. }