vendor/boldr/cms-bundle/src/Entity/Page.php line 18

Open in your IDE?
  1. <?php
  2. namespace Boldr\Cms\CmsBundle\Entity;
  3. use Boldr\Cms\CmsBundle\Translation\TranslationCollection;
  4. use Boldr\Cms\CmsBundle\Permalink\PermalinkableInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\{ CollectionArrayCollection };
  7. use DateTimeImmutable;
  8. /**
  9.  * @ORM\Entity
  10.  * @ORM\Table(name="cms_page")
  11.  * @ORM\HasLifecycleCallbacks
  12.  */
  13. class Page implements AttachmentUserInterfacePermalinkableInterface
  14. {
  15.     use Traits\AttachmentUserTrait;
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\Column(type="integer", options={"unsigned": true})
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     private ?int $id null;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=self::class)
  24.      */
  25.     private ?Page $parent null;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity=PageTranslation::class, mappedBy="page", cascade={"persist", "remove"}, orphanRemoval=true)
  28.      * @var Collection<int, PageTranslation>
  29.      */
  30.     private Collection $translations;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=PageAttachmentUsage::class, mappedBy="page", fetch="EXTRA_LAZY", cascade={"persist", "remove"}, orphanRemoval=true)
  33.      * @var Collection<int, AttachmentUsage>
  34.      */
  35.     private Collection $attachmentUsages;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity=Upload::class)
  38.      */
  39.     private ?Upload $primaryImage null;
  40.     /**
  41.      * @ORM\Column(type="string", length="50", options={"default": "default"})
  42.      */
  43.     private string $layout 'default';
  44.     /**
  45.      * @ORM\Column(type="text", nullable=true)
  46.      */
  47.     private ?string $serializedLayout null;
  48.     /**
  49.      * @ORM\Column(type="datetime_immutable", options={"default": "CURRENT_TIMESTAMP"})
  50.      */
  51.     private DateTimeImmutable $timeLastUpdated;
  52.     /**
  53.      * @ORM\Column(type="boolean", options={"default": false})
  54.      */
  55.     private bool $synchronizeTranslations true;
  56.     public function __construct()
  57.     {
  58.         $this->translations = new ArrayCollection;
  59.         $this->attachmentUsages = new ArrayCollection;
  60.         $this->timeLastUpdated = new DateTimeImmutable;
  61.     }
  62.     /**
  63.      * @ORM\Column(type="string", nullable=true)
  64.      */
  65.     private ?string $type null;
  66.     public function getId(): ?int { return $this->id; }
  67.     public function getParent(): ?Page { return $this->parent; }
  68.     public function setParent(?Page $parent): void
  69.     {
  70.         $p $parent;
  71.         while ($p !== null)
  72.         {
  73.             if ($p === $this)
  74.             {
  75.                 throw new \Exception('Cannot set parent (to child) of self');
  76.             }
  77.             $p $p->getParent();
  78.         }
  79.         $this->parent $parent;
  80.     }
  81.     public function getPrimaryImage(): ?Upload { return $this->primaryImage; }
  82.     public function setPrimaryImage(?Upload $primaryImage): void $this->primaryImage $primaryImage; }
  83.     public function getSerializedLayout(): ?string { return $this->serializedLayout; }
  84.     public function setSerializedLayout(?string $serializedLayout): void $this->serializedLayout $serializedLayout; }
  85.     public function getType(): ?string { return $this->type; }
  86.     public function setType(?string $type): void $this->type $type; }
  87.     /**
  88.      * @return TranslationCollection<PageTranslation>
  89.      */
  90.     public function getTranslations(): TranslationCollection
  91.     {
  92.         return new TranslationCollection($this$this->translationsPageTranslation::class);
  93.     }
  94.     public function updateAttachmentSearchTexts(): void
  95.     {
  96.         // Set the search text to all translations of the title
  97.         $searchText '';
  98.         foreach ($this->translations as $translation)
  99.         {
  100.             $searchText .= $translation->getTitle() . ' ';
  101.         }
  102.         foreach ($this->attachmentUsages as $attachmentUsage)
  103.         {
  104.             $attachmentUsage->setSearchText($searchText);
  105.         }
  106.     }
  107.     public function createAttachmentUsage(Upload $upload): AttachmentUsage
  108.     {
  109.         return new PageAttachmentUsage($upload$this);
  110.     }
  111.     /**
  112.      * @ORM\PreUpdate
  113.      * @ORM\PrePersist
  114.      */
  115.     public function removeEmptyTranslations(): void
  116.     {
  117.         $this->getTranslations()->removeEmptyTranslations();
  118.     }
  119.     /**
  120.      * @return Collection<int, AttachmentUsage>
  121.      */
  122.     public function getAttachmentUsages(): Collection { return $this->attachmentUsages; }
  123.     public function getLayout(): string { return $this->layout; }
  124.     public function setLayout(string $layout): void $this->layout $layout; }
  125.     public function getTimeLastUpdated(): DateTimeImmutable { return $this->timeLastUpdated; }
  126.     public function setTimeLastUpdated(DateTimeImmutable $timeLastUpdated): void $this->timeLastUpdated $timeLastUpdated; }
  127.     public function getSynchronizeTranslations(): bool { return $this->synchronizeTranslations; }
  128.     public function setSynchronizeTranslations(bool $synchronizeTranslations): void $this->synchronizeTranslations $synchronizeTranslations; }
  129.     /**
  130.      * @deprecated
  131.      */
  132.     public function getPublished(): bool { return true; }
  133.     /**
  134.      * @deprecated
  135.      */
  136.     public function setPublished(bool $published): void { }
  137. }