src/Entity/ExamUser.php line 586

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use EADPlataforma\Validator\Constraints as EADAssert;
  6. use EADPlataforma\Enum\ExamUserEnum;
  7. use EADPlataforma\Util\StringUtil;
  8. use EADPlataforma\Util\DateTimeUtil;
  9. use \DateTime;
  10. /**
  11.  * ExamUser
  12.  *
  13.  * @ORM\Table(name="exam_user", indexes={
  14.  *      @ORM\Index(name="fk_exam_user_exam_id", columns={"exam_id"}), 
  15.  *      @ORM\Index(name="fk_exam_user_user_id", columns={"user_id"}), 
  16.  *      @ORM\Index(name="fk_exam_user_course_id", columns={"course_id"}),
  17.  *      @ORM\Index(name="fk_exam_user_user_delete_id", columns={"user_delete_id"})
  18.  * })
  19.  *
  20.  * @ORM\Entity(repositoryClass="EADPlataforma\Repository\ExamUserRepository")
  21.  */
  22. class ExamUser
  23. {
  24.     /**
  25.      * @var int
  26.      *
  27.      * @ORM\Column(name="id", type="integer", nullable=false)
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue(strategy="IDENTITY")
  30.      */
  31.     private $id;
  32.     /**
  33.      * @Assert\NotBlank(
  34.      *      message = "Deleted not informed"
  35.      * )
  36.      *
  37.      * @Assert\Choice(
  38.      *      choices = { 
  39.      *                      ExamUserEnum::ITEM_NO_DELETED, 
  40.      *                      ExamUserEnum::ITEM_ON_TRASH,
  41.      *                      ExamUserEnum::ITEM_DELETED
  42.      *                },
  43.      *      message = "Delete Option Invalid"
  44.      * )
  45.      *
  46.      * @var int
  47.      *
  48.      * @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
  49.      */
  50.     private $deleted ExamUserEnum::ITEM_NO_DELETED;
  51.     /**
  52.      * @Assert\NotBlank(
  53.      *    message = "Status not informed"
  54.      * )
  55.      *
  56.      * @Assert\Choice(
  57.      *      choices = { 
  58.      *                   ExamUserEnum::IN_PROGRESS, 
  59.      *                   ExamUserEnum::WAITING_CORRECTION, 
  60.      *                   ExamUserEnum::TIMEOUT, 
  61.      *                   ExamUserEnum::APPROVED,
  62.      *                   ExamUserEnum::DISAPPROVED
  63.      *                },
  64.      *      message = "Status Invalid"
  65.      * )
  66.      *
  67.      * @var int
  68.      *
  69.      * @ORM\Column(name="status", type="integer", nullable=false, options={"default"="1"})
  70.      */
  71.     private $status ExamUserEnum::IN_PROGRESS;
  72.     /**
  73.      * @Assert\NotBlank(
  74.      *    message = "Inactive not informed"
  75.      * )
  76.      *
  77.      * @Assert\Choice(
  78.      *      choices = { ExamUserEnum::NO, ExamUserEnum::YES },
  79.      *      message = "Inactive Invalid"
  80.      * )
  81.      *
  82.      * @var int
  83.      *
  84.      * @ORM\Column(name="inactive", type="integer", nullable=false, options={"default"="0"})
  85.      */
  86.     private $inactive ExamUserEnum::NO;
  87.     /**
  88.      * @Assert\NotBlank(
  89.      *    message = "Release Access not informed"
  90.      * )
  91.      *
  92.      * @Assert\Choice(
  93.      *      choices = { ExamUserEnum::NO, ExamUserEnum::YES },
  94.      *      message = "Release Access Invalid"
  95.      * )
  96.      *
  97.      * @var int
  98.      *
  99.      * @ORM\Column(name="release_access", type="integer", nullable=false, options={"default"="0"})
  100.      */
  101.     private $releaseAccess ExamUserEnum::NO;
  102.     /**
  103.      * @Assert\NotBlank(
  104.      *    message = "Grade not informed"
  105.      * )
  106.      *
  107.      * @Assert\LessThanOrEqual(
  108.      *      value   = 10,
  109.      *      message = "Grade Invalid"
  110.      * )
  111.      *
  112.      * @var string
  113.      *
  114.      * @ORM\Column(name="grade", type="decimal", precision=10, scale=2, nullable=false, options={"default"="0.00"})
  115.      */
  116.     private $grade '0.00';
  117.     /**
  118.      * @Assert\NotBlank(
  119.      *    message = "Date Start not informed"
  120.      * )
  121.      *
  122.      * @EADAssert\DateTimeEAD(
  123.      *      message = "Date Start Invalid"
  124.      * )
  125.      *
  126.      * @var \DateTime
  127.      *
  128.      * @ORM\Column(name="date_start", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
  129.      */
  130.     private $dateStart;
  131.     /**
  132.      * @EADAssert\DateTimeEAD(
  133.      *      message = "Date End Invalid"
  134.      * )
  135.      *
  136.      * @var \DateTime|null
  137.      *
  138.      * @ORM\Column(name="date_end", type="datetime", nullable=true)
  139.      */
  140.     private $dateEnd;
  141.     /**
  142.      * @var string|null
  143.      *
  144.      * @ORM\Column(name="annotation", type="text", length=0, nullable=true)
  145.      */
  146.     private $annotation;
  147.     /**
  148.      * @Assert\NotBlank(
  149.      *    message = "Outside number not informed"
  150.      * )
  151.      *
  152.      * @var int
  153.      *
  154.      * @ORM\Column(name="outside_number", type="integer", nullable=false, options={"default"="0"})
  155.      */
  156.     private $outsideNumber 0;
  157.     /**
  158.      * @EADAssert\DateTimeEAD(
  159.      *      message = "Outside Time Invalid"
  160.      * )
  161.      *
  162.      * @ORM\Column(name="outside_time", type="time", nullable=true)
  163.      */
  164.     private $outsideTime;
  165.     /**
  166.      * @Assert\NotBlank(
  167.      *    message = "Exam not informed"
  168.      * )
  169.      *
  170.      * @Assert\Valid
  171.      *
  172.      * @var \Exam
  173.      *
  174.      * @ORM\ManyToOne(targetEntity="Exam")
  175.      * @ORM\JoinColumns({
  176.      *   @ORM\JoinColumn(name="exam_id", referencedColumnName="id", nullable=false)
  177.      * })
  178.      */
  179.     private $exam;
  180.     /**
  181.      * @Assert\NotBlank(
  182.      *    message = "Course not informed"
  183.      * )
  184.      *
  185.      * @Assert\Valid
  186.      *
  187.      * @var \Course
  188.      *
  189.      * @ORM\ManyToOne(targetEntity="Course")
  190.      * @ORM\JoinColumns({
  191.      *   @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=false)
  192.      * })
  193.      */
  194.     private $course;
  195.     /**
  196.      * @Assert\NotBlank(
  197.      *    message = "User not informed"
  198.      * )
  199.      *
  200.      * @Assert\Valid
  201.      *
  202.      * @var \User
  203.      *
  204.      * @ORM\ManyToOne(targetEntity="User")
  205.      * @ORM\JoinColumns({
  206.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
  207.      * })
  208.      */
  209.     private $user;
  210.     /**
  211.      * @Assert\Valid
  212.      *
  213.      * @var \EADPlataforma\Entity\User
  214.      *
  215.      * @ORM\ManyToOne(targetEntity="User")
  216.      * @ORM\JoinColumns({
  217.      *   @ORM\JoinColumn(name="user_delete_id", referencedColumnName="id", nullable=true)
  218.      * })
  219.      */
  220.     private $userDelete;
  221.     /**
  222.      * @Assert\Choice(
  223.      *      choices = { 
  224.      *                      ExamUserEnum::INDIVIDUAL, 
  225.      *                      ExamUserEnum::CASCADE
  226.      *                },
  227.      *      message = "Type Delete Invalid"
  228.      * )
  229.      *
  230.      * @var int
  231.      *
  232.      * @ORM\Column(name="type_delete", type="integer", nullable=true)
  233.      */
  234.     private $typeDelete;
  235.     /**
  236.      * @EADAssert\DateTimeEAD(
  237.      *      message = "Date Delete Invalid"
  238.      * )
  239.      *
  240.      * @var \DateTime|null
  241.      *
  242.      * @ORM\Column(name="date_delete", type="datetime", nullable=true)
  243.      */
  244.     private $dateDelete;
  245.     /**
  246.      * Constructor
  247.      */
  248.     public function __construct()
  249.     {
  250.         $this->dateStart = new DateTime();
  251.     }
  252.     public function getId(): ?int
  253.     {
  254.         return $this->id;
  255.     }
  256.     public function getStatus($string false)
  257.     {
  258.         if($string){
  259.             return $this->stringStatus($this->status);
  260.         }
  261.         return $this->status;
  262.         
  263.     }
  264.     public function setStatus(int $status): self
  265.     {
  266.         $this->status $status;
  267.         return $this;
  268.     }
  269.     public function getInactive(): ?int
  270.     {
  271.         return $this->inactive;
  272.     }
  273.     public function setInactive(int $inactive): self
  274.     {
  275.         $this->inactive $inactive;
  276.         return $this;
  277.     }
  278.     public function getReleaseAccess(): ?int
  279.     {
  280.         return $this->releaseAccess;
  281.     }
  282.     public function setReleaseAccess(int $releaseAccess): self
  283.     {
  284.         $this->releaseAccess $releaseAccess;
  285.         return $this;
  286.     }
  287.     public function getGrade()
  288.     {
  289.         return $this->grade;
  290.     }
  291.     public function setGrade($grade): self
  292.     {
  293.         $this->grade $grade;
  294.         return $this;
  295.     }
  296.     public function getDateStart($dateFormat 'Y-m-d H:i:s')
  297.     {
  298.         if(!empty($this->dateStart)){
  299.             return $this->dateStart->format($dateFormat);
  300.         }
  301.         return $this->dateStart;
  302.     }
  303.     public function setDateStart($dateStart): self
  304.     {
  305.         if(!empty($dateStart)){
  306.             $dateStart DateTime::createFromFormat('Y-m-d H:i:s'$dateStart);
  307.         }
  308.         $this->dateStart $dateStart;
  309.         return $this;
  310.     }
  311.     public function getDateEnd($dateFormat 'Y-m-d H:i:s')
  312.     {
  313.         if(!empty($this->dateEnd)){
  314.             return $this->dateEnd->format($dateFormat);
  315.         }
  316.         return $this->dateEnd;
  317.     }
  318.     public function setDateEnd($dateEnd): self
  319.     {
  320.         if(!empty($dateEnd)){
  321.             $dateEnd DateTime::createFromFormat('Y-m-d H:i:s'$dateEnd);
  322.         }
  323.         
  324.         $this->dateEnd $dateEnd;
  325.         return $this;
  326.     }
  327.     public function getAnnotation(): ?string
  328.     {
  329.         return StringUtil::encodeStringStatic($this->annotation);
  330.     }
  331.     public function setAnnotation(?string $annotation): self
  332.     {
  333.         $this->annotation $annotation;
  334.         return $this;
  335.     }
  336.     public function getOutsideNumber(): ?int
  337.     {
  338.         return $this->outsideNumber;
  339.     }
  340.     public function setOutsideNumber(?int $outsideNumber): self
  341.     {
  342.         $this->outsideNumber $outsideNumber;
  343.         return $this;
  344.     }
  345.     public function getOutsideTime($dateFormat 'H:i:s')
  346.     {
  347.         if($this->outsideTime){
  348.             return $this->outsideTime->format($dateFormat);
  349.         }
  350.         return $this->outsideTime;
  351.     }
  352.     public function setOutsideTime($outsideTime): self
  353.     {
  354.         if(!empty($outsideTime)){
  355.             $outsideTime DateTime::createFromFormat('H:i:s'$outsideTime);
  356.         }
  357.         $this->outsideTime $outsideTime;
  358.         return $this;
  359.     }
  360.     public function getExam(): ?Exam
  361.     {
  362.         return $this->exam;
  363.     }
  364.     public function setExam(?Exam $exam): self
  365.     {
  366.         $this->exam $exam;
  367.         return $this;
  368.     }
  369.     public function getCourse(): ?Course
  370.     {
  371.         return $this->course;
  372.     }
  373.     public function setCourse(?Course $course): self
  374.     {
  375.         $this->course $course;
  376.         return $this;
  377.     }
  378.     public function getUser(): ?User
  379.     {
  380.         return $this->user;
  381.     }
  382.     public function setUser(?User $user): self
  383.     {
  384.         $this->user $user;
  385.         return $this;
  386.     }
  387.     public function getUserDelete(): ?User
  388.     {
  389.         return $this->userDelete;
  390.     }
  391.     public function setUserDelete(?User $userDelete): self
  392.     {
  393.         $this->userDelete $userDelete;
  394.         return $this;
  395.     }
  396.     public function getDateDelete($dateFormat 'Y-m-d H:i:s')
  397.     {
  398.         if($this->dateDelete){
  399.             return $this->dateDelete->format($dateFormat);
  400.         }
  401.         return $this->dateDelete;
  402.     }
  403.     public function setDateDelete($dateDelete): self
  404.     {
  405.         if(!empty($dateDelete)){
  406.             $dateDelete DateTime::createFromFormat('Y-m-d H:i:s'$dateDelete);
  407.         }
  408.         
  409.         $this->dateDelete $dateDelete;
  410.         return $this;
  411.     }
  412.     public function individual(): self
  413.     {
  414.         $this->typeDelete ExamUserEnum::INDIVIDUAL;
  415.         return $this;
  416.     }
  417.     public function cascade(): self
  418.     {
  419.         $this->typeDelete ExamUserEnum::CASCADE;
  420.         return $this;
  421.     }
  422.     public function isOnTrash(): bool
  423.     {
  424.         return ($this->deleted == ExamUserEnum::ITEM_ON_TRASH);
  425.     }
  426.     public function isDeleted(): bool
  427.     {
  428.         return ($this->deleted == ExamUserEnum::ITEM_DELETED);
  429.     }
  430.     public function restore(): self
  431.     {
  432.         $this->deleted ExamUserEnum::ITEM_NO_DELETED;
  433.         return $this;
  434.     }
  435.     public function trash(): self
  436.     {
  437.         $this->deleted ExamUserEnum::ITEM_ON_TRASH;
  438.         return $this;
  439.     }
  440.     public function delete(): self
  441.     {
  442.         $this->deleted ExamUserEnum::ITEM_DELETED;
  443.         return $this;
  444.     }
  445.     public function stringStatus($status){
  446.         $string '';
  447.         switch ($status) {
  448.             case ExamUserEnum::IN_PROGRESS:
  449.                 $string 'In Progress';
  450.             break;
  451.             case ExamUserEnum::WAITING_CORRECTION:
  452.                 $string 'Waiting Correction';
  453.             break;
  454.             case ExamUserEnum::TIMEOUT:
  455.                 $string 'Time Out';
  456.             break;
  457.             case ExamUserEnum::APPROVED:
  458.                 $string 'Approved';
  459.             break;
  460.             case ExamUserEnum::DISAPPROVED:
  461.                 $string 'Disapproved';
  462.             break;
  463.         }
  464.         return $string;
  465.     }
  466.     public function getRuntime(): ?string
  467.     {
  468.         $start $this->getDateStart();
  469.         $end $this->getDateEnd();
  470.         if(!empty($start) && !empty($end)){
  471.             $start strtotime($start);
  472.             $end strtotime($end);
  473.             $diff $end $start;
  474.             if($diff 0){
  475.                 $diff $diff * -1;
  476.             }
  477.             return DateTimeUtil::secToTime($diff);
  478.         }
  479.         return '00:00:00';
  480.     }
  481.     public function toReturn(){
  482.         $data = [
  483.             "id" => $this->id,
  484.             "deleted" => $this->deleted,
  485.             "status" => $this->status,
  486.             "inactive" => $this->inactive,
  487.             "releaseAccess" => $this->releaseAccess,
  488.             "grade" => $this->grade,
  489.             "dateStart" => $this->getDateStart(),
  490.             "dateEnd" => $this->getDateEnd(),
  491.             "runtime" => $this->getRuntime(),
  492.             "annotation" => $this->getAnnotation(),
  493.             "outsideNumber" => $this->outsideNumber,
  494.             "outsideTime" => $this->getOutsideTime(),
  495.             "exam" => ( $this->exam $this->exam->getId() : null ),
  496.             "examTitle" => ( $this->exam $this->exam->getTitle() : null ),
  497.             "examType" => ( $this->exam $this->exam->getType() : null ),
  498.             "course" => ( $this->course $this->course->getId() : null ),
  499.             "user" => ($this->user $this->user->getId() : null ),
  500.             "userName" => ($this->user $this->user->getName() : null ),
  501.             "userDelete" => ( $this->userDelete $this->userDelete->getId() : null ),
  502.             "typeDelete" => $this->typeDelete,
  503.             "dateDelete" => $this->getDateDelete()
  504.         ];
  505.         if($this->exam){
  506.             $data["lesson"] = ( $this->exam->getLesson() ? $this->exam->getLesson()->getId() : null );
  507.             $data["lessonModule"] = ( 
  508.                 $this->exam->getLessonModule() ? $this->exam->getLessonModule()->getId() : null 
  509.             );
  510.         }
  511.         return $data;
  512.     }
  513. }