<?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\LessonModuleEnum;
use EADPlataforma\Util\StringUtil;
use \DateTime;
/**
* LessonModule
*
* @ORM\Table(name="lesson_module", indexes={
* @ORM\Index(name="fk_lesson_module_user_id", columns={"user_id"}),
* @ORM\Index(name="fk_lesson_module_course_id", columns={"course_id"}),
* @ORM\Index(name="fk_lesson_module_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\LessonModuleRepository")
*/
class LessonModule
{
/**
* @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 = {
* LessonModuleEnum::ITEM_NO_DELETED,
* LessonModuleEnum::ITEM_ON_TRASH,
* LessonModuleEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = LessonModuleEnum::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;
/**
* @var string|null
*
* @ORM\Column(name="workload", type="string", length=10, nullable=true)
*/
private $workload;
/**
* @Assert\NotBlank(
* message = "Status not informed"
* )
*
* @Assert\Choice(
* choices = { LessonModuleEnum::DRAFT, LessonModuleEnum::PUBLISHED },
* message = "Status Invalid"
* )
*
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="0"})
*/
private $status = LessonModuleEnum::DRAFT;
/**
* @var string|null
*
* @ORM\Column(name="description", type="text", length=65535, nullable=true)
*/
private $description;
/**
* @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 = {
* LessonModuleEnum::INDIVIDUAL,
* LessonModuleEnum::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;
/**
* @Assert\NotBlank(
* message = "Control Requirement not informed"
* )
*
* @Assert\Choice(
* choices = { LessonModuleEnum::NO, LessonModuleEnum::YES },
* message = "Control Requirement Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_requirement", type="integer", nullable=false, options={"default"="0"})
*/
private $controlRequirement = LessonModuleEnum::NO;
/**
* @Assert\NotBlank(
* message = "Control Release Type not informed"
* )
*
* @Assert\Choice(
* choices = { LessonModuleEnum::RELEASED, LessonModuleEnum::FIXED_DATE, LessonModuleEnum::FLEXIBLE_DATE },
* message = "Control Release Type Invalid"
* )
*
* @var int
*
* @ORM\Column(name="control_release_type", type="integer", nullable=false, options={"default"="0"})
*/
private $controlReleaseType = LessonModuleEnum::RELEASED;
/**
* @Assert\NotBlank(
* message = "Control Release After Type not informed",
* groups = "lssonControlReleaseTypeFlex",
* )
*
* @Assert\Choice(
* choices = { LessonModuleEnum::ENROLLMENT, LessonModuleEnum::LAST_MODULE },
* 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 = LessonModuleEnum::LAST_MODULE;
/**
* @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;
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 getWorkload(): ?string
{
return $this->workload;
}
public function setWorkload(?string $workload): self
{
$this->workload = $workload;
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 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 = LessonModuleEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = LessonModuleEnum::CASCADE;
return $this;
}
public function isLive(): bool
{
return ($this->deleted == LessonModuleEnum::ITEM_NO_DELETED);
}
public function isOnTrash(): bool
{
return ($this->deleted == LessonModuleEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == LessonModuleEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = LessonModuleEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = LessonModuleEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = LessonModuleEnum::ITEM_DELETED;
return $this;
}
public function isPublic(): bool
{
return ($this->status == LessonModuleEnum::PUBLISHED);
}
public function toReturn(){
$data = [
"id" => $this->id,
"deleted" => $this->deleted,
"order" => $this->order,
"title" => $this->getTitle(),
"workload" => $this->workload,
"status" => $this->status,
"description" => $this->getDescription(),
"controlRequirement" => $this->controlRequirement,
"controlReleaseType" => $this->controlReleaseType,
"controlReleaseAfterType" => $this->controlReleaseAfterType,
"controlDateRelease" => $this->getControlDateRelease(),
"controlReleasePeriod" => $this->controlReleasePeriod,
"controlClosePeriod" => $this->controlClosePeriod,
"course" => ( $this->course ? $this->course->getId() : null ),
"courseTitle" => ( $this->course ? $this->course->getTitle() : null ),
"user" => ( $this->user ? $this->user->getId() : null ),
"userName" => ( $this->user ? $this->user->getName() : null ),
"userPhoto" => (
$this->user ?
FileService::getFilePathComplete(
$this->user->getPhoto(),
LessonModuleEnum::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;
}
public function toReturnApi(): array
{
return [
"curso_id" => ( $this->course ? $this->course->getId() : null ),
"curso_titulo" => ( $this->course ? $this->course->getTitle() : null ),
"carga_horaria" => ( $this->course ? $this->course->getWorkload() : null ),
"modulo_id" => $this->id,
"ordem" => $this->getOrder(),
"modulo_titulo" => $this->getTitle(),
"descricao" => $this->getDescription(),
"status" => $this->getStatus(),
];
}
}