<?php
/**
* (c) itmedia.by <info@itmedia.by>
*/
namespace Submarine\PagesBundle\Entity\Type;
use Submarine\CoreBundle\AccessControl\Role;
use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Тип страницы
* @package Submarine\PagesBundle
*
* @ORM\Entity()
* @ORM\Table(name="submarine_pages_types")
*/
class PageType implements SubmarineEntityInterface
{
/**
* Сортировака по умолчанию
*/
const SORT_POSITION = 0;
/**
* Сортировка по дпте
*/
const SORT_PUBLISHED = 1;
/**
* ID
* @var string
*
* @ORM\Column(name="id", type="string", nullable=false, unique=true)
* @ORM\Id()
*
* @Assert\NotBlank()
* @Assert\Regex(
* pattern="/^[a-zA-Z0-9_]+$/i"
* )
*/
private $id;
/**
* Дополнительные поля
* @var PageTypeField[]
*
* @ORM\OneToMany(
* targetEntity="Submarine\PagesBundle\Entity\Type\PageTypeField",
* mappedBy="type",
* cascade={"REMOVE"},
* indexBy="id"
* )
* @ORM\OrderBy({"position" = "ASC", "title" = "ASC"})
*/
private $fields;
/**
* @var string
* @ORM\Column(type="string", length=128, nullable=false)
*
* @Assert\NotBlank()
*/
private $title;
/**
* @var string
* @ORM\Column(name="description", type="string", length=1024, nullable=true)
*/
private $description;
/**
* @var integer
* @ORM\Column(name="position", type="integer", nullable=false)
*
* @Assert\NotNull()
*/
private $position = 10;
/**
* @var string
* @ORM\Column(name="role_create", type="string", length=32, nullable=false)
*/
private $roleCreate = Role::ROLE_ADMIN;
/**
* @var string
* @ORM\Column(name="role_edit", type="string", length=32, nullable=false)
*/
private $roleEdit = Role::ROLE_ADMIN;
/**
* @var string
* @ORM\Column(name="role_remove", type="string", length=32, nullable=false)
*/
private $roleRemove = Role::ROLE_ADMIN;
/**
* @var boolean
* @ORM\Column(name="is_directory", type="boolean", nullable=true)
*/
private $directory = false;
/**
* @var boolean
* @ORM\Column(name="allow_image", type="boolean", nullable=true)
*/
private $allowImage = true;
/**
* @var boolean
* @ORM\Column(name="allow_files", type="boolean", nullable=true)
*/
private $allowFiles = false;
/**
* @var boolean
* @ORM\Column(name="allow_images", type="boolean", nullable=true)
*/
private $allowImages = false;
/**
* @var boolean
* @ORM\Column(name="allow_comments", type="boolean", nullable=true)
*/
private $allowComments = false;
/**
* @var bool
* @ORM\Column(name="allow_properties", type="boolean", nullable=true)
*/
private $allowProperties = false;
/**
* @var bool
* @ORM\Column(name="allow_linked_pages", type="boolean", nullable=true)
*/
private $allowLinkedPages = false;
/**
* @var bool
* @ORM\Column(name="disable_changing_price", type="boolean", nullable=true)
*/
private $disableChangingPrice = false;
/**
* Тип связанных страниц
* @var PageType|null
* @ORM\ManyToOne(targetEntity="Submarine\PagesBundle\Entity\Type\PageType")
* @ORM\JoinColumn(name="linked_pages_type_id", referencedColumnName="id")
*/
private $linkedPagesType;
/**
* @ORM\Column(name="is_product", type="boolean", nullable=true)
* @var boolean
*/
private $product = false;
/**
* @var \DateTime
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt;
/**
* Сортировка страниц внутри папки
*
* @var int
* @ORM\Column(name="sorting_type", name="sorting", type="integer", nullable=true)
*/
private $sortingType = self::SORT_POSITION;
/**
* Класс картинки для отображения в списке документов
*
* @var string
* @ORM\Column(name="html_class", type="string", nullable=true)
*
* @Assert\NotBlank()
*/
private $htmlClass = 'glyphicon-file';
/**
* Маска URL
* @var string
*
* @ORM\Column(name="url_mask", type="string", nullable=false)
* @Assert\NotBlank()
*/
private $urlMask = '/{tag}';
/**
* Имя сущности
* @return string
*/
public static function entityName()
{
return __CLASS__;
}
public function __construct()
{
$this->createdAt = new \DateTime();
$this->fields = new ArrayCollection();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* @param int $position
*/
public function setPosition($position)
{
$this->position = $position;
}
/**
* @return string
*/
public function getRoleCreate()
{
return $this->roleCreate;
}
/**
* @param string $roleCreatePage
*/
public function setRoleCreate($roleCreatePage)
{
$this->roleCreate = $roleCreatePage;
}
/**
* @return string
*/
public function getRoleEdit()
{
return $this->roleEdit;
}
/**
* @param string $roleChangePage
*/
public function setRoleEdit($roleChangePage)
{
$this->roleEdit = $roleChangePage;
}
/**
* @return string
*/
public function getRoleRemove()
{
return $this->roleRemove;
}
/**
* @param string $roleDeletePage
*/
public function setRoleRemove($roleDeletePage)
{
$this->roleRemove = $roleDeletePage;
}
/**
* @param boolean $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory;
}
/**
* @return boolean
*/
public function isDirectory()
{
return $this->directory;
}
/**
* @return int
*/
public function getSortingType()
{
return $this->sortingType;
}
/**
* @param int $sorting
*/
public function setSortingType($sorting)
{
$this->sortingType = $sorting;
}
/**
* @return string
*/
public function getHtmlClass()
{
return $this->htmlClass;
}
/**
* @param string $htmlClass
*/
public function setHtmlClass($htmlClass)
{
$this->htmlClass = $htmlClass;
}
/**
* @return PageTypeField[]
*/
public function getFields()
{
return $this->fields;
}
/**
* Существует ли поле с именем
*
* @param $id
*
* @return bool
*/
public function hasField($id)
{
return $this->fields->containsKey($id);
}
/**
* Поле
*
* @param $id
*
* @return PageTypeField|null
*/
public function getField($id)
{
return $this->fields->get($id);
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @return boolean
*/
public function isAllowImages()
{
return $this->allowImages;
}
/**
* @param boolean $allowedImages
*/
public function setAllowImages($allowedImages)
{
$this->allowImages = $allowedImages;
}
/**
* @return boolean
*/
public function isAllowImage()
{
return $this->allowImage;
}
/**
* @param boolean $allowedImage
*/
public function setAllowImage($allowedImage)
{
$this->allowImage = $allowedImage;
}
/**
* @return boolean
*/
public function isAllowFiles()
{
return $this->allowFiles;
}
/**
* @param boolean $allowedFiles
*/
public function setAllowFiles($allowedFiles)
{
$this->allowFiles = $allowedFiles;
}
/**
* @return boolean
*/
public function isAllowComments()
{
return $this->allowComments;
}
/**
* @param boolean $allowedComments
*/
public function setAllowComments($allowedComments)
{
$this->allowComments = $allowedComments;
}
/**
* @return boolean
*/
public function isAllowProperties()
{
return $this->allowProperties;
}
/**
* @param boolean $allowProperties
*/
public function setAllowProperties($allowProperties)
{
$this->allowProperties = $allowProperties;
}
/**
* @return mixed
*/
public function isAllowLinkedPages()
{
return $this->allowLinkedPages;
}
/**
* @param mixed $allowLinkedPages
*/
public function setAllowLinkedPages($allowLinkedPages)
{
$this->allowLinkedPages = (bool)$allowLinkedPages;
}
/**
* @return bool
*/
public function isDisableChangingPrice()
{
return $this->disableChangingPrice;
}
/**
* @param bool $disableChangingPrice
*/
public function setDisableChangingPrice($disableChangingPrice)
{
$this->disableChangingPrice = (bool)$disableChangingPrice;
}
/**
* @return null|PageType
*/
public function getLinkedPagesType()
{
return $this->linkedPagesType;
}
/**
* @param null|PageType $linkedPagesType
*/
public function setLinkedPagesType(PageType $linkedPagesType = null)
{
$this->linkedPagesType = $linkedPagesType;
}
/**
* @return boolean
*/
public function isProduct()
{
return $this->product;
}
/**
* @param boolean $product
*/
public function setProduct($product)
{
$this->product = $product;
}
/**
* @return string
*/
public function getUrlMask()
{
return $this->urlMask;
}
/**
* @param string $urlMask
*/
public function setUrlMask($urlMask)
{
$this->urlMask = $urlMask;
}
}