src/Entity/Page.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Translation\Page as Translation;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatableTrait;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Table(name="page", indexes={@ORM\Index(name="idx_page_slug", columns={"slug"})})
  15.  * @Gedmo\Tree(type="nested")
  16.  * @Gedmo\TranslationEntity(class="App\Entity\Translation\Page")
  17.  * @Vich\Uploadable
  18.  * @ORM\Entity(repositoryClass="App\Repository\PageRepository")
  19.  */
  20. class Page
  21. {
  22.     use PersonalTranslatableTrait;
  23.     /**
  24.      * @var ArrayCollection
  25.      *
  26.      * @ORM\OneToMany(
  27.      *     targetEntity="App\Entity\Translation\Page",
  28.      *     mappedBy="object",
  29.      *     cascade={"persist", "remove"}
  30.      * )
  31.      */
  32.     protected $translations;
  33.     /**
  34.      * @ORM\Id()
  35.      * @ORM\GeneratedValue()
  36.      * @ORM\Column(name="id", type="integer")
  37.      */
  38.     private $id;
  39.     /**
  40.      * @Gedmo\Translatable
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $name;
  44.     /**
  45.      * @Gedmo\Translatable
  46.      * @ORM\Column(type="string", length=255)
  47.      */
  48.     private $title;
  49.     /**
  50.      * @ORM\Column(type="string", length=255)
  51.      */
  52.     private $uniqueTitle;
  53.     /**
  54.      * @Gedmo\TreeLeft
  55.      * @ORM\Column(name="lft", type="integer", nullable=true)
  56.      */
  57.     private $lft;
  58.     /**
  59.      * @Gedmo\TreeRight
  60.      * @ORM\Column(name="rgt", type="integer", nullable=true)
  61.      */
  62.     private $rgt;
  63.     /**
  64.      * @Gedmo\TreeLevel
  65.      * @ORM\Column(name="lvl", type="integer", nullable=true)
  66.      */
  67.     private $lvl;
  68.     /**
  69.      * @Gedmo\TreeRoot
  70.      * @ORM\Column(name="root", type="integer")
  71.      */
  72.     private $root;
  73.     /**
  74.      * @Gedmo\TreeParent
  75.      * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
  76.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
  77.      */
  78.     private $parent;
  79.     /**
  80.      * @ORM\Column(name="parent_id", type="integer", nullable=true)
  81.      */
  82.     private $parentId;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
  85.      */
  86.     private $children;
  87.     /**
  88.      * @Gedmo\Slug(fields={"name"})
  89.      * @ORM\Column(length=128, unique=true)
  90.      */
  91.     private $slug;
  92.     /**
  93.      * @ORM\Column(type="text", nullable=true)
  94.      */
  95.     private $intro;
  96.     /**
  97.      * @ORM\Column(type="text", nullable=true)
  98.      */
  99.     private $content;
  100.     /**
  101.      * @ORM\Column(name="headerType", type="integer", options={"default" : 1})
  102.      */
  103.     private $headerType 1;
  104.     /**
  105.      * @Assert\Image(
  106.      *     maxSize = "1024768",
  107.      *     allowPortrait = true
  108.      * )
  109.      * @Vich\UploadableField(mapping="page_image", fileNameProperty="imageName")
  110.      *
  111.      * @var File
  112.      */
  113.     private $image;
  114.     /**
  115.      * @ORM\Column(type="string", length=255, nullable=true)
  116.      */
  117.     private $imageName;
  118.     /**
  119.      * @ORM\Column(type="string", length=255, nullable=true)
  120.      */
  121.     private $metaTitle;
  122.     /**
  123.      * @ORM\Column(type="string", length=255, nullable=true)
  124.      */
  125.     private $metaKeywords;
  126.     /**
  127.      * @ORM\Column(type="string", length=255, nullable=true)
  128.      */
  129.     private $metaDescription;
  130.     /**
  131.      * @ORM\Column(type="boolean", nullable=true)
  132.      */
  133.     private $active;
  134.     /**
  135.      * @var datetime
  136.      *
  137.      * @Gedmo\Timestampable(on="create")
  138.      * @ORM\Column(type="datetime", options={"default" : "CURRENT_TIMESTAMP"})
  139.      */
  140.     private $createdAt;
  141.     /**
  142.      * @var datetime
  143.      *
  144.      * @ORM\Column(type="datetime", options={"default" : "CURRENT_TIMESTAMP"})
  145.      * @Gedmo\Timestampable(on="update")
  146.      */
  147.     private $updatedAt;
  148.     
  149.     /**
  150.      * @ORM\Column(type="text", nullable=true)
  151.      */
  152.     private $contentEng;
  153.     
  154.     /**
  155.      * @ORM\Column(type="string", length=255)
  156.      */
  157.     private $titleEng;
  158.     /**
  159.      * Constructor.
  160.      */
  161.     public function __construct()
  162.     {
  163.         $this->children = new ArrayCollection();
  164.         $this->translations = new ArrayCollection();
  165.     }
  166.     public function __toString()
  167.     {
  168.         return '' != $this->title $this->title 'New Page';
  169.     }
  170.     public function isDescendantOfOrEqualTo($page)
  171.     {
  172.         return ($this->lft >= $page->getLft())
  173.                 && ($this->rgt <= $page->getRgt())
  174.                 && ($this->root == $page->getRoot());
  175.     }
  176.     public function getId()
  177.     {
  178.         return $this->id;
  179.     }
  180.     public function getName(): ?string
  181.     {
  182.         return $this->name;
  183.     }
  184.     public function setName(string $name): self
  185.     {
  186.         $this->name $name;
  187.         return $this;
  188.     }
  189.     public function getTitle(): ?string
  190.     {
  191.         return $this->title;
  192.     }
  193.     public function setTitle(string $title): self
  194.     {
  195.         $this->title $title;
  196.         return $this;
  197.     }
  198.     public function getSlug(): ?string
  199.     {
  200.         return $this->slug;
  201.     }
  202.     public function setSlug(string $slug): self
  203.     {
  204.         $this->slug $slug;
  205.         return $this;
  206.     }
  207.     public function getIntro(): ?string
  208.     {
  209.         return $this->intro;
  210.     }
  211.     public function setIntro(?string $intro): self
  212.     {
  213.         $this->intro $intro;
  214.         return $this;
  215.     }
  216.     public function getContent(): ?string
  217.     {
  218.         return $this->content;
  219.     }
  220.     public function setContent(?string $content): self
  221.     {
  222.         $this->content $content;
  223.         return $this;
  224.     }
  225.     /**
  226.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  227.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  228.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  229.      * must be able to accept an instance of 'File' as the bundle will inject one here
  230.      * during Doctrine hydration.
  231.      *
  232.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  233.      */
  234.     public function setImage(?File $image null): void
  235.     {
  236.         $this->image $image;
  237.         if (null !== $image) {
  238.             // It is required that at least one field changes if you are using doctrine
  239.             // otherwise the event listeners won't be called and the file is lost
  240.             $this->updatedAt = new \DateTimeImmutable();
  241.         }
  242.     }
  243.     public function getImage(): ?File
  244.     {
  245.         return $this->image;
  246.     }
  247.     public function getImageName(): ?string
  248.     {
  249.         return $this->imageName;
  250.     }
  251.     public function setImageName(?string $imageName): self
  252.     {
  253.         $this->imageName $imageName;
  254.         return $this;
  255.     }
  256.     public function getMetaTitle(): ?string
  257.     {
  258.         return $this->metaTitle;
  259.     }
  260.     public function setMetaTitle(?string $metaTitle): self
  261.     {
  262.         $this->metaTitle $metaTitle;
  263.         return $this;
  264.     }
  265.     public function getMetaKeywords(): ?string
  266.     {
  267.         return $this->metaKeywords;
  268.     }
  269.     public function setMetaKeywords(?string $metaKeywords): self
  270.     {
  271.         $this->metaKeywords $metaKeywords;
  272.         return $this;
  273.     }
  274.     public function getMetaDescription(): ?string
  275.     {
  276.         return $this->metaDescription;
  277.     }
  278.     public function setMetaDescription(?string $metaDescription): self
  279.     {
  280.         $this->metaDescription $metaDescription;
  281.         return $this;
  282.     }
  283.     public function getActive(): ?bool
  284.     {
  285.         return $this->active;
  286.     }
  287.     public function setActive(?bool $active): self
  288.     {
  289.         $this->active $active;
  290.         return $this;
  291.     }
  292.     public function getLft(): ?int
  293.     {
  294.         return $this->lft;
  295.     }
  296.     public function setLft(?int $lft): self
  297.     {
  298.         $this->lft $lft;
  299.         return $this;
  300.     }
  301.     public function getRgt(): ?int
  302.     {
  303.         return $this->rgt;
  304.     }
  305.     public function setRgt(?int $rgt): self
  306.     {
  307.         $this->rgt $rgt;
  308.         return $this;
  309.     }
  310.     public function getLvl(): ?int
  311.     {
  312.         return $this->lvl;
  313.     }
  314.     public function setLvl(?int $lvl): self
  315.     {
  316.         $this->lvl $lvl;
  317.         return $this;
  318.     }
  319.     public function getRoot(): ?int
  320.     {
  321.         return $this->root;
  322.     }
  323.     public function setRoot(int $root): self
  324.     {
  325.         $this->root $root;
  326.         return $this;
  327.     }
  328.     public function getParentId(): ?int
  329.     {
  330.         return $this->parentId;
  331.     }
  332.     public function setParentId(?int $parentId): self
  333.     {
  334.         $this->parentId $parentId;
  335.         return $this;
  336.     }
  337.     public function getCreatedAt(): ?\DateTimeInterface
  338.     {
  339.         return $this->createdAt;
  340.     }
  341.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  342.     {
  343.         $this->createdAt $createdAt;
  344.         return $this;
  345.     }
  346.     public function getUpdatedAt(): ?\DateTimeInterface
  347.     {
  348.         return $this->updatedAt;
  349.     }
  350.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  351.     {
  352.         $this->updatedAt $updatedAt;
  353.         return $this;
  354.     }
  355.     public function getParent(): ?self
  356.     {
  357.         return $this->parent;
  358.     }
  359.     public function setParent(?self $parent): self
  360.     {
  361.         $this->parent $parent;
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection|Page[]
  366.      */
  367.     public function getChildren(): Collection
  368.     {
  369.         return $this->children;
  370.     }
  371.     public function addChild(Page $child): self
  372.     {
  373.         if (!$this->children->contains($child)) {
  374.             $this->children[] = $child;
  375.             $child->setParent($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeChild(Page $child): self
  380.     {
  381.         if ($this->children->contains($child)) {
  382.             $this->children->removeElement($child);
  383.             // set the owning side to null (unless already changed)
  384.             if ($child->getParent() === $this) {
  385.                 $child->setParent(null);
  386.             }
  387.         }
  388.         return $this;
  389.     }
  390.     public function getUniqueTitle(): ?string
  391.     {
  392.         return $this->uniqueTitle;
  393.     }
  394.     public function setUniqueTitle(string $uniqueTitle): self
  395.     {
  396.         $this->uniqueTitle $uniqueTitle;
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection|Translation[]
  401.      */
  402.     public function getTranslations(): Collection
  403.     {
  404.         return $this->translations;
  405.     }
  406.     public function addTranslation(Translation $translation): self
  407.     {
  408.         if (!$this->translations->contains($translation)) {
  409.             $this->translations[] = $translation;
  410.             $translation->setObject($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeTranslation(Translation $translation): self
  415.     {
  416.         if ($this->translations->contains($translation)) {
  417.             $this->translations->removeElement($translation);
  418.             // set the owning side to null (unless already changed)
  419.             if ($translation->getObject() === $this) {
  420.                 $translation->setObject(null);
  421.             }
  422.         }
  423.         return $this;
  424.     }
  425.     public function getHeaderType(): ?int
  426.     {
  427.         return $this->headerType;
  428.     }
  429.     public function setHeaderType(int $headerType): self
  430.     {
  431.         $this->headerType $headerType;
  432.         return $this;
  433.     }
  434.     
  435.     public function getContentEng(): ?string
  436.     {
  437.         return $this->contentEng;
  438.     }
  439.     public function setContentEng(?string $contentEng): self
  440.     {
  441.         $this->contentEng contentEng;
  442.         return $this;
  443.     }
  444.     
  445.     public function getTitleEng(): ?string
  446.     {
  447.         return $this->titleEng;
  448.     }
  449.     public function setTitleEng(string $titleEng): self
  450.     {
  451.         $this->titleEng titleEng;
  452.         return $this;
  453.     }
  454. }