src/Entity/LessonModule.php line 320

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\Services\FileService;
  7. use EADPlataforma\Enum\LessonModuleEnum;
  8. use EADPlataforma\Util\StringUtil;
  9. use \DateTime;
  10. /**
  11.  * LessonModule
  12.  *
  13.  * @ORM\Table(name="lesson_module", indexes={
  14.  *      @ORM\Index(name="fk_lesson_module_user_id", columns={"user_id"}), 
  15.  *      @ORM\Index(name="fk_lesson_module_course_id", columns={"course_id"}),
  16.  *      @ORM\Index(name="fk_lesson_module_user_delete_id", columns={"user_delete_id"})
  17.  * })
  18.  *
  19.  * @ORM\Entity(repositoryClass="EADPlataforma\Repository\LessonModuleRepository")
  20.  */
  21. class LessonModule
  22. {
  23.     /**
  24.      * @var int
  25.      *
  26.      * @ORM\Column(name="id", type="integer", nullable=false)
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="IDENTITY")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @Assert\NotBlank(
  33.      *      message = "Deleted not informed"
  34.      * )
  35.      *
  36.      * @Assert\Choice(
  37.      *      choices = { 
  38.      *                      LessonModuleEnum::ITEM_NO_DELETED, 
  39.      *                      LessonModuleEnum::ITEM_ON_TRASH,
  40.      *                      LessonModuleEnum::ITEM_DELETED
  41.      *                },
  42.      *      message = "Delete Option Invalid"
  43.      * )
  44.      *
  45.      * @var int
  46.      *
  47.      * @ORM\Column(name="deleted", type="integer", nullable=false, options={"default"="0"})
  48.      */
  49.     private $deleted LessonModuleEnum::ITEM_NO_DELETED;
  50.     /**
  51.      * @Assert\NotBlank(
  52.      *      message = "Order not informed"
  53.      * )
  54.      *
  55.      * @var int
  56.      *
  57.      * @ORM\Column(name="`order`", type="integer", nullable=false)
  58.      */
  59.     private $order;
  60.     /**
  61.      * @Assert\NotBlank(
  62.      *    message = "Title not informed"
  63.      * )
  64.      * 
  65.      * @Assert\Length(
  66.      *      min = 0,
  67.      *      max = 250
  68.      * )
  69.      *
  70.      * @var string
  71.      *
  72.      * @ORM\Column(name="title", type="string", length=255, nullable=false)
  73.      */
  74.     private $title;
  75.     /**
  76.      * @var string|null
  77.      *
  78.      * @ORM\Column(name="workload", type="string", length=10, nullable=true)
  79.      */
  80.     private $workload;
  81.     /**
  82.      * @Assert\NotBlank(
  83.      *    message = "Status not informed"
  84.      * )
  85.      *
  86.      * @Assert\Choice(
  87.      *      choices = { LessonModuleEnum::DRAFT, LessonModuleEnum::PUBLISHED },
  88.      *      message = "Status Invalid"
  89.      * )
  90.      *
  91.      * @var int
  92.      *
  93.      * @ORM\Column(name="status", type="integer", nullable=false, options={"default"="0"})
  94.      */
  95.     private $status LessonModuleEnum::DRAFT;
  96.     /**
  97.      * @var string|null
  98.      *
  99.      * @ORM\Column(name="description", type="text", length=65535, nullable=true)
  100.      */
  101.     private $description;
  102.     /**
  103.      * @Assert\NotBlank(
  104.      *    message = "Course not informed"
  105.      * )
  106.      *
  107.      * @Assert\Valid
  108.      *
  109.      * @var \Course
  110.      *
  111.      * @ORM\ManyToOne(targetEntity="Course")
  112.      * @ORM\JoinColumns({
  113.      *   @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=false)
  114.      * })
  115.      */
  116.     private $course;
  117.     /**
  118.      * @Assert\NotBlank(
  119.      *    message = "User not informed"
  120.      * )
  121.      *
  122.      * @Assert\Valid
  123.      *
  124.      * @var \User
  125.      *
  126.      * @ORM\ManyToOne(targetEntity="User")
  127.      * @ORM\JoinColumns({
  128.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
  129.      * })
  130.      */
  131.     private $user;
  132.     /**
  133.      * @Assert\Valid
  134.      *
  135.      * @var \EADPlataforma\Entity\User
  136.      *
  137.      * @ORM\ManyToOne(targetEntity="User")
  138.      * @ORM\JoinColumns({
  139.      *   @ORM\JoinColumn(name="user_delete_id", referencedColumnName="id", nullable=true)
  140.      * })
  141.      */
  142.     private $userDelete;
  143.     /**
  144.      * @Assert\Choice(
  145.      *      choices = { 
  146.      *                      LessonModuleEnum::INDIVIDUAL, 
  147.      *                      LessonModuleEnum::CASCADE
  148.      *                },
  149.      *      message = "Type Delete Invalid"
  150.      * )
  151.      *
  152.      * @var int
  153.      *
  154.      * @ORM\Column(name="type_delete", type="integer", nullable=true)
  155.      */
  156.     private $typeDelete;
  157.     /**
  158.      * @EADAssert\DateTimeEAD(
  159.      *      message = "Date Delete Invalid"
  160.      * )
  161.      *
  162.      * @var \DateTime|null
  163.      *
  164.      * @ORM\Column(name="date_delete", type="datetime", nullable=true)
  165.      */
  166.     private $dateDelete;
  167.     /**
  168.      * @Assert\NotBlank(
  169.      *    message = "Control Requirement not informed"
  170.      * )
  171.      *
  172.      * @Assert\Choice(
  173.      *      choices = { LessonModuleEnum::NO, LessonModuleEnum::YES },
  174.      *      message = "Control Requirement Invalid"
  175.      * )
  176.      *
  177.      * @var int
  178.      *
  179.      * @ORM\Column(name="control_requirement", type="integer", nullable=false, options={"default"="0"})
  180.      */
  181.     private $controlRequirement LessonModuleEnum::NO;
  182.     /**
  183.      * @Assert\NotBlank(
  184.      *    message = "Control Release Type not informed"
  185.      * )
  186.      *
  187.      * @Assert\Choice(
  188.      *      choices = { LessonModuleEnum::RELEASED, LessonModuleEnum::FIXED_DATE, LessonModuleEnum::FLEXIBLE_DATE },
  189.      *      message = "Control Release Type Invalid"
  190.      * )
  191.      *
  192.      * @var int
  193.      *
  194.      * @ORM\Column(name="control_release_type", type="integer", nullable=false, options={"default"="0"})
  195.      */
  196.     private $controlReleaseType LessonModuleEnum::RELEASED;
  197.     /**
  198.      * @Assert\NotBlank(
  199.      *    message = "Control Release After Type not informed",
  200.      *    groups  = "lssonControlReleaseTypeFlex",
  201.      * )
  202.      *
  203.      * @Assert\Choice(
  204.      *      choices = { LessonModuleEnum::ENROLLMENT, LessonModuleEnum::LAST_MODULE },
  205.      *      message = "Control Release After Type Invalid",
  206.      *      groups  = "lssonControlReleaseTypeFlex",
  207.      * )
  208.      *
  209.      * @var int
  210.      *
  211.      * @ORM\Column(name="control_release_after_type", type="integer", nullable=false, options={"default"="1"})
  212.      */
  213.     private $controlReleaseAfterType LessonModuleEnum::LAST_MODULE;
  214.     /**
  215.      * @Assert\NotBlank(
  216.      *    message = "Control Release Date not informed",
  217.      *    groups  = "lssonControlReleaseTypeFixed",
  218.      * )
  219.      *
  220.      * @EADAssert\DateTimeEAD(
  221.      *      message = "Control Release Date Invalid"
  222.      * )
  223.      *
  224.      * @var \DateTime|null
  225.      *
  226.      * @ORM\Column(name="control_date_release", type="datetime", nullable=true)
  227.      */
  228.     private $controlDateRelease;
  229.     /**
  230.      * @Assert\NotBlank(
  231.      *    message = "Control Release Period not informed",
  232.      *    groups  = "lssonControlReleaseTypeFlex",
  233.      * )
  234.      *
  235.      * @var int|null
  236.      *
  237.      * @ORM\Column(name="control_release_period", type="integer", nullable=true)
  238.      */
  239.     private $controlReleasePeriod;
  240.     /**
  241.      * @var int|null
  242.      *
  243.      * @ORM\Column(name="control_close_period", type="integer", nullable=true)
  244.      */
  245.     private $controlClosePeriod;
  246.     public function getId(): ?int
  247.     {
  248.         return $this->id;
  249.     }
  250.     public function getOrder(): ?int
  251.     {
  252.         return $this->order;
  253.     }
  254.     public function setOrder(int $order): self
  255.     {
  256.         $this->order $order;
  257.         return $this;
  258.     }
  259.     public function getTitle(): ?string
  260.     {
  261.         return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->title));
  262.     }
  263.     public function setTitle(string $title): self
  264.     {
  265.         $this->title StringUtil::toUnicode($title);
  266.         return $this;
  267.     }
  268.     public function getWorkload(): ?string
  269.     {
  270.         return $this->workload;
  271.     }
  272.     public function setWorkload(?string $workload): self
  273.     {
  274.         $this->workload $workload;
  275.         return $this;
  276.     }
  277.     public function getStatus(): ?int
  278.     {
  279.         return $this->status;
  280.     }
  281.     public function setStatus(int $status): self
  282.     {
  283.         $this->status $status;
  284.         return $this;
  285.     }
  286.     public function getDescription(): ?string
  287.     {
  288.         return StringUtil::fromUnicode(StringUtil::encodeStringStatic($this->description));
  289.     }
  290.     public function setDescription(?string $description): self
  291.     {
  292.         $this->description StringUtil::toUnicode($description);
  293.         return $this;
  294.     }
  295.     public function getControlRequirement(): ?int
  296.     {
  297.         return $this->controlRequirement;
  298.     }
  299.     public function setControlRequirement(int $controlRequirement): self
  300.     {
  301.         $this->controlRequirement $controlRequirement;
  302.         return $this;
  303.     }
  304.     public function getControlReleaseType(): ?int
  305.     {
  306.         return $this->controlReleaseType;
  307.     }
  308.     public function setControlReleaseType(int $controlReleaseType): self
  309.     {
  310.         $this->controlReleaseType $controlReleaseType;
  311.         return $this;
  312.     }
  313.     public function getControlReleaseAfterType(): ?int
  314.     {
  315.         return $this->controlReleaseAfterType;
  316.     }
  317.     public function setControlReleaseAfterType(int $controlReleaseAfterType): self
  318.     {
  319.         $this->controlReleaseAfterType $controlReleaseAfterType;
  320.         return $this;
  321.     }
  322.     public function getControlDateRelease($dateFormat 'Y-m-d H:i:s')
  323.     {
  324.         if($this->controlDateRelease){
  325.             return $this->controlDateRelease->format($dateFormat);
  326.         }
  327.         return $this->controlDateRelease;
  328.     }
  329.     public function setControlDateRelease($controlDateRelease): self
  330.     {
  331.         if($controlDateRelease){
  332.             $controlDateRelease DateTime::createFromFormat('Y-m-d H:i:s'$controlDateRelease);
  333.         }
  334.         
  335.         $this->controlDateRelease $controlDateRelease;
  336.         return $this;
  337.     }
  338.     public function getControlReleasePeriod(): ?int
  339.     {
  340.         return $this->controlReleasePeriod;
  341.     }
  342.     public function setControlReleasePeriod(?int $controlReleasePeriod): self
  343.     {
  344.         $this->controlReleasePeriod $controlReleasePeriod;
  345.         return $this;
  346.     }
  347.     public function getControlClosePeriod(): ?int
  348.     {
  349.         return $this->controlClosePeriod;
  350.     }
  351.     public function setControlClosePeriod(?int $controlClosePeriod): self
  352.     {
  353.         $this->controlClosePeriod $controlClosePeriod;
  354.         return $this;
  355.     }
  356.     public function getCourse(): ?Course
  357.     {
  358.         return $this->course;
  359.     }
  360.     public function setCourse(?Course $course): self
  361.     {
  362.         $this->course $course;
  363.         return $this;
  364.     }
  365.     public function getUser(): ?User
  366.     {
  367.         return $this->user;
  368.     }
  369.     public function setUser(?User $user): self
  370.     {
  371.         $this->user $user;
  372.         return $this;
  373.     }
  374.     public function getUserDelete(): ?User
  375.     {
  376.         return $this->userDelete;
  377.     }
  378.     public function setUserDelete(?User $userDelete): self
  379.     {
  380.         $this->userDelete $userDelete;
  381.         return $this;
  382.     }
  383.     public function getDateDelete($dateFormat 'Y-m-d H:i:s')
  384.     {
  385.         if($this->dateDelete){
  386.             return $this->dateDelete->format($dateFormat);
  387.         }
  388.         return $this->dateDelete;
  389.     }
  390.     public function setDateDelete($dateDelete): self
  391.     {
  392.         if(!empty($dateDelete)){
  393.             $dateDelete DateTime::createFromFormat('Y-m-d H:i:s'$dateDelete);
  394.         }
  395.         
  396.         $this->dateDelete $dateDelete;
  397.         return $this;
  398.     }
  399.     public function individual(): self
  400.     {
  401.         $this->typeDelete LessonModuleEnum::INDIVIDUAL;
  402.         return $this;
  403.     }
  404.     public function cascade(): self
  405.     {
  406.         $this->typeDelete LessonModuleEnum::CASCADE;
  407.         return $this;
  408.     }
  409.     public function isLive(): bool
  410.     {
  411.         return ($this->deleted == LessonModuleEnum::ITEM_NO_DELETED);
  412.     }
  413.     public function isOnTrash(): bool
  414.     {
  415.         return ($this->deleted == LessonModuleEnum::ITEM_ON_TRASH);
  416.     }
  417.     public function isDeleted(): bool
  418.     {
  419.         return ($this->deleted == LessonModuleEnum::ITEM_DELETED);
  420.     }
  421.     public function restore(): self
  422.     {
  423.         $this->deleted LessonModuleEnum::ITEM_NO_DELETED;
  424.         return $this;
  425.     }
  426.     public function trash(): self
  427.     {
  428.         $this->deleted LessonModuleEnum::ITEM_ON_TRASH;
  429.         return $this;
  430.     }
  431.     public function delete(): self
  432.     {
  433.         $this->deleted LessonModuleEnum::ITEM_DELETED;
  434.         return $this;
  435.     }
  436.     public function isPublic(): bool
  437.     {
  438.         return ($this->status == LessonModuleEnum::PUBLISHED);
  439.     }
  440.     
  441.     public function toReturn(){
  442.         $data = [
  443.             "id" => $this->id,
  444.             "deleted" => $this->deleted,
  445.             "order" => $this->order,
  446.             "title" => $this->getTitle(),
  447.             "workload" => $this->workload,
  448.             "status" => $this->status,
  449.             "description" => $this->getDescription(),
  450.             "controlRequirement" => $this->controlRequirement,
  451.             "controlReleaseType" => $this->controlReleaseType,
  452.             "controlReleaseAfterType" => $this->controlReleaseAfterType,
  453.             "controlDateRelease" => $this->getControlDateRelease(),
  454.             "controlReleasePeriod" => $this->controlReleasePeriod,
  455.             "controlClosePeriod" => $this->controlClosePeriod,
  456.             "course" => ( $this->course $this->course->getId() : null ),
  457.             "courseTitle" => ( $this->course $this->course->getTitle() : null ),
  458.             "user" => ( $this->user $this->user->getId() : null ),
  459.             "userName" => ( $this->user $this->user->getName() : null ),
  460.             "userPhoto" => (
  461.                 $this->user 
  462.                     FileService::getFilePathComplete(
  463.                         $this->user->getPhoto(), 
  464.                         LessonModuleEnum::PATH_PROFILES
  465.                         true
  466.                         true
  467.                     )
  468.                 : null 
  469.             ),
  470.             "userUsername" => ( $this->user $this->user->getUsername() : null ),
  471.             "userDelete" => ( $this->userDelete $this->userDelete->getId() : null ),
  472.             "typeDelete" => $this->typeDelete,
  473.             "dateDelete" => $this->getDateDelete()
  474.         ];
  475.         return $data;
  476.     }
  477.     public function toReturnApi(): array
  478.     {
  479.         return [
  480.             "curso_id" => ( $this->course $this->course->getId() : null ),
  481.             "curso_titulo" => ( $this->course $this->course->getTitle() : null ),
  482.             "carga_horaria" => ( $this->course $this->course->getWorkload() : null ),
  483.             "modulo_id" => $this->id,
  484.             "ordem" => $this->getOrder(),
  485.             "modulo_titulo" => $this->getTitle(),
  486.             "descricao" => $this->getDescription(),
  487.             "status" => $this->getStatus(),
  488.         ];
  489.     }
  490. }