<?php
namespace EADPlataforma\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use EADPlataforma\Validator\Constraints as EADAssert;
use EADPlataforma\Enum\LibraryEnum;
use EADPlataforma\Util\StringUtil;
use \DateTime;
/**
* Library
*
* @ORM\Table(name="library", indexes={
* @ORM\Index(name="fk_library_record_user_id", columns={"record_user_id"}),
* @ORM\Index(name="fk_library_record_library_id", columns={"record_library_id"}),
* @ORM\Index(name="fk_library_user_id", columns={"user_id"}),
* @ORM\Index(name="fk_library_live_end_user_id", columns={"live_end_user_id"}),
* @ORM\Index(name="fk_library_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\LibraryRepository")
*/
class Library
{
/**
* @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 = {
* LibraryEnum::ITEM_NO_DELETED,
* LibraryEnum::ITEM_ON_TRASH,
* LibraryEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = LibraryEnum::ITEM_NO_DELETED;
/**
* @Assert\NotBlank(
* message = "Title not informed"
* )
*
* @Assert\Length(
* min = 0,
* max = 145
* )
*
* @var string
*
* @ORM\Column(name="title", type="string", length=150, nullable=false)
*/
private $title;
/**
* @Assert\NotBlank(
* message = "Status not informed"
* )
*
* @Assert\Choice(
* choices = { LibraryEnum::DRAFT, LibraryEnum::PUBLISHED },
* message = "Status Invalid"
* )
*
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="0"})
*/
private $status = LibraryEnum::DRAFT;
/**
* @Assert\NotBlank(
* message = "Origin not informed"
* )
*
* @Assert\Choice(
* choices = {
* LibraryEnum::LESSON,
* LibraryEnum::LESSON_DOWNLOAD,
* LibraryEnum::QUESTION,
* LibraryEnum::LIBRARY,
* LibraryEnum::RECORD
* },
* message = "Origin Invalid"
* )
*
* @var int
*
* @ORM\Column(name="origin", type="integer", nullable=false)
*/
private $origin;
/**
* @Assert\NotBlank(
* message = "Download number not informed"
* )
*
* @var int
*
* @ORM\Column(name="download_number", type="integer", nullable=false, options={"default"="0"})
*/
private $downloadNumber = 0;
/**
* @Assert\Choice(
* choices = {
* LibraryEnum::CONTENT_EMBED,
* LibraryEnum::CONTENT_FILES,
* LibraryEnum::CONTENT_AUDIO,
* LibraryEnum::CONTENT_TEXT,
* LibraryEnum::CONTENT_VIDEO,
* LibraryEnum::CONTENT_LIVE,
* LibraryEnum::CONTENT_CONFERENCE,
* LibraryEnum::CONTENT_VIDEO_FILE,
* LibraryEnum::CONTENT_EXTERNAL_LIVE,
* LibraryEnum::CONTENT_NEW_LIVE
* },
* message = "Type Invalid"
* )
*
* @var int
*
* @ORM\Column(name="type", type="integer", nullable=true)
*/
private $type;
/**
* @Assert\NotBlank(
* message = "Link not informed",
* groups = "linkType"
* )
*
* @var string|null
*
* @ORM\Column(name="link", type="text", length=0, nullable=true)
*/
private $link;
/**
* @Assert\NotBlank(
* message = "Text not informed",
* groups = "textType"
* )
*
* @var string|null
*
* @ORM\Column(name="text", type="text", length=0, nullable=true)
*/
private $text;
/**
* @Assert\File(
* maxSize = "4000M",
* maxSizeMessage = "File is to large",
* groups = "fileType"
* )
*/
protected $file;
/**
* @Assert\NotBlank(
* message = "File not informed",
* groups = "fileType"
* )
*
* @Assert\Length(
* min = 0,
* max = 250
* )
*
* @var string|null
*
* @ORM\Column(name="file", type="string", length=255, nullable=true)
*/
private $fileName;
/**
* @Assert\NotBlank(
* message = "File Size informed",
* groups = "fileType"
* )
*
* @var int|null
*
* @ORM\Column(name="file_size", type="integer", nullable=true)
*/
private $fileSize;
/**
* @Assert\NotBlank(
* message = "File Extension not informed",
* groups = "fileType"
* )
*
* @var string|null
*
* @ORM\Column(name="file_extension", type="string", length=5, nullable=true, options={"fixed"=true})
*/
private $fileExtension;
/**
* @Assert\NotBlank(
* message = "Vimeo Id not informed",
* groups = "vimeoFileType"
* )
*
* @var int|null
*
* @ORM\Column(name="vimeo_id", type="integer", nullable=true)
*/
private $vimeoId;
/**
* @Assert\NotBlank(
* message = "Vimeo Id not informed",
* groups = "vimeoFileType"
* )
*
* @var string|null
*
* @ORM\Column(name="vimeo_video_id", type="string", length=255, nullable=true)
*/
private $vimeoVideoId;
/**
* @Assert\NotBlank(
* message = "Vdocipher Id not informed",
* groups = "videFileType"
* )
*
* @var string|null
*
* @ORM\Column(name="vdocipher_video_id", type="string", length=255, nullable=true)
*/
private $vdocipherVideoId;
/**
* @var int|null
*
* @ORM\Column(name="pages_number", type="integer", nullable=true)
*/
private $pagesNumber;
/**
* @var string|null
*
* @ORM\Column(name="duration", type="string", length=10, nullable=true)
*/
private $duration;
/**
* @EADAssert\DateTimeEAD(
* message = "Live Start Invalid",
* groups = "liveType"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="live_start", type="datetime", nullable=true)
*/
private $liveStart;
/**
* @var \DateTime|null
*
* @ORM\Column(name="live_start_real", type="datetime", nullable=true)
*/
private $liveStartReal;
/**
* @EADAssert\DateTimeEAD(
* message = "Live End Invalid"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="live_end", type="datetime", nullable=true)
*/
private $liveEnd;
/**
* @Assert\Length(
* min = 0,
* max = 250
* )
*
* @var string|null
*
* @ORM\Column(name="live_cover", type="string", length=255, nullable=true)
*/
private $liveCover;
/**
* @Assert\NotBlank(
* message = "Live Link Transmit Invalid",
* groups = "liveType"
* )
*
* @var string|null
*
* @ORM\Column(name="live_link_transmit", type="string", length=255, nullable=true)
*/
private $liveLinkTransmit;
/**
* @Assert\NotBlank(
* message = "Live Link Invalid",
* groups = "liveType"
* )
*
* @var string|null
*
* @ORM\Column(name="live_link", type="string", length=255, nullable=true)
*/
private $liveLink;
/**
* @Assert\NotBlank(
* message = "Live Token Invalid",
* groups = "liveType"
* )
*
* @var string|null
*
* @ORM\Column(name="live_token", type="string", length=255, nullable=true)
*/
private $liveToken;
/**
* @Assert\NotBlank(
* message = "Live Id Event Invalid",
* groups = "liveType"
* )
*
* @var string|null
*
* @ORM\Column(name="live_id_event", type="string", length=45, nullable=true)
*/
private $liveIdEvent;
/**
* @Assert\NotBlank(
* message = "Show Live Viewer Number not informed"
* )
*
* @Assert\Choice(
* choices = { LibraryEnum::NO, LibraryEnum::YES },
* message = "Show Live Viewer Number Invalid"
* )
*
* @var int
*
* @ORM\Column(name="show_live_viewer_number", type="integer", nullable=false, options={"default"="0"})
*/
private $showLiveViewerNumber = LibraryEnum::NO;
/**
* @Assert\NotBlank(
* message = "Show Text Pdf not informed"
* )
*
* @Assert\Choice(
* choices = { LibraryEnum::NO, LibraryEnum::YES },
* message = "Show Text Pdf Invalid"
* )
*
* @var int
*
* @ORM\Column(name="show_text_pdf", type="integer", nullable=false, options={"default"="0"})
*/
private $showTextPdf = LibraryEnum::NO;
/**
*
* @Assert\Choice(
* choices = { LibraryEnum::SVG_OFF, LibraryEnum::SVG_ON },
* message = "PDF Svg Mode invalid"
* )
*
* @var int
*
* @ORM\Column(name="pdf_svg_mode", type="integer", nullable=false, options={"default"="1"})
*/
private $pdfSvgMode = LibraryEnum::SVG_OFF;
/**
*
* @Assert\Choice(
* choices = { LibraryEnum::NO, LibraryEnum::YES },
* message = "Record invalid"
* )
*
* @var int
*
* @ORM\Column(name="record", type="integer", nullable=false, options={"default"="0"})
*/
private $record = LibraryEnum::NO;
/**
* @Assert\NotBlank(
* message = "User not informed"
* )
*
* @Assert\Valid
*
* @var \User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
* })
*/
private $user;
/**
* @Assert\Valid
*
* @var \User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="record_user_id", referencedColumnName="id", nullable=false)
* })
*/
private $recordUser;
/**
* @Assert\Valid
*
* @var \Library
*
* @ORM\ManyToOne(targetEntity="Library")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="record_library_id", referencedColumnName="id", nullable=false)
* })
*/
private $recordLibrary;
/**
* @Assert\Valid
*
* @var \EADPlataforma\Entity\User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="live_end_user_id", referencedColumnName="id", nullable=true)
* })
*/
private $liveEndUser;
/**
* @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 = {
* LibraryEnum::INDIVIDUAL,
* LibraryEnum::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 getTitle(): ?string
{
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->title));
}
public function setTitle(string $title): self
{
$this->title = StringUtil::toUnicode($title);
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getOrigin(): ?int
{
return $this->origin;
}
public function setOrigin(int $origin): self
{
$this->origin = $origin;
return $this;
}
public function getDownloadNumber(): ?int
{
return $this->downloadNumber;
}
public function setDownloadNumber(int $downloadNumber): self
{
$this->downloadNumber = $downloadNumber;
return $this;
}
public function getType($string = false)
{
if($string){
return $this->stringType($this->type);
}
return $this->type;
}
public function setType(?int $type): self
{
$this->type = $type;
return $this;
}
public function getLink(): ?string
{
return html_entity_decode($this->link);
}
public function setLink(?string $link): self
{
$this->link = $link;
return $this;
}
public function getText(): ?string
{
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->text));
}
public function setText(?string $text): self
{
$this->text = StringUtil::toUnicode($text);
return $this;
}
public function setFile($file): self
{
$this->file = $file;
return $this;
}
public function getFile()
{
return $this->file;
}
public function getFileName(): ?string
{
return StringUtil::encodeStringStatic($this->fileName);
}
public function setFileName(?string $fileName): self
{
$this->fileName = $fileName;
return $this;
}
public function getFileSize(): ?int
{
return $this->fileSize;
}
public function setFileSize(?int $fileSize): self
{
$this->fileSize = $fileSize;
return $this;
}
public function getFileExtension(): ?string
{
return $this->fileExtension;
}
public function setFileExtension(?string $fileExtension): self
{
$this->fileExtension = $fileExtension;
return $this;
}
public function getVimeoId(): ?int
{
return $this->vimeoId;
}
public function setVimeoId(?int $vimeoId): self
{
$this->vimeoId = $vimeoId;
return $this;
}
public function getVimeoVideoId(): ?string
{
return $this->vimeoVideoId;
}
public function setVimeoVideoId(?string $vimeoVideoId): self
{
$this->vimeoVideoId = $vimeoVideoId;
return $this;
}
public function getVdocipherVideoId(): ?string
{
return $this->vdocipherVideoId;
}
public function setVdocipherVideoId(?string $vdocipherVideoId): self
{
$this->vdocipherVideoId = $vdocipherVideoId;
return $this;
}
public function getPagesNumber(): ?int
{
return $this->pagesNumber;
}
public function setPagesNumber(?int $pagesNumber): self
{
$this->pagesNumber = $pagesNumber;
return $this;
}
public function getDuration(): ?string
{
return $this->duration;
}
public function setDuration(?string $duration): self
{
$this->duration = $duration;
return $this;
}
public function getLiveStart($dateFormat = 'Y-m-d H:i:s')
{
if($this->liveStart){
return $this->liveStart->format($dateFormat);
}
return $this->liveStart;
}
public function setLiveStart($liveStart): self
{
if($liveStart){
$liveStart = DateTime::createFromFormat('Y-m-d H:i:s', $liveStart);
}
$this->liveStart = $liveStart;
return $this;
}
public function getLiveStartReal($dateFormat = 'Y-m-d H:i:s')
{
if($this->liveStartReal){
return $this->liveStartReal->format($dateFormat);
}
return $this->liveStartReal;
}
public function setLiveStartReal($liveStartReal): self
{
if($liveStartReal){
$liveStartReal = DateTime::createFromFormat('Y-m-d H:i:s', $liveStartReal);
}
$this->liveStartReal = $liveStartReal;
return $this;
}
public function getLiveEnd($dateFormat = 'Y-m-d H:i:s')
{
if($this->liveEnd){
return $this->liveEnd->format($dateFormat);
}
return $this->liveEnd;
}
public function setLiveEnd($liveEnd): self
{
if($liveEnd){
$liveEnd = DateTime::createFromFormat('Y-m-d H:i:s', $liveEnd);
}
$this->liveEnd = $liveEnd;
return $this;
}
public function getLiveCover(): ?string
{
return $this->liveCover;
}
public function setLiveCover(?string $liveCover): self
{
$this->liveCover = $liveCover;
return $this;
}
public function getLiveLinkTransmit(): ?string
{
return $this->liveLinkTransmit;
}
public function setLiveLinkTransmit(?string $liveLinkTransmit): self
{
$this->liveLinkTransmit = $liveLinkTransmit;
return $this;
}
public function getLiveLink(): ?string
{
return $this->liveLink;
}
public function setLiveLink(?string $liveLink): self
{
$this->liveLink = $liveLink;
return $this;
}
public function getLiveToken(): ?string
{
return $this->liveToken;
}
public function setLiveToken(?string $liveToken): self
{
$this->liveToken = $liveToken;
return $this;
}
public function getLiveIdEvent(): ?string
{
return $this->liveIdEvent;
}
public function setLiveIdEvent(?string $liveIdEvent): self
{
$this->liveIdEvent = $liveIdEvent;
return $this;
}
public function getShowLiveViewerNumber(): ?int
{
return $this->showLiveViewerNumber;
}
public function setShowLiveViewerNumber(?int $showLiveViewerNumber): self
{
$this->showLiveViewerNumber = $showLiveViewerNumber;
return $this;
}
public function getShowTextPdf(): ?int
{
return $this->showTextPdf;
}
public function setShowTextPdf(?int $showTextPdf): self
{
$this->showTextPdf = $showTextPdf;
return $this;
}
public function getPdfSvgMode(): ?int
{
return $this->pdfSvgMode;
}
public function setPdfSvgMode(int $pdfSvgMode): self
{
$this->pdfSvgMode = $pdfSvgMode;
return $this;
}
public function getRecord(): ?int
{
return $this->record;
}
public function setRecord(int $record): self
{
$this->record = $record;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getRecordUser(): ?User
{
return $this->recordUser;
}
public function setRecordUser(?User $recordUser): self
{
$this->recordUser = $recordUser;
return $this;
}
public function getRecordLibrary(): ?Library
{
return $this->recordLibrary;
}
public function setRecordLibrary(?Library $recordLibrary): self
{
$this->recordLibrary = $recordLibrary;
return $this;
}
public function getLiveEndUser(): ?User
{
return $this->liveEndUser;
}
public function setLiveEndUser(?User $liveEndUser): self
{
$this->liveEndUser = $liveEndUser;
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 isLive(): bool
{
return ($this->deleted == LibraryEnum::ITEM_NO_DELETED);
}
public function exist(): bool
{
return ($this->deleted != LibraryEnum::ITEM_DELETED);
}
public function individual(): self
{
$this->typeDelete = LibraryEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = LibraryEnum::CASCADE;
return $this;
}
public function isOnTrash(): bool
{
return ($this->deleted == LibraryEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == LibraryEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = LibraryEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = LibraryEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = LibraryEnum::ITEM_DELETED;
return $this;
}
public function stringType($type){
$string = '';
switch ($type) {
case LibraryEnum::CONTENT_EMBED:
$string = 'Embed';
break;
case LibraryEnum::CONTENT_FILES:
$string = 'Files';
break;
case LibraryEnum::CONTENT_AUDIO:
$string = 'Audio';
break;
case LibraryEnum::CONTENT_TEXT:
$string = 'Text';
break;
case LibraryEnum::CONTENT_VIDEO:
$string = 'Video';
break;
case LibraryEnum::CONTENT_LIVE:
$string = 'Live';
break;
case LibraryEnum::CONTENT_NEW_LIVE:
$string = 'Live';
break;
case LibraryEnum::CONTENT_CONFERENCE:
$string = 'Conference';
break;
case LibraryEnum::CONTENT_VIDEO_FILE:
$string = 'Storage';
break;
}
return $string;
}
public function toReturn($clean = false){
$data = [
"id" => $this->id,
"title" => $this->getTitle(),
"downloadNumber" => $this->downloadNumber,
"type" => $this->type,
"link" => html_entity_decode($this->link),
"text" => $this->getText(),
"file" => $this->getFileName(),
"fileSize" => $this->fileSize,
"fileExtension" => $this->fileExtension,
"pagesNumber" => $this->pagesNumber,
"pdfSvgMode" => $this->pdfSvgMode,
"record" => $this->record,
"recordUser" => ($this->recordUser ? $this->recordUser->getId() : null),
"recordLibrary" => ($this->recordLibrary ? $this->recordLibrary->getId() : null),
"duration" => $this->getDuration(),
"liveStart" => $this->getLiveStart(),
"liveStartReal" => $this->getLiveStartReal(),
"liveEnd" => $this->getLiveEnd(),
"liveEndUser" => ( $this->liveEndUser ? $this->liveEndUser->getId() : null ),
"userDelete" => ( $this->userDelete ? $this->userDelete->getId() : null ),
"typeDelete" => $this->typeDelete,
"dateDelete" => $this->getDateDelete()
];
if(!$clean){
$data["deleted"] = $this->deleted;
$data["status"] = $this->status;
$data["origin"] = $this->origin;
$data["vimeoId"] = $this->vimeoId;
$data["vimeoVideoId"] = $this->vimeoVideoId;
$data["vdocipherVideoId"] = $this->vdocipherVideoId;
$data["liveCover"] = $this->liveCover;
$data["liveLinkTransmit"] = $this->liveLinkTransmit;
$data["liveLink"] = $this->liveLink;
$data["liveToken"] = $this->liveToken;
$data["showLiveViewerNumber"] = $this->showLiveViewerNumber;
$data["liveIdEvent"] = $this->liveIdEvent;
$data["showTextPdf"] = $this->showTextPdf;
$data["user"] = ( $this->user ? $this->user->getId() : null );
}
return $data;
}
public function toReturnApi(){
$data = [
"id" => $this->id,
"arquivo" => $this->getTitle(),
"extensao" => $this->fileExtension,
"tipo_conteudo" => $this->type,
"url" => $this->link,
"texto" => $this->text,
"paginas" => $this->pagesNumber,
"duracao" => $this->getDuration(),
"status" => $this->status
];
return $data;
}
}