src/Entity/Page.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PageRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\OrderBy;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Gedmo\Translatable\Translatable;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassPageRepository::class)]
  13. class Page implements Translatable
  14. {
  15.     use TimestampableEntity;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private ?int $id null;
  20.     #[ORM\Column(type'string'length255uniquetruenullablefalse)]
  21.     #[Assert\NotBlank]
  22.     #[Assert\Length(min5max50)]
  23.     #[Gedmo\Translatable]
  24.     private ?string $title '';
  25.     #[ORM\Column(type'string'length255nullabletrue)]
  26.     #[Gedmo\Translatable]
  27.     private ?string $subtitle;
  28.     #[ORM\Column(type'string'length255uniquetrue)]
  29.     #[Gedmo\Slug(fields: ['title'])]
  30.     private ?string $slug;
  31.     #[ORM\Column(type'text'nullabletrue)]
  32.     #[Gedmo\Translatable]
  33.     private ?string $content;
  34.     #[ORM\Column(type'boolean')]
  35.     private bool $online false;
  36.     #[ORM\Column(type'integer'nullablefalse)]
  37.     #[Assert\Positive]
  38.     private ?int $position;
  39.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'children')]
  40.     private $parent;
  41.     #[ORM\OneToMany(targetEntityself::class, mappedBy'parent')]
  42.     private Collection $children;
  43.     #[ORM\OneToMany(mappedBy'page'targetEntityMedia::class)]
  44.     #[OrderBy(["position" => "ASC"])]
  45.     private $medias;
  46.     #[Gedmo\Locale]
  47.     private $locale;
  48.     public function __construct()
  49.     {
  50.         $this->children = new ArrayCollection();
  51.         $this->medias = new ArrayCollection();
  52.     }
  53.     public function setTranslatableLocale($locale)
  54.     {
  55.         $this->locale $locale;
  56.     }
  57.     /**
  58.      * @return int|null
  59.      */
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     /**
  65.      * @return string|null
  66.      */
  67.     public function getTitle(): ?string
  68.     {
  69.         return $this->title;
  70.     }
  71.     /**
  72.      * @param string $title
  73.      * @return $this
  74.      */
  75.     public function setTitle(string $title): self
  76.     {
  77.         $this->title $title;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return string|null
  82.      */
  83.     public function getSubtitle(): ?string
  84.     {
  85.         return $this->subtitle;
  86.     }
  87.     /**
  88.      * @param string|null $subtitle
  89.      * @return $this
  90.      */
  91.     public function setSubtitle(?string $subtitle): self
  92.     {
  93.         $this->subtitle $subtitle;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return string|null
  98.      */
  99.     public function getSlug(): ?string
  100.     {
  101.         return $this->slug;
  102.     }
  103.     /**
  104.      * @param string $slug
  105.      * @return $this
  106.      */
  107.     public function setSlug(string $slug): self
  108.     {
  109.         $this->slug $slug;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return string|null
  114.      */
  115.     public function getContent(): ?string
  116.     {
  117.         return $this->content;
  118.     }
  119.     /**
  120.      * @param string $content
  121.      * @return $this
  122.      */
  123.     public function setContent(string $content): self
  124.     {
  125.         $this->content $content;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return bool|null
  130.      */
  131.     public function getOnline(): ?bool
  132.     {
  133.         return $this->online;
  134.     }
  135.     /**
  136.      * @param bool $online
  137.      * @return $this
  138.      */
  139.     public function setOnline(bool $online): self
  140.     {
  141.         $this->online $online;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return int|null
  146.      */
  147.     public function getPosition(): ?int
  148.     {
  149.         return $this->position;
  150.     }
  151.     /**
  152.      * @param int $position
  153.      * @return $this
  154.      */
  155.     public function setPosition(int $position): self
  156.     {
  157.         $this->position $position;
  158.         return $this;
  159.     }
  160.     public function getParent(): ?self
  161.     {
  162.         return $this->parent;
  163.     }
  164.     public function setParent(?self $parent): self
  165.     {
  166.         $this->parent $parent;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection|self[]
  171.      */
  172.     public function getChildren(): Collection
  173.     {
  174.         return $this->children;
  175.     }
  176.     public function addChild(self $child): self
  177.     {
  178.         if (!$this->children->contains($child)) {
  179.             $this->children[] = $child;
  180.             $child->setParent($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeChild(self $child): self
  185.     {
  186.         if ($this->children->contains($child)) {
  187.             $this->children->removeElement($child);
  188.             // set the owning side to null (unless already changed)
  189.             if ($child->getParent() === $this) {
  190.                 $child->setParent(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection<int, Media>
  197.      */
  198.     public function getMedias(): Collection
  199.     {
  200.         return $this->medias;
  201.     }
  202.     public function addMedia(Media $media): self
  203.     {
  204.         if (!$this->medias->contains($media)) {
  205.             $this->medias[] = $media;
  206.             $media->setPage($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeMedia(Media $media): self
  211.     {
  212.         if ($this->medias->removeElement($media)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($media->getPage() === $this) {
  215.                 $media->setPage(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return string
  222.      */
  223.     public function __toString(): string
  224.     {
  225.         return $this->title;
  226.     }
  227. }