src/Entity/Page.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PageRepository::class)
  9.  * @UniqueEntity("uri")
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Page
  13. {
  14.     use RemoveImageTrait;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      * @Assert\NotBlank
  24.      */
  25.     private $title;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      * @Assert\NotBlank
  29.      */
  30.     private $uri;
  31.     /**
  32.      * @ORM\Column(type="text", nullable=true)
  33.      */
  34.     private $data;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=PageTemplate::class, inversedBy="pages")
  37.      * @ORM\JoinColumn(nullable=false)
  38.      * @Assert\NotBlank
  39.      */
  40.     private $template;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $updated;
  45.     /**
  46.      * @ORM\Column(type="boolean")
  47.      */
  48.     private $published false;
  49.     /**
  50.      * @ORM\Column(type="datetime", nullable=true)
  51.      */
  52.     private $created;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=true)
  55.      */
  56.     private $publishedDate;
  57.     /**
  58.      * @ORM\Column(type="json", nullable=true)
  59.      */
  60.     private $meta = [];
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $menuTitle;
  65.     /**
  66.      * @ORM\Column(type="integer")
  67.      */
  68.     private $menuPosition 0;
  69.     /**
  70.      * @ORM\Column(type="json")
  71.      */
  72.     private $extraFields = [];
  73.     /**
  74.      * @ORM\PostRemove()
  75.      */
  76.     public function postRemove()
  77.     {
  78.         $extraFields $this->getExtraFields();
  79.         if (!empty($extraFields['image'])) {
  80.             $this->removeImage($extraFields['image']);
  81.         }
  82.     }
  83.     public function __construct()
  84.     {
  85.         $this->setUpdated(new \DateTime());
  86.         $this->setCreated(new \DateTime());
  87.     }
  88.     public function getId(): ?int
  89.     {
  90.         return $this->id;
  91.     }
  92.     public function getTitle(): ?string
  93.     {
  94.         return $this->title;
  95.     }
  96.     public function setTitle(string $title): self
  97.     {
  98.         $this->title $title;
  99.         return $this;
  100.     }
  101.     public function getUri(): ?string
  102.     {
  103.         return $this->uri;
  104.     }
  105.     public function setUri(string $uri): self
  106.     {
  107.         $this->uri $uri;
  108.         return $this;
  109.     }
  110.     public function getData(): ?string
  111.     {
  112.         return $this->data;
  113.     }
  114.     public function setData(?string $data): self
  115.     {
  116.         $this->data $data;
  117.         return $this;
  118.     }
  119.     public function getTemplate(): ?PageTemplate
  120.     {
  121.         return $this->template;
  122.     }
  123.     public function setTemplate(?PageTemplate $template): self
  124.     {
  125.         $this->template $template;
  126.         return $this;
  127.     }
  128.     public function getUpdated(): ?\DateTimeInterface
  129.     {
  130.         return $this->updated;
  131.     }
  132.     public function setUpdated(\DateTimeInterface $updated): self
  133.     {
  134.         $this->updated $updated;
  135.         return $this;
  136.     }
  137.     public function getPublished(): ?bool
  138.     {
  139.         return $this->published;
  140.     }
  141.     public function setPublished(bool $published): self
  142.     {
  143.         $this->published $published;
  144.         return $this;
  145.     }
  146.     public function __toString(): string
  147.     {
  148.         return $this->getTitle();
  149.     }
  150.     public function getCreated(): ?\DateTimeInterface
  151.     {
  152.         return $this->created;
  153.     }
  154.     public function setCreated(\DateTimeInterface $created): self
  155.     {
  156.         $this->created $created;
  157.         return $this;
  158.     }
  159.     public function getPublishedDate(): ?\DateTimeInterface
  160.     {
  161.         return $this->publishedDate;
  162.     }
  163.     public function setPublishedDate(?\DateTimeInterface $publishedDate): self
  164.     {
  165.         $this->publishedDate $publishedDate ?? new \DateTime();
  166.         return $this;
  167.     }
  168.     public function getMeta(): ?array
  169.     {
  170.         return $this->meta;
  171.     }
  172.     public function setMeta(?array $meta): self
  173.     {
  174.         $this->meta $meta;
  175.         return $this;
  176.     }
  177.     public function getMenuTitle(): ?string
  178.     {
  179.         return $this->menuTitle;
  180.     }
  181.     public function setMenuTitle(?string $menuTitle): self
  182.     {
  183.         $this->menuTitle $menuTitle;
  184.         return $this;
  185.     }
  186.     public function getMenuPosition(): ?int
  187.     {
  188.         return $this->menuPosition;
  189.     }
  190.     public function setMenuPosition(int $menuPosition): self
  191.     {
  192.         $this->menuPosition $menuPosition;
  193.         return $this;
  194.     }
  195.     public function getExtraFields(): ?array
  196.     {
  197.         return $this->extraFields;
  198.     }
  199.     public function setExtraFields(array $extraFields): self
  200.     {
  201.         $this->extraFields $extraFields;
  202.         return $this;
  203.     }
  204. }