src/Entity/Exam.php line 547

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use EADPlataforma\Validator\Constraints as EADAssert;
  7. use EADPlataforma\Enum\ExamEnum;
  8. use EADPlataforma\Enum\QuestionEnum;
  9. use EADPlataforma\Util\StringUtil;
  10. use \DateTime;
  11. /**
  12.  * Exam
  13.  *
  14.  * @ORM\Table(name="exam", indexes={
  15.  *      @ORM\Index(name="fk_exam_lesson_id", columns={"lesson_id"}), 
  16.  *      @ORM\Index(name="fk_exam_lesson_module_id", columns={"lesson_module_id"}), 
  17.  *      @ORM\Index(name="fk_exam_course_id", columns={"course_id"}),
  18.  *      @ORM\Index(name="fk_exam_user_delete_id", columns={"user_delete_id"})
  19.  * })
  20.  *
  21.  * @ORM\Entity(repositoryClass="EADPlataforma\Repository\ExamRepository")
  22.  */
  23. class Exam
  24. {
  25.     /**
  26.      * @var int
  27.      *
  28.      * @ORM\Column(name="id", type="integer", nullable=false)
  29.      * @ORM\Id
  30.      * @ORM\GeneratedValue(strategy="IDENTITY")
  31.      */
  32.     private $id;
  33.     /**
  34.      * @Assert\NotBlank(
  35.      *      message = "Deleted not informed"
  36.      * )
  37.      *
  38.      * @Assert\Choice(
  39.      *      choices = { 
  40.      *                      ExamEnum::ITEM_NO_DELETED, 
  41.      *                      ExamEnum::ITEM_ON_TRASH,
  42.      *                      ExamEnum::ITEM_DELETED
  43.      *                },
  44.      *      message = "Delete Option Invalid"
  45.      * )
  46.      *
  47.      * @var int
  48.      *
  49.      * @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
  50.      */
  51.     private $deleted ExamEnum::ITEM_NO_DELETED;
  52.     /**
  53.      * @Assert\Length(
  54.      *      min = 0,
  55.      *      max = 120
  56.      * )
  57.      *
  58.      * @var string|null
  59.      *
  60.      * @ORM\Column(name="title", type="string", length=125, nullable=true)
  61.      */
  62.     private $title;
  63.     /**
  64.      * @Assert\NotBlank(
  65.      *    message = "Type not informed"
  66.      * )
  67.      *
  68.      * @Assert\Choice(
  69.      *      choices = { ExamEnum::COURSE, ExamEnum::MODULE, ExamEnum::LESSON, ExamEnum::QUIZ },
  70.      *      message = "Type Invalid"
  71.      * )
  72.      *
  73.      * @var int
  74.      *
  75.      * @ORM\Column(name="type", type="integer", nullable=false, options={"default"="1"})
  76.      */
  77.     private $type ExamEnum::COURSE;
  78.     /**
  79.      * @Assert\NotBlank(
  80.      *    message = "Status not informed"
  81.      * )
  82.      *
  83.      * @Assert\Choice(
  84.      *      choices = { ExamEnum::DRAFT, ExamEnum::PUBLISHED },
  85.      *      message = "Status Invalid"
  86.      * )
  87.      *
  88.      * @var int
  89.      *
  90.      * @ORM\Column(name="status", type="integer", nullable=false, options={"default"="0"})
  91.      */
  92.     private $status ExamEnum::DRAFT;
  93.     /**
  94.      * @Assert\NotBlank(
  95.      *    message = "Requirement not informed"
  96.      * )
  97.      *
  98.      * @Assert\Choice(
  99.      *      choices = { ExamEnum::NO, ExamEnum::YES },
  100.      *      message = "Requirement Invalid"
  101.      * )
  102.      *
  103.      * @var int
  104.      *
  105.      * @ORM\Column(name="requirement", type="integer", nullable=false, options={"default"="0"})
  106.      */
  107.     private $requirement ExamEnum::NO;
  108.     /**
  109.      * @Assert\NotBlank(
  110.      *    message = "Question order not informed"
  111.      * )
  112.      *
  113.      * @Assert\Choice(
  114.      *      choices = { ExamEnum::SEQUENTIAL, ExamEnum::RANDOM },
  115.      *      message = "Question order Invalid"
  116.      * )
  117.      *
  118.      * @var int
  119.      *
  120.      * @ORM\Column(name="question_order", type="integer", nullable=false, options={"default"="0"})
  121.      */
  122.     private $questionOrder ExamEnum::SEQUENTIAL;
  123.     /**
  124.      * @Assert\NotBlank(
  125.      *    message = "Question number not informed"
  126.      * )
  127.      *
  128.      * @Assert\GreaterThan(
  129.      *      value   = 0,
  130.      *      message = "Question number not informed"
  131.      * )
  132.      *
  133.      * @Assert\EqualTo(
  134.      *      value   = 1,
  135.      *      groups  = "lessQuestion",
  136.      *      message = "The number of questions is less than the number informed!"
  137.      * )
  138.      *
  139.      * @var int
  140.      *
  141.      * @ORM\Column(name="question_number", type="integer", nullable=false)
  142.      */
  143.     private $questionNumber;
  144.     /**
  145.      * @Assert\NotBlank(
  146.      *    message = "Exame average not informed"
  147.      * )
  148.      *
  149.      * @Assert\GreaterThan(
  150.      *      value   = 0,
  151.      *      message = "Exame average Invalid"
  152.      * )
  153.      *
  154.      * @Assert\LessThanOrEqual(
  155.      *      value   = 10,
  156.      *      message = "Exame average Invalid"
  157.      * )
  158.      *
  159.      * @var int
  160.      *
  161.      * @ORM\Column(name="exam_average", type="decimal", precision=10, scale=2, nullable=false, options={"default"="7"})
  162.      */
  163.     private $examAverage '7';
  164.     /**
  165.      * @Assert\NotBlank(
  166.      *    message = "Exame weight not informed"
  167.      * )
  168.      *
  169.      * @Assert\GreaterThanOrEqual(
  170.      *      value   = 0,
  171.      *      message = "Exame weight Invalid"
  172.      * )
  173.      *
  174.      * @Assert\LessThanOrEqual(
  175.      *      value   = 10,
  176.      *      message = "Exame weight Invalid"
  177.      * )
  178.      *
  179.      * @var int
  180.      *
  181.      * @ORM\Column(name="exam_weight", type="integer", nullable=false, options={"default"="0"})
  182.      */
  183.     private $examWeight '0';
  184.     /**
  185.      * @Assert\NotBlank(
  186.      *    message = "Type Release not informed"
  187.      * )
  188.      *
  189.      * @Assert\Choice(
  190.      *      choices = { ExamEnum::RELEASED, ExamEnum::FIXED_DATE, ExamEnum::FLEXIBLE_PERIOD },
  191.      *      message = "Type Release Invalid"
  192.      * )
  193.      *
  194.      * @var int
  195.      *
  196.      * @ORM\Column(name="type_release", type="integer", nullable=false, options={"default"="1"})
  197.      */
  198.     private $typeRelease ExamEnum::RELEASED;
  199.     /**
  200.      * @Assert\NotBlank(
  201.      *    message = "Period start not informed"
  202.      * )
  203.      *
  204.      * @Assert\GreaterThan(
  205.      *      value   = 0,
  206.      *      groups  = "typeReleaseFlexible",
  207.      *      message = "Period start Invalid"
  208.      * )
  209.      *
  210.      * @var int
  211.      *
  212.      * @ORM\Column(name="period_start", type="integer", nullable=false, options={"default"="0"})
  213.      */
  214.     private $periodStart '0';
  215.     /**
  216.      * @Assert\NotBlank(
  217.      *    message = "Period end not informed"
  218.      * )
  219.      *
  220.      * @var int
  221.      *
  222.      * @ORM\Column(name="period_end", type="integer", nullable=false, options={"default"="0"})
  223.      */
  224.     private $periodEnd '0';
  225.     /**
  226.      * @Assert\NotBlank(
  227.      *    groups  = "typeReleaseFixedDate",
  228.      *    message = "Date Start not informed"
  229.      * )
  230.      *
  231.      * @EADAssert\DateTimeEAD(
  232.      *      message = "Date Start Invalid"
  233.      * )
  234.      *
  235.      * @var \DateTime|null
  236.      *
  237.      * @ORM\Column(name="date_start", type="datetime", nullable=true)
  238.      */
  239.     private $dateStart;
  240.     /**
  241.      * @Assert\NotBlank(
  242.      *    groups  = "notQuiz",
  243.      *    message = "Exam Time not informed"
  244.      * )
  245.      *
  246.      * @Assert\NotEqualTo(
  247.      *    value   = "00:00:00",
  248.      *    groups  = "notQuiz",
  249.      *    message = "Exam Time not informed"
  250.      * )
  251.      *
  252.      * @EADAssert\TimeEAD(
  253.      *    message = "Exam Time Invalid"
  254.      * )
  255.      *
  256.      * @var Time|null
  257.      *
  258.      * @ORM\Column(name="exam_time", type="string", length=10, nullable=true)
  259.      */
  260.     private $examTime;
  261.     /**
  262.      * @Assert\NotBlank(
  263.      *    message = "Attempts not informed"
  264.      * )
  265.      *
  266.      * @Assert\Choice(
  267.      *      choices = { ExamEnum::NO, ExamEnum::YES },
  268.      *      message = "Attempts Invalid"
  269.      * )
  270.      *
  271.      * @var int
  272.      *
  273.      * @ORM\Column(name="attempts", type="integer", nullable=false, options={"default"="0"})
  274.      */
  275.     private $attempts ExamEnum::NO;
  276.     /**
  277.      * @Assert\NotBlank(
  278.      *    message = "Attempts number not informed"
  279.      * )
  280.      *
  281.      * @Assert\GreaterThan(
  282.      *      value   = 0,
  283.      *      message = "Attempts number Invalid"
  284.      * )
  285.      *
  286.      * @var int
  287.      *
  288.      * @ORM\Column(name="attempts_number", type="integer", nullable=false, options={"default"="1"})
  289.      */
  290.     private $attemptsNumber '1';
  291.     /**
  292.      * @Assert\NotBlank(
  293.      *    message = "Attempts auto release not informed"
  294.      * )
  295.      *
  296.      * @Assert\Choice(
  297.      *      choices = { ExamEnum::NO, ExamEnum::YES },
  298.      *      message = "Attempts Auto Release Invalid"
  299.      * )
  300.      *
  301.      * @var int
  302.      *
  303.      * @ORM\Column(name="attempts_auto_release", type="integer", nullable=false, options={"default"="1"})
  304.      */
  305.     private $attemptsAutoRelease ExamEnum::YES;
  306.     /**
  307.      * @Assert\NotBlank(
  308.      *    message = "Attempts type release not informed"
  309.      * )
  310.      *
  311.      * @Assert\Choice(
  312.      *      choices = { ExamEnum::DAYS, ExamEnum::HOURS },
  313.      *      message = "Attempts type Release Invalid"
  314.      * )
  315.      *
  316.      * @var int
  317.      *
  318.      * @ORM\Column(name="attempts_type_release", type="integer", nullable=false, options={"default"="1"})
  319.      */
  320.     private $attemptsTypeRelease ExamEnum::DAYS;
  321.     /**
  322.      * @Assert\NotBlank(
  323.      *    groups  = "attemptsTypeReleaseHours",
  324.      *    message = "Attempts Time not informed"
  325.      * )
  326.      *
  327.      * @Assert\NotEqualTo(
  328.      *    value   = "00:00:00",
  329.      *    groups  = "attemptsTypeReleaseHours",
  330.      *    message = "Attempts Time not informed"
  331.      * )
  332.      *
  333.      * @EADAssert\TimeEAD(
  334.      *    message = "Attempts Time Invalid"
  335.      * )
  336.      *
  337.      * @var Time|null
  338.      *
  339.      * @ORM\Column(name="attempts_time", type="string", length=10, nullable=true)
  340.      */
  341.     private $attemptsTime;
  342.     /**
  343.      * @Assert\NotBlank(
  344.      *    groups  = "attemptsTypeReleaseDays",
  345.      *    message = "Attempts Period not informed"
  346.      * )
  347.      *
  348.      * @Assert\GreaterThan(
  349.      *      value   = 0,
  350.      *      groups  = "attemptsTypeReleaseDays",
  351.      *      message = "Attempts Period Invalid"
  352.      * )
  353.      *
  354.      * @var int|null
  355.      *
  356.      * @ORM\Column(name="attempts_period", type="integer", nullable=true)
  357.      */
  358.     private $attemptsPeriod;
  359.     /**
  360.      * @Assert\NotBlank(
  361.      *    message = "Show template not informed"
  362.      * )
  363.      *
  364.      * @Assert\Choice(
  365.      *      choices = { ExamEnum::NO, ExamEnum::YES },
  366.      *      message = "Show Template Invalid"
  367.      * )
  368.      *
  369.      * @var int
  370.      *
  371.      * @ORM\Column(name="show_template", type="integer", nullable=false, options={"default"="0"})
  372.      */
  373.     private $showTemplate ExamEnum::NO;
  374.     /**
  375.      * @var string|null
  376.      *
  377.      * @ORM\Column(name="note", type="text", length=0, nullable=true)
  378.      */
  379.     private $note;
  380.     /**
  381.      * @EADAssert\DateTimeEAD(
  382.      *      message = "Date Last Notify Invalid"
  383.      * )
  384.      *
  385.      * @var \DateTime|null
  386.      *
  387.      * @ORM\Column(name="date_last_notify", type="datetime", nullable=true)
  388.      */
  389.     private $dateLastNotify;
  390.     /**
  391.      * @Assert\NotBlank(
  392.      *    message = "Course not informed"
  393.      * )
  394.      *
  395.      * @Assert\Valid
  396.      *
  397.      * @var \Course
  398.      *
  399.      * @ORM\ManyToOne(targetEntity="Course")
  400.      * @ORM\JoinColumns({
  401.      *   @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=false)
  402.      * })
  403.      */
  404.     private $course;
  405.     /**
  406.      * @Assert\NotBlank(
  407.      *    groups  = "lessonModule",
  408.      *    message = "Lesson Module not informed"
  409.      * )
  410.      *
  411.      * @Assert\Valid
  412.      *
  413.      * @var \LessonModule
  414.      *
  415.      * @ORM\ManyToOne(targetEntity="LessonModule")
  416.      * @ORM\JoinColumns({
  417.      *   @ORM\JoinColumn(name="lesson_module_id", referencedColumnName="id")
  418.      * })
  419.      */
  420.     private $lessonModule;
  421.     /**
  422.      * @Assert\NotBlank(
  423.      *    groups  = "lesson",
  424.      *    message = "Lesson not informed"
  425.      * )
  426.      *
  427.      * @Assert\Valid
  428.      *
  429.      * @var \Lesson
  430.      *
  431.      * @ORM\ManyToOne(targetEntity="Lesson")
  432.      * @ORM\JoinColumns({
  433.      *   @ORM\JoinColumn(name="lesson_id", referencedColumnName="id")
  434.      * })
  435.      */
  436.     private $lesson;
  437.     /**
  438.      * @Assert\Count(
  439.      *      min = 0,
  440.      *      groups  = "examPublished",
  441.      *      minMessage = "You must specify at least one question",
  442.      * )
  443.      *
  444.      * @var \Doctrine\Common\Collections\Collection
  445.      *
  446.      * @ORM\ManyToMany(targetEntity="Question", inversedBy="exam")
  447.      * @ORM\JoinTable(name="exam_x_question",
  448.      *   joinColumns={
  449.      *     @ORM\JoinColumn(name="exam_id", referencedColumnName="id")
  450.      *   },
  451.      *   inverseJoinColumns={
  452.      *     @ORM\JoinColumn(name="question_id", referencedColumnName="id")
  453.      *   }
  454.      * )
  455.      */
  456.     private $question;
  457.     /**
  458.      * @Assert\Valid
  459.      *
  460.      * @var \EADPlataforma\Entity\User
  461.      *
  462.      * @ORM\ManyToOne(targetEntity="User")
  463.      * @ORM\JoinColumns({
  464.      *   @ORM\JoinColumn(name="user_delete_id", referencedColumnName="id", nullable=true)
  465.      * })
  466.      */
  467.     private $userDelete;
  468.     /**
  469.      * @Assert\Choice(
  470.      *      choices = { 
  471.      *                      ExamEnum::INDIVIDUAL, 
  472.      *                      ExamEnum::CASCADE
  473.      *                },
  474.      *      message = "Type Delete Invalid"
  475.      * )
  476.      *
  477.      * @var int
  478.      *
  479.      * @ORM\Column(name="type_delete", type="integer", nullable=true)
  480.      */
  481.     private $typeDelete;
  482.     /**
  483.      * @EADAssert\DateTimeEAD(
  484.      *      message = "Date Delete Invalid"
  485.      * )
  486.      *
  487.      * @var \DateTime|null
  488.      *
  489.      * @ORM\Column(name="date_delete", type="datetime", nullable=true)
  490.      */
  491.     private $dateDelete;
  492.     /**
  493.      *
  494.      * @var int
  495.      *
  496.      * @ORM\Column(name="control_time", type="integer", nullable=false, options={"default"="0"})
  497.      */
  498.     private $controlTime ExamEnum::NO;
  499.     /**
  500.      * Constructor
  501.      */
  502.     public function __construct()
  503.     {
  504.         $this->question = new \Doctrine\Common\Collections\ArrayCollection();
  505.     }
  506.     public function getId(): ?int
  507.     {
  508.         return $this->id;
  509.     }
  510.     public function getTitle(): ?string
  511.     {
  512.         return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->title));
  513.     }
  514.     public function setTitle(?string $title): self
  515.     {
  516.         $this->title StringUtil::toUnicode($title);
  517.         return $this;
  518.     }
  519.     public function getType($string false)
  520.     {
  521.         if($string){
  522.             return $this->stringType($this->type);
  523.         }
  524.         return $this->type;
  525.     }
  526.     public function setType(int $type): self
  527.     {
  528.         $this->type $type;
  529.         return $this;
  530.     }
  531.     public function getStatus(): ?int
  532.     {
  533.         return $this->status;
  534.     }
  535.     public function setStatus(int $status): self
  536.     {
  537.         $this->status $status;
  538.         return $this;
  539.     }
  540.     public function getRequirement(): ?int
  541.     {
  542.         return $this->requirement;
  543.     }
  544.     public function setRequirement(int $requirement): self
  545.     {
  546.         $this->requirement $requirement;
  547.         return $this;
  548.     }
  549.     public function getQuestionOrder(): ?int
  550.     {
  551.         return $this->questionOrder;
  552.     }
  553.     public function setQuestionOrder(int $questionOrder): self
  554.     {
  555.         $this->questionOrder $questionOrder;
  556.         return $this;
  557.     }
  558.     public function getQuestionNumber(): ?int
  559.     {
  560.         return $this->questionNumber;
  561.     }
  562.     public function setQuestionNumber(int $questionNumber): self
  563.     {
  564.         $this->questionNumber $questionNumber;
  565.         return $this;
  566.     }
  567.     public function getExamAverage()
  568.     {
  569.         return (float)$this->examAverage;
  570.     }
  571.     public function setExamAverage($examAverage): self
  572.     {
  573.         $this->examAverage = (float)$examAverage;
  574.         return $this;
  575.     }
  576.     public function getExamWeight(): ?int
  577.     {
  578.         return $this->examWeight;
  579.     }
  580.     public function setExamWeight(int $examWeight): self
  581.     {
  582.         $this->examWeight $examWeight;
  583.         return $this;
  584.     }
  585.     public function getTypeRelease(): ?int
  586.     {
  587.         return $this->typeRelease;
  588.     }
  589.     public function setTypeRelease(int $typeRelease): self
  590.     {
  591.         $this->typeRelease $typeRelease;
  592.         return $this;
  593.     }
  594.     public function getControlTime(): ?int
  595.     {
  596.         return $this->controlTime;
  597.     }
  598.     public function setControlTime(int $controlTime): self
  599.     {
  600.         $this->controlTime $controlTime;
  601.         return $this;
  602.     } 
  603.     public function getPeriodStart(): ?int
  604.     {
  605.         return $this->periodStart;
  606.     }
  607.     public function setPeriodStart(int $periodStart): self
  608.     {
  609.         $this->periodStart $periodStart;
  610.         return $this;
  611.     }
  612.     public function getPeriodEnd(): ?int
  613.     {
  614.         return $this->periodEnd;
  615.     }
  616.     public function setPeriodEnd(int $periodEnd): self
  617.     {
  618.         $this->periodEnd $periodEnd;
  619.         return $this;
  620.     }
  621.     public function getDateStart($dateFormat 'Y-m-d H:i:s')
  622.     {
  623.         if($this->dateStart){
  624.             return $this->dateStart->format($dateFormat);
  625.         }
  626.         return $this->dateStart;
  627.     }
  628.     public function setDateStart($dateStart): self
  629.     {
  630.         if(!empty($dateStart)){
  631.             $dateStart DateTime::createFromFormat('Y-m-d H:i:s'$dateStart);
  632.         }else{
  633.             $dateStart null;
  634.         }
  635.         $this->dateStart $dateStart;
  636.         return $this;
  637.     }
  638.     public function getExamTime(): ?string
  639.     {
  640.         return $this->examTime;
  641.     }
  642.     public function setExamTime(?string $examTime): self
  643.     {
  644.         $this->examTime $examTime;
  645.         return $this;
  646.     }
  647.     public function getAttempts(): ?int
  648.     {
  649.         return $this->attempts;
  650.     }
  651.     public function setAttempts(int $attempts): self
  652.     {
  653.         $this->attempts $attempts;
  654.         return $this;
  655.     }
  656.     public function getAttemptsNumber(): ?int
  657.     {
  658.         return $this->attemptsNumber;
  659.     }
  660.     public function setAttemptsNumber(int $attemptsNumber): self
  661.     {
  662.         $this->attemptsNumber $attemptsNumber;
  663.         return $this;
  664.     }
  665.     public function getAttemptsAutoRelease(): ?int
  666.     {
  667.         return $this->attemptsAutoRelease;
  668.     }
  669.     public function setAttemptsAutoRelease(int $attemptsAutoRelease): self
  670.     {
  671.         $this->attemptsAutoRelease $attemptsAutoRelease;
  672.         return $this;
  673.     }
  674.     public function getAttemptsTypeRelease(): ?int
  675.     {
  676.         return $this->attemptsTypeRelease;
  677.     }
  678.     public function setAttemptsTypeRelease(int $attemptsTypeRelease): self
  679.     {
  680.         $this->attemptsTypeRelease $attemptsTypeRelease;
  681.         return $this;
  682.     }
  683.     public function getAttemptsTime(): ?string
  684.     {
  685.         return $this->attemptsTime;
  686.     }
  687.     public function setAttemptsTime(?string $attemptsTime): self
  688.     {
  689.         $this->attemptsTime $attemptsTime;
  690.         return $this;
  691.     }
  692.     public function getAttemptsPeriod(): ?int
  693.     {
  694.         return $this->attemptsPeriod;
  695.     }
  696.     public function setAttemptsPeriod(?int $attemptsPeriod): self
  697.     {
  698.         $this->attemptsPeriod $attemptsPeriod;
  699.         return $this;
  700.     }
  701.     public function getShowTemplate(): ?int
  702.     {
  703.         return $this->showTemplate;
  704.     }
  705.     public function setShowTemplate(int $showTemplate): self
  706.     {
  707.         $this->showTemplate $showTemplate;
  708.         return $this;
  709.     }
  710.     public function getNote(): ?string
  711.     {
  712.         return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->note));
  713.     }
  714.     public function setNote(?string $note): self
  715.     {
  716.         $this->note StringUtil::toUnicode($note);
  717.         return $this;
  718.     }
  719.     public function getDateLastNotify($dateFormat 'Y-m-d H:i:s')
  720.     {
  721.         if($this->dateLastNotify){
  722.             return $this->dateLastNotify->format($dateFormat);
  723.         }
  724.         return $this->dateLastNotify;
  725.     }
  726.     public function setDateLastNotify($dateLastNotify): self
  727.     {
  728.         if($dateLastNotify){
  729.             $dateLastNotify DateTime::createFromFormat('Y-m-d H:i:s'$dateLastNotify);
  730.         }
  731.         
  732.         $this->dateLastNotify $dateLastNotify;
  733.         return $this;
  734.     }
  735.     public function getCourse(): ?Course
  736.     {
  737.         return $this->course;
  738.     }
  739.     public function setCourse(?Course $course): self
  740.     {
  741.         $this->course $course;
  742.         return $this;
  743.     }
  744.     public function getLessonModule(): ?LessonModule
  745.     {
  746.         return $this->lessonModule;
  747.     }
  748.     public function setLessonModule(?LessonModule $lessonModule): self
  749.     {
  750.         $this->lessonModule $lessonModule;
  751.         return $this;
  752.     }
  753.     public function getLesson(): ?Lesson
  754.     {
  755.         return $this->lesson;
  756.     }
  757.     public function setLesson(?Lesson $lesson): self
  758.     {
  759.         $this->lesson $lesson;
  760.         return $this;
  761.     }
  762.     public function getUserDelete(): ?User
  763.     {
  764.         return $this->userDelete;
  765.     }
  766.     public function setUserDelete(?User $userDelete): self
  767.     {
  768.         $this->userDelete $userDelete;
  769.         return $this;
  770.     }
  771.     public function getDateDelete($dateFormat 'Y-m-d H:i:s')
  772.     {
  773.         if($this->dateDelete){
  774.             return $this->dateDelete->format($dateFormat);
  775.         }
  776.         return $this->dateDelete;
  777.     }
  778.     public function setDateDelete($dateDelete): self
  779.     {
  780.         if(!empty($dateDelete)){
  781.             $dateDelete DateTime::createFromFormat('Y-m-d H:i:s'$dateDelete);
  782.         }
  783.         
  784.         $this->dateDelete $dateDelete;
  785.         return $this;
  786.     }
  787.     /**
  788.      * @return Collection|Question[]
  789.      */
  790.     public function getQuestion(): Collection
  791.     {
  792.         return $this->question;
  793.     }
  794.     public function addQuestion(Question $question): self
  795.     {
  796.         if (!$this->question->contains($question)) {
  797.             $this->question[] = $question;
  798.         }
  799.         return $this;
  800.     }
  801.     public function getLiveQuestion(): array
  802.     {
  803.         $questions = [];
  804.         foreach ($this->question as $key => $question) {
  805.             if($question->isLive()){
  806.                 $questions[] = $question;
  807.             }
  808.         }
  809.         return $questions;
  810.     }
  811.     public function getQuestionNumberReal(): int
  812.     {
  813.         $questionNumber $this->getQuestionNumber();
  814.         $questionNumberReal count($this->getLiveQuestion());
  815.         if($questionNumber $questionNumberReal){
  816.             $questionNumber $questionNumberReal;
  817.         }
  818.         if($this->getQuestionOrder() == ExamEnum::SEQUENTIAL){
  819.             $questionNumber $questionNumberReal;
  820.         }
  821.         return $questionNumber;
  822.     }
  823.     public function removeQuestion(Question $question): self
  824.     {
  825.         if ($this->question->contains($question)) {
  826.             $this->question->removeElement($question);
  827.         }
  828.         return $this;
  829.     }
  830.     public function individual(): self
  831.     {
  832.         $this->typeDelete ExamEnum::INDIVIDUAL;
  833.         return $this;
  834.     }
  835.     public function cascade(): self
  836.     {
  837.         $this->typeDelete ExamEnum::CASCADE;
  838.         return $this;
  839.     }
  840.     public function isOnTrash(): bool
  841.     {
  842.         return ($this->deleted == ExamEnum::ITEM_ON_TRASH);
  843.     }
  844.     public function isDeleted(): bool
  845.     {
  846.         return ($this->deleted == ExamEnum::ITEM_DELETED);
  847.     }
  848.     public function restore(): self
  849.     {
  850.         $this->deleted ExamEnum::ITEM_NO_DELETED;
  851.         return $this;
  852.     }
  853.     public function trash(): self
  854.     {
  855.         $this->deleted ExamEnum::ITEM_ON_TRASH;
  856.         return $this;
  857.     }
  858.     public function delete(): self
  859.     {
  860.         $this->deleted ExamEnum::ITEM_DELETED;
  861.         return $this;
  862.     }
  863.     public function stringType($type){
  864.         $string '';
  865.         switch ($type) {
  866.             case ExamEnum::COURSE:
  867.                 $string 'Course';
  868.             break;
  869.             case ExamEnum::MODULE:
  870.                 $string 'Module';
  871.             break;
  872.             case ExamEnum::LESSON:
  873.                 $string 'Lesson';
  874.             break;
  875.             case ExamEnum::QUIZ:
  876.                 $string 'Quiz';
  877.             break;
  878.         }
  879.         return $string;
  880.     }
  881.     public function getQuestionsArray(?bool $onlyQuestionLive false): ?array
  882.     {
  883.         $arrQuestion = [];
  884.         foreach ($this->question as $key => $question) {
  885.             if($question->isLive() || !$onlyQuestionLive){
  886.                 if(
  887.                     $this->type != ExamEnum::QUIZ || 
  888.                     $question->getType() == QuestionEnum::ALTERNATIVE
  889.                 ){
  890.                     $arrOption = [];
  891.                     foreach ($question->getOption() as $key => $option) {
  892.                         if($option->isLive() || !$onlyQuestionLive){
  893.                             $arrOption[] = (object)[
  894.                                 "id" => $option->getId(),
  895.                                 "option" => html_entity_decode($option->getOption()),
  896.                             ];
  897.                         }
  898.                     }
  899.                     $arrQuestion[] = (object)[
  900.                         "id" => $question->getId(),
  901.                         "order" => $question->getOrder(),
  902.                         "question" => $question->getQuestion(),
  903.                         "type" => $question->getType(),
  904.                         "note" => $question->getNote(),
  905.                         "libraryId" => (
  906.                             $question->getLibrary() ? 
  907.                             $question->getLibrary()->getId() : 
  908.                             null
  909.                         ),
  910.                         "options" => $arrOption,
  911.                     ];
  912.                 }
  913.             }
  914.         }
  915.         if(!empty($arrQuestion)){
  916.             usort($arrQuestion, function($a$b) {return $a->order $b->order;});
  917.         }
  918.         return $arrQuestion;
  919.     }
  920.     public function toReturn(bool $questions falsebool $onlyQuestionLive false){
  921.         $arrQuestion = [];
  922.         if($questions){
  923.             $arrQuestion $this->getQuestionsArray($onlyQuestionLive);
  924.         }
  925.         $data = [
  926.             "id" => $this->id,
  927.             "deleted" => $this->deleted,
  928.             "title" => $this->getTitle(),
  929.             "type" => $this->type,
  930.             "status" => $this->status,
  931.             "requirement" => $this->requirement,
  932.             "questionOrder" => $this->questionOrder,
  933.             "questionNumber" => $this->questionNumber,
  934.             "examAverage" => $this->examAverage,
  935.             "examWeight" => $this->examWeight,
  936.             "typeRelease" => $this->typeRelease,
  937.             "controlTime" => $this->controlTime,
  938.             "periodStart" => $this->periodStart,
  939.             "periodEnd" => $this->periodEnd,
  940.             "dateStart" => $this->getDateStart(),
  941.             "examTime" => $this->getExamTime(),
  942.             "attempts" => $this->attempts,
  943.             "attemptsNumber" => $this->attemptsNumber,
  944.             "attemptsAutoRelease" => $this->attemptsAutoRelease,
  945.             "attemptsTypeRelease" => $this->attemptsTypeRelease,
  946.             "attemptsTime" => $this->getAttemptsTime(),
  947.             "attemptsPeriod" => $this->attemptsPeriod,
  948.             "showTemplate" => $this->showTemplate,
  949.             "note" => $this->getNote(),
  950.             "dateLastNotify" => $this->getDateLastNotify(),
  951.             "course" => ( $this->course $this->course->getId() : null ),
  952.             "lessonModule" => ( $this->lessonModule $this->lessonModule->getId() : null ),
  953.             "lesson" => ( $this->lesson $this->lesson->getId() : null ),
  954.             "userDelete" => ( $this->userDelete $this->userDelete->getId() : null ),
  955.             "typeDelete" => $this->typeDelete,
  956.             "dateDelete" => $this->getDateDelete()
  957.         ];
  958.         if($questions){
  959.             $data["question"] = $arrQuestion;
  960.         }
  961.         return $data;
  962.     }
  963. }