<?php
namespace EADPlataforma\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use EADPlataforma\Validator\Constraints as EADAssert;
use EADPlataforma\Enum\LessonXLibraryEnum;
use \DateTime;
/**
* LessonXLibrary
*
* @ORM\Table(name="lesson_x_library", indexes={
* @ORM\Index(name="fk_lesson_file_lesson_id", columns={"lesson_id"}),
* @ORM\Index(name="fk_lesson_file_library_id", columns={"library_id"}),
* @ORM\Index(name="fk_lesson_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\LessonXLibraryRepository")
*/
class LessonXLibrary
{
/**
* @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 = {
* LessonXLibraryEnum::ITEM_NO_DELETED,
* LessonXLibraryEnum::ITEM_ON_TRASH,
* LessonXLibraryEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = LessonXLibraryEnum::ITEM_NO_DELETED;
/**
* @Assert\NotBlank(
* message = "Type not informed"
* )
*
* @Assert\Choice(
* choices = { LessonXLibraryEnum::CONTENT, LessonXLibraryEnum::DOWNLOAD },
* message = "Type Invalid"
* )
*
* @var int
*
* @ORM\Column(name="type", type="integer", nullable=false)
*/
private $type;
/**
* @Assert\NotBlank(
* message = "Control Show Document not informed"
* )
*
* @Assert\Choice(
* choices = { LessonXLibraryEnum::NO, LessonXLibraryEnum::YES },
* message = "Control Show Document Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_show_document", type="integer", nullable=false, options={"default"="0"})
*/
private $controlShowDocument = LessonXLibraryEnum::NO;
/**
* @Assert\NotBlank(
* message = "Lesson not informed"
* )
*
* @Assert\Valid
*
* @var \Lesson
*
* @ORM\ManyToOne(targetEntity="Lesson")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="lesson_id", referencedColumnName="id", nullable=false)
* })
*/
private $lesson;
/**
* @Assert\NotBlank(
* message = "Library not informed"
* )
*
* @Assert\Valid
*
* @var \Library
*
* @ORM\ManyToOne(targetEntity="Library")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="library_id", referencedColumnName="id", nullable=false)
* })
*/
private $library;
/**
* @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 = {
* LessonXLibraryEnum::INDIVIDUAL,
* LessonXLibraryEnum::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 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 getControlShowDocument(): ?int
{
return $this->controlShowDocument;
}
public function setControlShowDocument(int $controlShowDocument): self
{
$this->controlShowDocument = $controlShowDocument;
return $this;
}
public function getLesson(): ?Lesson
{
return $this->lesson;
}
public function setLesson(?Lesson $lesson): self
{
$this->lesson = $lesson;
return $this;
}
public function getLibrary(): ?Library
{
return $this->library;
}
public function setLibrary(?Library $library): self
{
$this->library = $library;
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 = LessonXLibraryEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = LessonXLibraryEnum::CASCADE;
return $this;
}
public function isOnTrash(): bool
{
return ($this->deleted == LessonXLibraryEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == LessonXLibraryEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = LessonXLibraryEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = LessonXLibraryEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = LessonXLibraryEnum::ITEM_DELETED;
return $this;
}
public function stringType($type){
$string = '';
switch ($type) {
case LessonXLibraryEnum::CONTENT:
$string = 'Lesson';
break;
case LessonXLibraryEnum::DOWNLOAD:
$string = 'Download';
break;
}
return $string;
}
public function toReturn(){
$data = (object)[
"id" => $this->id,
"deleted" => $this->deleted,
"type" => $this->type,
"controlShowDocument" => $this->controlShowDocument,
"libraryPdfSvgMode" => ( $this->library ? $this->library->getPdfSvgMode() : null ),
"lesson" => ( $this->lesson ? $this->lesson->getId() : null ),
"library" => ( $this->library ? $this->library->getId() : null ),
"libraryTitle" => ( $this->library ? $this->library->getTitle() : null ),
"libraryDownloadNumber" => ( $this->library ? $this->library->getDownloadNumber() : null),
"libraryType" => ( $this->library ? $this->library->getType() : null),
"libraryLink" => ( $this->library ? $this->library->getLink() : null),
"libraryText" => ( $this->library ? $this->library->getText() : null),
"libraryFile" => ( $this->library ? $this->library->getFileName() : null),
"libraryFileSize" => ( $this->library ? $this->library->getFileSize() : null),
"libraryFileExtension" => ( $this->library ? $this->library->getFileExtension() : null),
"libraryPagesNumber" => ( $this->library ? $this->library->getPagesNumber() : null),
"libraryDuration" => ( $this->library ? $this->library->getDuration() : null),
"libraryLiveStart" => ( $this->library ? $this->library->getLiveStart() : null),
"libraryLiveCover" => ( $this->library ? $this->library->getLiveCover() : null),
"libraryLiveLinkTransmit" => (
$this->library ? $this->library->getLiveLinkTransmit() : null
),
"libraryLiveLink" => ( $this->library ? $this->library->getLiveLink() : null),
"libraryLiveToken" => ( $this->library ? $this->library->getLiveToken() : null),
"libraryLiveIdEvent" => ( $this->library ? $this->library->getLiveIdEvent() : null),
"libraryshowTextPdf" => ( $this->library ? $this->library->getShowTextPdf() : null),
"userDelete" => ( $this->userDelete ? $this->userDelete->getId() : null ),
"typeDelete" => $this->typeDelete,
"dateDelete" => $this->getDateDelete()
];
return $data;
}
}