<?php
namespace EADPlataforma\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use EADPlataforma\Validator\Constraints as EADAssert;
use EADPlataforma\Util\StringUtil;
use EADPlataforma\Enum\PageEnum;
use \DateTime;
/**
* Page
*
* @ORM\Table(name="page", indexes={
* @ORM\Index(name="fk_page_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\PageRepository")
*
* @UniqueEntity(
* fields={"slug"},
* message="This slug is already"
* )
*/
class Page
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @Assert\NotBlank(
* message = "Deleted not informed"
* )
*
* @Assert\Choice(
* choices = {
* PageEnum::ITEM_NO_DELETED,
* PageEnum::ITEM_ON_TRASH,
* PageEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = PageEnum::ITEM_NO_DELETED;
/**
* @Assert\NotBlank(
* message = "Order not informed"
* )
*
* @var int
*
* @ORM\Column(name="`order`", type="integer", nullable=false)
*/
private $order;
/**
* @Assert\NotBlank(
* message = "Title not informed"
* )
*
* @Assert\Length(
* min = 0,
* max = 45
* )
*
* @var string
*
* @ORM\Column(name="title", type="string", length=50, nullable=false)
*/
private $title;
/**
* @var string|null
*
* @ORM\Column(name="content", type="text", length=0, nullable=true)
*/
private $content;
/**
* @Assert\NotBlank(
* message = "Slug not informed"
* )
*
* @Assert\Length(
* min = 0,
* max = 45
* )
*
* @var string
*
* @ORM\Column(name="slug", type="string", length=50, nullable=false)
*/
private $slug;
/**
* @Assert\NotBlank(
* message = "Status not informed"
* )
*
* @Assert\Choice(
* choices = { PageEnum::DRAFT, PageEnum::PUBLISHED },
* message = "Status Invalid"
* )
*
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="1"})
*/
private $status = PageEnum::PUBLISHED;
/**
* @Assert\NotBlank(
* message = "Show Type not informed"
* )
*
* @Assert\Choice(
* choices = { PageEnum::NAVBAR, PageEnum::FOOTER },
* message = "Show Type Invalid"
* )
*
* @var int
*
* @ORM\Column(name="show_type", type="integer", nullable=false, options={"default"="1"})
*/
private $showType = PageEnum::FOOTER;
/**
* @Assert\NotBlank(
* groups = "linkType"
* )
*
* @Assert\Length(
* min = 0,
* max = 250
* )
*
* @var string|null
*
* @ORM\Column(name="external_link", type="string", length=255, nullable=true)
*/
private $externalLink;
/**
* @Assert\NotBlank(
* message = "Use External Link not informed"
* )
*
* @Assert\Choice(
* choices = { PageEnum::NO, PageEnum::YES },
* message = "Use External Link Invalid"
* )
*
* @var int
*
* @ORM\Column(name="use_external_link", type="integer", nullable=false, options={"default"="0"})
*/
private $useExternalLink = PageEnum::NO;
/**
* @Assert\Valid
*
* @var \EADPlataforma\Entity\User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_delete_id", referencedColumnName="id", nullable=true)
* })
*/
private $userDelete;
/**
* @Assert\Choice(
* choices = {
* PageEnum::INDIVIDUAL,
* PageEnum::CASCADE
* },
* message = "Type Delete Invalid"
* )
*
* @var int
*
* @ORM\Column(name="type_delete", type="integer", nullable=true)
*/
private $typeDelete;
/**
* @EADAssert\DateTimeEAD(
* message = "Date Delete Invalid"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="date_delete", type="datetime", nullable=true)
*/
private $dateDelete;
public function getId(): ?int
{
return $this->id;
}
public function getOrder(): ?int
{
return $this->order;
}
public function setOrder(int $order): self
{
$this->order = $order;
return $this;
}
public function getTitle(): ?string
{
$this->title = StringUtil::removeScriptsStatic($this->title);
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->title));
}
public function setTitle(string $title): self
{
$title = StringUtil::removeScriptsStatic($title);
$this->title = StringUtil::toUnicode($title);
return $this;
}
public function getContent(): ?string
{
$this->content = StringUtil::removeScriptsStatic($this->content);
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->content));
}
public function setContent(string $content): self
{
$content = StringUtil::removeScriptsStatic($content);
$this->content = StringUtil::toUnicode($content);
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = StringUtil::slugStatic($slug);
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getShowType(): ?int
{
return $this->showType;
}
public function setShowType(int $showType): self
{
$this->showType = $showType;
return $this;
}
public function getExternalLink(): ?string
{
return $this->externalLink;
}
public function setExternalLink(?string $externalLink): self
{
$this->externalLink = $externalLink;
return $this;
}
public function getUseExternalLink(): ?int
{
return $this->useExternalLink;
}
public function setUseExternalLink(int $useExternalLink): self
{
$this->useExternalLink = $useExternalLink;
return $this;
}
public function getUserDelete(): ?User
{
return $this->userDelete;
}
public function setUserDelete(?User $userDelete): self
{
$this->userDelete = $userDelete;
return $this;
}
public function getDateDelete($dateFormat = 'Y-m-d H:i:s')
{
if($this->dateDelete){
return $this->dateDelete->format($dateFormat);
}
return $this->dateDelete;
}
public function setDateDelete($dateDelete): self
{
if(!empty($dateDelete)){
$dateDelete = DateTime::createFromFormat('Y-m-d H:i:s', $dateDelete);
}
$this->dateDelete = $dateDelete;
return $this;
}
public function individual(): self
{
$this->typeDelete = PageEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = PageEnum::CASCADE;
return $this;
}
public function isOnTrash(): bool
{
return ($this->deleted == PageEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == PageEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = PageEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = PageEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = PageEnum::ITEM_DELETED;
return $this;
}
public function toReturn(){
$data = [
"id" => $this->id,
"deleted" => $this->deleted,
"order" => $this->order,
"title" => $this->getTitle(),
"content" => $this->getContent(),
"slug" => $this->slug,
"status" => $this->status,
"showType" => $this->showType,
"externalLink" => $this->externalLink,
"useExternalLink" => $this->useExternalLink,
"userDelete" => ( $this->userDelete ? $this->userDelete->getId() : null ),
"typeDelete" => $this->typeDelete,
"dateDelete" => $this->getDateDelete()
];
return $data;
}
}