<?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\ExamUserEnum;
use EADPlataforma\Util\StringUtil;
use EADPlataforma\Util\DateTimeUtil;
use \DateTime;
/**
* ExamUser
*
* @ORM\Table(name="exam_user", indexes={
* @ORM\Index(name="fk_exam_user_exam_id", columns={"exam_id"}),
* @ORM\Index(name="fk_exam_user_user_id", columns={"user_id"}),
* @ORM\Index(name="fk_exam_user_course_id", columns={"course_id"}),
* @ORM\Index(name="fk_exam_user_user_delete_id", columns={"user_delete_id"})
* })
*
* @ORM\Entity(repositoryClass="EADPlataforma\Repository\ExamUserRepository")
*/
class ExamUser
{
/**
* @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 = {
* ExamUserEnum::ITEM_NO_DELETED,
* ExamUserEnum::ITEM_ON_TRASH,
* ExamUserEnum::ITEM_DELETED
* },
* message = "Delete Option Invalid"
* )
*
* @var int
*
* @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
*/
private $deleted = ExamUserEnum::ITEM_NO_DELETED;
/**
* @Assert\NotBlank(
* message = "Status not informed"
* )
*
* @Assert\Choice(
* choices = {
* ExamUserEnum::IN_PROGRESS,
* ExamUserEnum::WAITING_CORRECTION,
* ExamUserEnum::TIMEOUT,
* ExamUserEnum::APPROVED,
* ExamUserEnum::DISAPPROVED
* },
* message = "Status Invalid"
* )
*
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="1"})
*/
private $status = ExamUserEnum::IN_PROGRESS;
/**
* @Assert\NotBlank(
* message = "Inactive not informed"
* )
*
* @Assert\Choice(
* choices = { ExamUserEnum::NO, ExamUserEnum::YES },
* message = "Inactive Invalid"
* )
*
* @var int
*
* @ORM\Column(name="inactive", type="integer", nullable=false, options={"default"="0"})
*/
private $inactive = ExamUserEnum::NO;
/**
* @Assert\NotBlank(
* message = "Release Access not informed"
* )
*
* @Assert\Choice(
* choices = { ExamUserEnum::NO, ExamUserEnum::YES },
* message = "Release Access Invalid"
* )
*
* @var int
*
* @ORM\Column(name="release_access", type="integer", nullable=false, options={"default"="0"})
*/
private $releaseAccess = ExamUserEnum::NO;
/**
* @Assert\NotBlank(
* message = "Grade not informed"
* )
*
* @Assert\LessThanOrEqual(
* value = 10,
* message = "Grade Invalid"
* )
*
* @var string
*
* @ORM\Column(name="grade", type="decimal", precision=10, scale=2, nullable=false, options={"default"="0.00"})
*/
private $grade = '0.00';
/**
* @Assert\NotBlank(
* message = "Date Start not informed"
* )
*
* @EADAssert\DateTimeEAD(
* message = "Date Start Invalid"
* )
*
* @var \DateTime
*
* @ORM\Column(name="date_start", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
*/
private $dateStart;
/**
* @EADAssert\DateTimeEAD(
* message = "Date End Invalid"
* )
*
* @var \DateTime|null
*
* @ORM\Column(name="date_end", type="datetime", nullable=true)
*/
private $dateEnd;
/**
* @var string|null
*
* @ORM\Column(name="annotation", type="text", length=0, nullable=true)
*/
private $annotation;
/**
* @Assert\NotBlank(
* message = "Outside number not informed"
* )
*
* @var int
*
* @ORM\Column(name="outside_number", type="integer", nullable=false, options={"default"="0"})
*/
private $outsideNumber = 0;
/**
* @EADAssert\DateTimeEAD(
* message = "Outside Time Invalid"
* )
*
* @ORM\Column(name="outside_time", type="time", nullable=true)
*/
private $outsideTime;
/**
* @Assert\NotBlank(
* message = "Exam not informed"
* )
*
* @Assert\Valid
*
* @var \Exam
*
* @ORM\ManyToOne(targetEntity="Exam")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="exam_id", referencedColumnName="id", nullable=false)
* })
*/
private $exam;
/**
* @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 = {
* ExamUserEnum::INDIVIDUAL,
* ExamUserEnum::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;
/**
* Constructor
*/
public function __construct()
{
$this->dateStart = new DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getStatus($string = false)
{
if($string){
return $this->stringStatus($this->status);
}
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getInactive(): ?int
{
return $this->inactive;
}
public function setInactive(int $inactive): self
{
$this->inactive = $inactive;
return $this;
}
public function getReleaseAccess(): ?int
{
return $this->releaseAccess;
}
public function setReleaseAccess(int $releaseAccess): self
{
$this->releaseAccess = $releaseAccess;
return $this;
}
public function getGrade()
{
return $this->grade;
}
public function setGrade($grade): self
{
$this->grade = $grade;
return $this;
}
public function getDateStart($dateFormat = 'Y-m-d H:i:s')
{
if(!empty($this->dateStart)){
return $this->dateStart->format($dateFormat);
}
return $this->dateStart;
}
public function setDateStart($dateStart): self
{
if(!empty($dateStart)){
$dateStart = DateTime::createFromFormat('Y-m-d H:i:s', $dateStart);
}
$this->dateStart = $dateStart;
return $this;
}
public function getDateEnd($dateFormat = 'Y-m-d H:i:s')
{
if(!empty($this->dateEnd)){
return $this->dateEnd->format($dateFormat);
}
return $this->dateEnd;
}
public function setDateEnd($dateEnd): self
{
if(!empty($dateEnd)){
$dateEnd = DateTime::createFromFormat('Y-m-d H:i:s', $dateEnd);
}
$this->dateEnd = $dateEnd;
return $this;
}
public function getAnnotation(): ?string
{
return StringUtil::encodeStringStatic($this->annotation);
}
public function setAnnotation(?string $annotation): self
{
$this->annotation = $annotation;
return $this;
}
public function getOutsideNumber(): ?int
{
return $this->outsideNumber;
}
public function setOutsideNumber(?int $outsideNumber): self
{
$this->outsideNumber = $outsideNumber;
return $this;
}
public function getOutsideTime($dateFormat = 'H:i:s')
{
if($this->outsideTime){
return $this->outsideTime->format($dateFormat);
}
return $this->outsideTime;
}
public function setOutsideTime($outsideTime): self
{
if(!empty($outsideTime)){
$outsideTime = DateTime::createFromFormat('H:i:s', $outsideTime);
}
$this->outsideTime = $outsideTime;
return $this;
}
public function getExam(): ?Exam
{
return $this->exam;
}
public function setExam(?Exam $exam): self
{
$this->exam = $exam;
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 = ExamUserEnum::INDIVIDUAL;
return $this;
}
public function cascade(): self
{
$this->typeDelete = ExamUserEnum::CASCADE;
return $this;
}
public function isOnTrash(): bool
{
return ($this->deleted == ExamUserEnum::ITEM_ON_TRASH);
}
public function isDeleted(): bool
{
return ($this->deleted == ExamUserEnum::ITEM_DELETED);
}
public function restore(): self
{
$this->deleted = ExamUserEnum::ITEM_NO_DELETED;
return $this;
}
public function trash(): self
{
$this->deleted = ExamUserEnum::ITEM_ON_TRASH;
return $this;
}
public function delete(): self
{
$this->deleted = ExamUserEnum::ITEM_DELETED;
return $this;
}
public function stringStatus($status){
$string = '';
switch ($status) {
case ExamUserEnum::IN_PROGRESS:
$string = 'In Progress';
break;
case ExamUserEnum::WAITING_CORRECTION:
$string = 'Waiting Correction';
break;
case ExamUserEnum::TIMEOUT:
$string = 'Time Out';
break;
case ExamUserEnum::APPROVED:
$string = 'Approved';
break;
case ExamUserEnum::DISAPPROVED:
$string = 'Disapproved';
break;
}
return $string;
}
public function getRuntime(): ?string
{
$start = $this->getDateStart();
$end = $this->getDateEnd();
if(!empty($start) && !empty($end)){
$start = strtotime($start);
$end = strtotime($end);
$diff = $end - $start;
if($diff < 0){
$diff = $diff * -1;
}
return DateTimeUtil::secToTime($diff);
}
return '00:00:00';
}
public function toReturn(){
$data = [
"id" => $this->id,
"deleted" => $this->deleted,
"status" => $this->status,
"inactive" => $this->inactive,
"releaseAccess" => $this->releaseAccess,
"grade" => $this->grade,
"dateStart" => $this->getDateStart(),
"dateEnd" => $this->getDateEnd(),
"runtime" => $this->getRuntime(),
"annotation" => $this->getAnnotation(),
"outsideNumber" => $this->outsideNumber,
"outsideTime" => $this->getOutsideTime(),
"exam" => ( $this->exam ? $this->exam->getId() : null ),
"examTitle" => ( $this->exam ? $this->exam->getTitle() : null ),
"examType" => ( $this->exam ? $this->exam->getType() : null ),
"course" => ( $this->course ? $this->course->getId() : null ),
"user" => ($this->user ? $this->user->getId() : null ),
"userName" => ($this->user ? $this->user->getName() : null ),
"userDelete" => ( $this->userDelete ? $this->userDelete->getId() : null ),
"typeDelete" => $this->typeDelete,
"dateDelete" => $this->getDateDelete()
];
if($this->exam){
$data["lesson"] = ( $this->exam->getLesson() ? $this->exam->getLesson()->getId() : null );
$data["lessonModule"] = (
$this->exam->getLessonModule() ? $this->exam->getLessonModule()->getId() : null
);
}
return $data;
}
}