<?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\Services\FileService;
use EADPlataforma\Enum\LessonEnum;
use EADPlataforma\Util\StringUtil;
use \DateTime;
/**
* Lesson
*
* @ORM\Table(name="lesson", indexes={
* @ORM\Index(name="fk_lesson_lesson_module_id", columns={"lesson_module_id"}),
* @ORM\Index(name="fk_lesson_course_id", columns={"course_id"}),
* @ORM\Index(name="fk_lesson_library_id", columns={"library_id"}),
* @ORM\Index(name="fk_lesson_user_id", columns={"user_id"}),
* @ORM\Index(name="fk_lesson_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\LessonRepository")
*/
class Lesson
{
/**
* @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 = {
* LessonEnum::ITEM_NO_DELETED,
* LessonEnum::ITEM_ON_TRASH,
* LessonEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = LessonEnum::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 = 250
* )
*
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* @Assert\NotBlank(
* message = "Demonstration not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Demonstration Invalid"
* )
*
* @var int
*
* @ORM\Column(name="demonstration", type="integer", nullable=false, options={"default"="0"})
*/
private $demonstration = LessonEnum::NO;
/**
* @Assert\NotBlank(
* message = "Status not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::DRAFT, LessonEnum::PUBLISHED },
* message = "Status Invalid"
* )
*
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="0"})
*/
private $status = LessonEnum::DRAFT;
/**
* @var string|null
*
* @ORM\Column(name="description", type="text", length=65535, nullable=true)
*/
private $description;
/**
* @Assert\NotBlank(
* message = "Control Requirement not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Control Requirement Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_requirement", type="integer", nullable=false, options={"default"="0"})
*/
private $controlRequirement = LessonEnum::NO;
/**
* @Assert\NotBlank(
* message = "Control Release Type not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::RELEASED, LessonEnum::FIXED_DATE, LessonEnum::FLEXIBLE_DATE },
* message = "Control Release Type Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_release_type", type="integer", nullable=false, options={"default"="0"})
*/
private $controlReleaseType = LessonEnum::RELEASED;
/**
* @Assert\NotBlank(
* message = "Control Release After Type not informed",
* groups = "lssonControlReleaseTypeFlex",
* )
*
* @Assert\Choice(
* choices = { LessonEnum::ENROLLMENT, LessonEnum::LAST_LESSON },
* message = "Control Release After Type Invalid",
* groups = "lssonControlReleaseTypeFlex",
* )
*
* @var int
*
* @ORM\Column(name="control_release_after_type", type="integer", nullable=false, options={"default"="1"})
*/
private $controlReleaseAfterType = LessonEnum::LAST_LESSON;
/**
* @Assert\NotBlank(
* message = "Control Release Date not informed",
* groups = "lssonControlReleaseTypeFixed",
* )
*
* @EADAssert\DateTimeEAD(
* message = "Control Release Date Invalid"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="control_date_release", type="datetime", nullable=true)
*/
private $controlDateRelease;
/**
* @Assert\NotBlank(
* message = "Control Release Period not informed",
* groups = "lssonControlReleaseTypeFlex",
* )
*
* @var int|null
*
* @ORM\Column(name="control_release_period", type="integer", nullable=true)
*/
private $controlReleasePeriod;
/**
* @var int|null
*
* @ORM\Column(name="control_close_period", type="integer", nullable=true)
*/
private $controlClosePeriod;
/**
* @Assert\NotBlank(
* message = "Control Time not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Control Time Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_time", type="integer", nullable=false, options={"default"="0"})
*/
private $controlTime = LessonEnum::NO;
/**
* @EADAssert\TimeEAD(
* message = "Control Time Stay Invalid"
* )
*
* @Assert\NotEqualTo(
* value = "00:00:00",
* message = "Control Time Stay not informed"
* )
*
* @var Time|null
*
* @ORM\Column(name="control_time_stay", type="string", length=10, nullable=true)
*/
private $controlTimeStay;
/**
* @Assert\NotBlank(
* message = "Control View not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Control View Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_view_limit", type="integer", nullable=false, options={"default"="0"})
*/
private $controlViewLimit = LessonEnum::NO;
/**
* @Assert\NotBlank(
* message = "Control Lesson View Number not informed",
* groups = "lssonLimitedView"
* )
*
* @Assert\GreaterThanOrEqual(
* value = 1,
* message = "Control Lesson View Number invalid",
* groups = "lssonLimitedView"
* )
*
* @var int|null
*
* @ORM\Column(name="control_view_number", type="integer", nullable=true)
*/
private $controlViewNumber;
/**
* @var int|null
*
* @ORM\Column(name="control_pause_number", type="integer", nullable=true)
*/
private $controlPauseNumber;
/**
* @Assert\NotBlank(
* message = "Control Show Document not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Control Show Document Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_show_document", type="integer", nullable=false, options={"default"="0"})
*/
private $controlShowDocument = LessonEnum::NO;
/**
* @Assert\NotBlank(
* message = "Show Live Chat not informed"
* )
*
* @Assert\Choice(
* choices = { LessonEnum::NO, LessonEnum::YES },
* message = "Show Live Chat Invalid"
* )
*
* @var int
*
* @ORM\Column(name="show_live_chat", type="integer", nullable=false, options={"default"="0"})
*/
private $showLiveChat = LessonEnum::NO;
/**
* @EADAssert\DateTimeEAD(
* message = "Date Last Notify Invalid"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="date_last_notify", type="date", nullable=true)
*/
private $dateLastNotify;
/**
* @Assert\Valid
*
* @var \Library
*
* @ORM\ManyToOne(targetEntity="Library")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="library_id", referencedColumnName="id", nullable=true)
* })
*/
private $library;
/**
* @Assert\NotBlank(
* message = "Lesson Module not informed"
* )
*
* @Assert\Valid
*
* @var \LessonModule
*
* @ORM\ManyToOne(targetEntity="LessonModule")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="lesson_module_id", referencedColumnName="id", nullable=false)
* })
*/
private $lessonModule;
/**
* @Assert\NotBlank(
* message = "Course not informed"
* )
*
* @Assert\Valid
*
* @var \Course
*
* @ORM\ManyToOne(targetEntity="Course")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=false)
* })
*/
private $course;
/**
* @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 \EADPlataforma\Entity\User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_delete_id", referencedColumnName="id", nullable=true)
* })
*/
private $userDelete;
/**
* @Assert\Choice(
* choices = {
* LessonEnum::INDIVIDUAL,
* LessonEnum::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
{
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->title));
}
public function setTitle(string $title): self
{
$this->title = StringUtil::toUnicode($title);
return $this;
}
public function getDemonstration(): ?int
{
return $this->demonstration;
}
public function setDemonstration(int $demonstration): self
{
$this->demonstration = $demonstration;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getDescription(): ?string
{
return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->description));
}
public function setDescription(?string $description): self
{
$this->description = StringUtil::toUnicode($description);
return $this;
}
public function getControlRequirement(): ?int
{
return $this->controlRequirement;
}
public function setControlRequirement(int $controlRequirement): self
{
$this->controlRequirement = $controlRequirement;
return $this;
}
public function getControlReleaseType(): ?int
{
return $this->controlReleaseType;
}
public function setControlReleaseType(int $controlReleaseType): self
{
$this->controlReleaseType = $controlReleaseType;
return $this;
}
public function getControlReleaseAfterType(): ?int
{
return $this->controlReleaseAfterType;
}
public function setControlReleaseAfterType(int $controlReleaseAfterType): self
{
$this->controlReleaseAfterType = $controlReleaseAfterType;
return $this;
}
public function getControlDateRelease($dateFormat = 'Y-m-d H:i:s')
{
if($this->controlDateRelease){
return $this->controlDateRelease->format($dateFormat);
}
return $this->controlDateRelease;
}
public function setControlDateRelease($controlDateRelease): self
{
if($controlDateRelease){
$controlDateRelease = DateTime::createFromFormat('Y-m-d H:i:s', $controlDateRelease);
}
$this->controlDateRelease = $controlDateRelease;
return $this;
}
public function getControlReleasePeriod(): ?int
{
return $this->controlReleasePeriod;
}
public function setControlReleasePeriod(?int $controlReleasePeriod): self
{
$this->controlReleasePeriod = $controlReleasePeriod;
return $this;
}
public function getControlClosePeriod(): ?int
{
return $this->controlClosePeriod;
}
public function setControlClosePeriod(?int $controlClosePeriod): self
{
$this->controlClosePeriod = $controlClosePeriod;
return $this;
}
public function getControlTime(): ?int
{
return ($this->controlRequirement ? $this->controlTime : LessonEnum::NO);
}
public function setControlTime(int $controlTime): self
{
$this->controlTime = $controlTime;
return $this;
}
public function getControlTimeStay(): ?string
{
return $this->controlTimeStay;
}
public function setControlTimeStay(?string $controlTimeStay): self
{
$this->controlTimeStay = $controlTimeStay;
return $this;
}
public function getControlViewLimit(): ?int
{
return $this->controlViewLimit;
}
public function setControlViewLimit(int $controlViewLimit): self
{
$this->controlViewLimit = $controlViewLimit;
return $this;
}
public function getControlViewNumber(): ?int
{
return $this->controlViewNumber;
}
public function setControlViewNumber(?int $controlViewNumber): self
{
$this->controlViewNumber = $controlViewNumber;
return $this;
}
public function getControlPauseNumber(): ?int
{
return $this->controlPauseNumber;
}
public function setControlPauseNumber(?int $controlPauseNumber): self
{
$this->controlPauseNumber = $controlPauseNumber;
return $this;
}
public function getControlShowDocument(): ?int
{
return $this->controlShowDocument;
}
public function setControlShowDocument(int $controlShowDocument): self
{
$this->controlShowDocument = $controlShowDocument;
return $this;
}
public function getShowLiveChat(): ?int
{
return $this->showLiveChat;
}
public function setShowLiveChat(int $showLiveChat): self
{
$this->showLiveChat = $showLiveChat;
return $this;
}
public function getDateLastNotify($dateFormat = 'Y-m-d H:i:s')
{
if($this->dateLastNotify){
return $this->dateLastNotify->format($dateFormat);
}
return $this->dateLastNotify;
}
public function setDateLastNotify($dateLastNotify): self
{
if(!empty($dateLastNotify)){
$dateLastNotify = DateTime::createFromFormat('Y-m-d H:i:s', $dateLastNotify);
}
$this->dateLastNotify = $dateLastNotify;
return $this;
}
public function getLibrary(): ?Library
{
return $this->library;
}
public function setLibrary(?Library $library): self
{
$this->library = $library;
return $this;
}
public function getLessonModule(): ?LessonModule
{
return $this->lessonModule;
}
public function setLessonModule(?LessonModule $lessonModule): self
{
$this->lessonModule = $lessonModule;
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(?Course $course): self
{
$this->course = $course;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
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 = LessonEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = LessonEnum::CASCADE;
return $this;
}
public function isLive(): bool
{
return ($this->deleted == LessonEnum::ITEM_NO_DELETED);
}
public function isOnTrash(): bool
{
return ($this->deleted == LessonEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == LessonEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = LessonEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = LessonEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = LessonEnum::ITEM_DELETED;
return $this;
}
public function isAble(): bool
{
if(!$this->course){
return false;
}
if(!$this->lessonModule){
return false;
}
if(!$this->getCourse()->isLive()){
return false;
}
if(!$this->getLessonModule()->isLive()){
return false;
}
if(!$this->isLive()){
return false;
}
if(!$this->getCourse()->isPublic()){
return false;
}
if(!$this->getLessonModule()->isPublic()){
return false;
}
if(!$this->isPublic()){
return false;
}
return true;
}
public function isPublic(): bool
{
return ($this->status == LessonEnum::PUBLISHED);
}
public function toReturn(){
$data = [
"id" => $this->id,
"deleted" => $this->deleted,
"order" => $this->order,
"title" => $this->getTitle(),
"demonstration" => $this->demonstration,
"status" => $this->status,
"description" => $this->getDescription(),
"controlRequirement" => $this->controlRequirement,
"controlReleaseType" => $this->controlReleaseType,
"controlReleaseAfterType" => $this->controlReleaseAfterType,
"controlDateRelease" => $this->getControlDateRelease(),
"controlReleasePeriod" => $this->controlReleasePeriod,
"controlClosePeriod" => $this->controlClosePeriod,
"controlTime" => (
$this->controlRequirement ? $this->controlTime : LessonEnum::NO
),
"controlTimeStay" => $this->getControlTimeStay(),
"controlViewLimit" => $this->controlViewLimit,
"controlViewNumber" => $this->controlViewNumber,
"controlPauseNumber" => $this->controlPauseNumber,
"controlShowDocument" => $this->controlShowDocument,
"showLiveChat" => $this->showLiveChat,
"dateLastNotify" => $this->getDateLastNotify(),
"library" => ( $this->library ? $this->library->getId() : null ),
"lessonModule" => ( $this->lessonModule ? $this->lessonModule->getId() : null ),
"course" => ( $this->course ? $this->course->getId() : null ),
"user" => ( $this->user ? $this->user->getId() : null ),
"userIsLive" => ( $this->user ? $this->user->isLive() : false ),
"userName" => ( $this->user ? $this->user->getName() : null ),
"userPhoto" => (
$this->user ?
FileService::getFilePathComplete(
$this->user->getPhoto(),
LessonEnum::PATH_PROFILES,
true,
true
)
: null
),
"userUsername" => ( $this->user ? $this->user->getUsername() : null ),
"userDelete" => ( $this->userDelete ? $this->userDelete->getId() : null ),
"typeDelete" => $this->typeDelete,
"dateDelete" => $this->getDateDelete()
];
return $data;
}
}