<?php
namespace App\Entity\Content\Pages;
use Symfony\Component\Validator\Constraints AS Constraints;
use Symfony\Component\Validator\Constraints AS Assert;
use Doctrine\ORM\Mapping AS ORM;
use Ramsey\Uuid\Uuid;
use App\Entity\BaseEntity;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="App\Repository\Content\Pages\PageRepository")
* @ORM\Table(name="content_pages_page")
* @ORM\HasLifecycleCallbacks()
*/
class Page extends BaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="uuid")
* @Assert\Uuid
*/
protected $uuid;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $created;
/**
* @ORM\Column(type="string", length=180, nullable=false)
*/
private $name;
/**
* @ORM\Column(type="array", nullable=false)
*/
private $content;
/**
* @ORM\Column(type="string", length=180, nullable=false)
*/
private $slug;
/**
* @ORM\Column(type="string", length=180, nullable=false)
*/
private $path;
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
private $primaryImage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $seoPageTitle;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $seoDescription;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $seoKeywords;
/**
* @ORM\Column(type="integer", length=10, nullable=true)
*/
private $displayOrder;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="parent", cascade={"all"})
* @ORM\OrderBy({"displayOrder" = "ASC", "name" = "ASC"})
**/
private $children;
/**
* @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
**/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Block", mappedBy="page", cascade={"all"})
**/
private $blocks;
public function __construct(array $defaults = array())
{
// Defaults
$this->setUuid(Uuid::uuid4());
$this->setCreated(new \DateTime());
$this->children = new ArrayCollection();
$this->blocks = new ArrayCollection();
$this->content = array();
$this->slug = "";
$this->path = "";
$this->displayDepth = 0;
parent::__construct($defaults);
}
public function getSeoCompletedCount()
{
$count = 0;
if($this->getSeoPageTitle())
$count ++;
if($this->getSeoDescription())
$count ++;
if($this->getSeoKeywords())
$count ++;
return $count;
}
public function __toString()
{
return $this->getName();
}
public function getIndentedName()
{
return trim(str_pad("", $this->getDisplayDepth() * 2, '-', STR_PAD_LEFT) . " " . $this->getName());
}
public function setDisplayDepth($displayDepth)
{
$this->displayDepth = $displayDepth;
}
public function getDisplayDepth()
{
return $this->displayDepth;
}
public function getFriendlyPath()
{
return '/' . $this->getPath();
}
public function getId()
{
return $this->id;
}
public function setUuid($uuid)
{
$this->uuid = $uuid;
return $this;
}
public function getUuid()
{
return $this->uuid;
}
public function setCreated(\DateTime $created)
{
$this->created = $created;
}
public function getCreated()
{
return $this->created;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
public function getDisplayOrder()
{
return $this->displayOrder;
}
public function setDisplayOrder(int $displayOrder = null)
{
$this->displayOrder = $displayOrder;
}
public function getPrimaryImage()
{
return $this->primaryImage;
}
public function setPrimaryImage(string $primaryImage = null)
{
$this->primaryImage = $primaryImage;
}
public function getPrimaryImageWebPath()
{
if(!strlen($this->getPrimaryImage()))
return null;
return '/data/' . $this->getPrimaryImage();
}
public function getSlug()
{
return $this->slug;
}
public function setSlug(string $slug)
{
$this->slug = $slug;
}
public function getPath()
{
return $this->path;
}
public function setPath(string $path)
{
$this->path = $path;
}
public function setContent(array $content = array())
{
$this->content = $content;
}
public function getContent()
{
return $this->content;
}
public function addChild(\App\Entity\Content\Pages\Page $page)
{
if(in_array($page, $this->children->toArray()))
return true;
$this->children[] = $page;
$page->setParent($this);
return $this;
}
public function removeChild(\App\Entity\Content\Pages\Page $page)
{
$this->children->removeElement($page);
$page->setParent(null);
}
public function getChildren()
{
return $this->children;
}
public function setParent(\App\Entity\Content\Pages\Page $parent = null)
{
$this->parent = $parent;
if($parent)
$parent->addChild($this);
}
public function getParent()
{
return $this->parent;
}
public function addBlock(\App\Entity\Content\Pages\Block $block)
{
if(in_array($block, $this->blocks->toArray()))
return true;
$this->blocks[] = $block;
$block->setPage($this);
return $this;
}
public function removeBlock(\App\Entity\Content\Pages\Block $block)
{
$this->blocks->removeElement($block);
$block->setPage(null);
}
public function getBlocks()
{
return $this->blocks;
}
public function setSeoPageTitle(string $seoPageTitle = null)
{
$this->seoPageTitle = $seoPageTitle;
}
public function getSeoPageTitle()
{
return $this->seoPageTitle;
}
public function setSeoDescription(string $seoDescription = null)
{
$this->seoDescription = $seoDescription;
}
public function getSeoDescription()
{
return $this->seoDescription;
}
public function setSeoKeywords(string $seoKeywords = null)
{
$this->seoKeywords = $seoKeywords;
}
public function getSeoKeywords()
{
return $this->seoKeywords;
}
}