src/Entity/Content/Pages/Page.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Content\Pages;
  3. use Symfony\Component\Validator\Constraints AS Constraints;
  4. use Symfony\Component\Validator\Constraints AS Assert;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Ramsey\Uuid\Uuid;
  7. use App\Entity\BaseEntity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\Content\Pages\PageRepository")
  11.  * @ORM\Table(name="content_pages_page")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class Page extends BaseEntity
  15. {
  16.     /**
  17.     * @ORM\Id
  18.     * @ORM\GeneratedValue(strategy="AUTO")
  19.     * @ORM\Column(type="integer")
  20.     */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="uuid")
  24.      * @Assert\Uuid
  25.      */
  26.     protected $uuid;
  27.     /**
  28.      * @var \DateTime
  29.      *
  30.      * @ORM\Column(type="datetime", nullable=false)
  31.      */
  32.     private $created;
  33.     /**
  34.      * @ORM\Column(type="string", length=180, nullable=false)
  35.      */
  36.     private $name;
  37.     /**
  38.      * @ORM\Column(type="array", nullable=false)
  39.      */
  40.     private $content;
  41.     /**
  42.      * @ORM\Column(type="string", length=180, nullable=false)
  43.      */
  44.     private $slug;
  45.     /**
  46.      * @ORM\Column(type="string", length=180, nullable=false)
  47.      */
  48.     private $path;
  49.     /**
  50.      * @ORM\Column(type="string", length=200, nullable=true)
  51.      */
  52.     private $primaryImage;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $seoPageTitle;
  57.     /**
  58.      * @ORM\Column(type="string", length=500, nullable=true)
  59.      */
  60.     private $seoDescription;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $seoKeywords;
  65.     /**
  66.      * @ORM\Column(type="integer", length=10, nullable=true)
  67.      */
  68.     private $displayOrder;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity="Page", mappedBy="parent", cascade={"all"})
  71.      * @ORM\OrderBy({"displayOrder" = "ASC", "name" = "ASC"})
  72.      **/
  73.     private $children;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
  76.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  77.      **/
  78.     private $parent;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity="Block", mappedBy="page", cascade={"all"})
  81.      **/
  82.     private $blocks;
  83.     public function __construct(array $defaults = array())
  84.     {
  85.          // Defaults
  86.         $this->setUuid(Uuid::uuid4());
  87.         $this->setCreated(new \DateTime());
  88.         $this->children = new ArrayCollection();
  89.         $this->blocks = new ArrayCollection();
  90.         $this->content = array();
  91.         $this->slug "";
  92.         $this->path "";
  93.         $this->displayDepth 0;
  94.         parent::__construct($defaults);
  95.     }
  96.     public function getSeoCompletedCount()
  97.     {
  98.         $count 0;
  99.         if($this->getSeoPageTitle())
  100.             $count ++;
  101.         if($this->getSeoDescription())
  102.             $count ++;
  103.         if($this->getSeoKeywords())
  104.             $count ++;
  105.         return $count;
  106.     }
  107.     public function __toString()
  108.     {
  109.         return $this->getName();
  110.     }
  111.     public function getIndentedName()
  112.     {
  113.         return trim(str_pad(""$this->getDisplayDepth() * 2'-'STR_PAD_LEFT) . " " $this->getName());
  114.     }
  115.     public function setDisplayDepth($displayDepth)
  116.     {
  117.         $this->displayDepth $displayDepth;
  118.     }
  119.     public function getDisplayDepth()
  120.     {
  121.         return $this->displayDepth;
  122.     }
  123.     public function getFriendlyPath()
  124.     {
  125.         return '/' $this->getPath();
  126.     }
  127.     public function getId()
  128.     {
  129.         return $this->id;
  130.     }
  131.     public function setUuid($uuid)
  132.     {
  133.         $this->uuid $uuid;
  134.         return $this;
  135.     }
  136.     public function getUuid()
  137.     {
  138.         return $this->uuid;
  139.     }
  140.     public function setCreated(\DateTime $created)
  141.     {
  142.         $this->created $created;
  143.     }
  144.     public function getCreated()
  145.     {
  146.         return $this->created;
  147.     }
  148.     public function getName()
  149.     {
  150.         return $this->name;
  151.     }
  152.     public function setName(string $name)
  153.     {
  154.         $this->name $name;
  155.     }
  156.     public function getDisplayOrder()
  157.     {
  158.         return $this->displayOrder;
  159.     }
  160.     public function setDisplayOrder(int $displayOrder null)
  161.     {
  162.         $this->displayOrder $displayOrder;
  163.     }
  164.     public function getPrimaryImage()
  165.     {
  166.         return $this->primaryImage;
  167.     }
  168.     public function setPrimaryImage(string $primaryImage null)
  169.     {
  170.         $this->primaryImage $primaryImage;
  171.     }
  172.     public function getPrimaryImageWebPath()
  173.     {
  174.         if(!strlen($this->getPrimaryImage()))
  175.             return null;
  176.         return '/data/' $this->getPrimaryImage();
  177.     }
  178.     public function getSlug()
  179.     {
  180.         return $this->slug;
  181.     }
  182.     public function setSlug(string $slug)
  183.     {
  184.         $this->slug $slug;
  185.     }
  186.     public function getPath()
  187.     {
  188.         return $this->path;
  189.     }
  190.     public function setPath(string $path)
  191.     {
  192.         $this->path $path;
  193.     }
  194.     public function setContent(array $content = array())
  195.     {
  196.         $this->content $content;
  197.     }
  198.     public function getContent()
  199.     {
  200.         return $this->content;
  201.     }
  202.     public function addChild(\App\Entity\Content\Pages\Page $page)
  203.     {
  204.         if(in_array($page$this->children->toArray()))
  205.             return true;
  206.         $this->children[] = $page;
  207.         $page->setParent($this);
  208.         return $this;
  209.     }
  210.     public function removeChild(\App\Entity\Content\Pages\Page $page)
  211.     {
  212.         $this->children->removeElement($page);
  213.         $page->setParent(null);
  214.     }
  215.     public function getChildren()
  216.     {
  217.         return $this->children;
  218.     }
  219.     public function setParent(\App\Entity\Content\Pages\Page $parent null)
  220.     {
  221.         $this->parent $parent;
  222.         if($parent)
  223.             $parent->addChild($this);
  224.     }
  225.     public function getParent()
  226.     {
  227.         return $this->parent;
  228.     }
  229.     public function addBlock(\App\Entity\Content\Pages\Block $block)
  230.     {
  231.         if(in_array($block$this->blocks->toArray()))
  232.             return true;
  233.         $this->blocks[] = $block;
  234.         $block->setPage($this);
  235.         return $this;
  236.     }
  237.     public function removeBlock(\App\Entity\Content\Pages\Block $block)
  238.     {
  239.         $this->blocks->removeElement($block);
  240.         $block->setPage(null);
  241.     }
  242.     public function getBlocks()
  243.     {
  244.         return $this->blocks;
  245.     }
  246.     public function setSeoPageTitle(string $seoPageTitle null)
  247.     {
  248.         $this->seoPageTitle $seoPageTitle;
  249.     }
  250.     public function getSeoPageTitle()
  251.     {
  252.         return $this->seoPageTitle;
  253.     }
  254.     public function setSeoDescription(string $seoDescription null)
  255.     {
  256.         $this->seoDescription $seoDescription;
  257.     }
  258.     public function getSeoDescription()
  259.     {
  260.         return $this->seoDescription;
  261.     }
  262.     public function setSeoKeywords(string $seoKeywords null)
  263.     {
  264.         $this->seoKeywords $seoKeywords;
  265.     }
  266.     public function getSeoKeywords()
  267.     {
  268.         return $this->seoKeywords;
  269.     }
  270. }