src/Entity/Course.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CourseRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. #[ORM\Entity(repositoryClassCourseRepository::class)]
  9. class Course
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[ORM\Column(type'string'length255)]
  16.     #[Groups(['LogService'])]
  17.     private $title;
  18.     #[ORM\Column(type'text'nullabletrue)]
  19.     private $description;
  20.     #[ORM\Column(type'text'nullabletrue)]
  21.     private $excerpt
  22.     #[ORM\Column(type'integer'nullabletrue)]
  23.     private $duration;
  24.     #[ORM\Column(type'integer'nullabletrue)]
  25.     private $dueDay;
  26.     #[ORM\Column(type'integer'nullabletrue)]
  27.     #[Groups(['LogService'])]
  28.     private $minScore;
  29.     #[ORM\Column(type'boolean'nullabletrue)]
  30.     private $randomizeOrder false;
  31.     #[ORM\Column(type'boolean'nullabletrue)]
  32.     private $randomizeQuestion;
  33.     #[ORM\Column(type'boolean'nullabletrue)]
  34.     private $isOnboarding;
  35.     #[ORM\Column(type'boolean'nullabletrue)]
  36.     private $needApproval;
  37.     // #[ORM\Column(type: 'boolean')]
  38.     // private $bypass = 1;
  39.     #[ORM\Column(type'integer'nullabletrue)]
  40.     private $retryInterval 0;
  41.     #[ORM\ManyToMany(targetEntityDepartment::class, inversedBy'courses')]
  42.     private $departments;
  43.     #[ORM\ManyToMany(targetEntityOffice::class, inversedBy'courses')]
  44.     private $offices;
  45.     #[ORM\Column(type'text'nullabletrue)]
  46.     #[Groups(['LogService'])]
  47.     private $type;
  48.     #[ORM\Column(type'boolean'nullabletrue)]
  49.     private $isRequired;
  50.     #[ORM\Column(type'array'nullabletrue)]
  51.     private $roles = [];
  52.     #[ORM\Column(type'integer'nullabletrue)]
  53.     private $quizTimer;
  54.     #[ORM\OneToMany(targetEntityCourseContent::class, mappedBy'course')]
  55.     private $courseContents;
  56.      #[ORM\Column(type'string'length16nullabletrue)]
  57.     private $level;
  58.     #[ORM\OneToMany(targetEntityCourseAutoEnrollment::class, mappedBy'course')]
  59.     private $courseAutoEnrollments;
  60.     #[ORM\Column(type'datetime_immutable')]
  61.     private $createdAt;
  62.     #[ORM\ManyToOne(targetEntityUser::class)]
  63.     private $createdBy;
  64.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  65.     #[Groups(['LogService'])]
  66.     private $updatedAt;
  67.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  68.     private $deletedAt;
  69.     #[ORM\OneToMany(targetEntityCourseQuizQuestion::class, mappedBy'course')]
  70.     private $courseQuizQuestions;
  71.     #[ORM\OneToMany(targetEntityCourseUserEnrollment::class, mappedBy'course')]
  72.     private $courseUserEnrollments;
  73.     #[ORM\Column(type'boolean'options: ['default' => false])]
  74.     private $isPublished;
  75.     public function __construct()
  76.     {
  77.         $this->departments = new ArrayCollection();
  78.         $this->offices = new ArrayCollection();
  79.         $this->courseContents = new ArrayCollection();
  80.         $this->courseAutoEnrollments = new ArrayCollection();
  81.         $this->courseQuizQuestions = new ArrayCollection();
  82.         $this->courseUserEnrollments = new ArrayCollection();
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getTitle(): ?string
  89.     {
  90.         return $this->title;
  91.     }
  92.     public function setTitle(string $title): self
  93.     {
  94.         $this->title $title;
  95.         return $this;
  96.     }
  97.     public function getDescription(): ?string
  98.     {
  99.         return $this->description;
  100.     }
  101.     public function setDescription(?string $description): self
  102.     {
  103.         $this->description $description;
  104.         return $this;
  105.     }
  106.     public function getExcerpt(): ?string
  107.     {
  108.         return $this->excerpt;
  109.     }
  110.     public function setExcerpt(?string $excerpt): self
  111.     {
  112.         $this->excerpt $excerpt;
  113.         return $this;
  114.     }
  115.     public function getDuration(): ?int
  116.     {
  117.         return $this->duration;
  118.     }
  119.     public function setDuration(?int $duration): self
  120.     {
  121.         $this->duration $duration;
  122.         return $this;
  123.     }
  124.     public function getDueDay(): ?int
  125.     {
  126.         return $this->dueDay;
  127.     }
  128.     public function setDueDay(?int $dueDay): self
  129.     {
  130.         $this->dueDay $dueDay;
  131.         return $this;
  132.     }
  133.     public function getMinScore(): ?int
  134.     {
  135.         return $this->minScore;
  136.     }
  137.     public function setMinScore(?int $minScore): self
  138.     {
  139.         $this->minScore $minScore;
  140.         return $this;
  141.     }
  142.     public function getRandomizeOrder(): ?int
  143.     {
  144.         return $this->randomizeOrder;
  145.     }
  146.     public function setRandomizeOrder(?int $randomizeOrder): self
  147.     {
  148.         $this->randomizeOrder $randomizeOrder;
  149.         return $this;
  150.     }
  151.     public function getRandomizeQuestion(): ?int
  152.     {
  153.         return $this->randomizeQuestion;
  154.     }
  155.     public function setRandomizeQuestion(?int $randomizeQuestion): self
  156.     {
  157.         $this->randomizeQuestion $randomizeQuestion;
  158.         return $this;
  159.     }
  160.     public function getNeedApproval(): ?int
  161.     {
  162.         return $this->needApproval;
  163.     }
  164.     public function setNeedApproval(?int $needApproval): self
  165.     {
  166.         $this->needApproval $needApproval;
  167.         return $this;
  168.     }
  169.    /* 
  170.     public function getBypass(): ?int
  171.     {
  172.         return $this->bypass;
  173.     }
  174.     public function setBypass(?int $bypass): self
  175.     {
  176.         $this->bypass = $bypass;
  177.         return $this;
  178.     }
  179.     */
  180.     
  181.     public function getIsOnboarding(): ?int
  182.     {
  183.         return $this->isOnboarding;
  184.     }
  185.     public function setIsOnboarding(?int $isOnboarding): self
  186.     {
  187.         $this->isOnboarding $isOnboarding;
  188.         return $this;
  189.     }
  190.     public function getRetryInterval(): ?int
  191.     {
  192.         return $this->retryInterval;
  193.     }
  194.     public function setRetryInterval(?int $retryInterval): self
  195.     {
  196.         $this->retryInterval $retryInterval;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection|Department[]
  201.      */
  202.     public function getDepartments(): Collection
  203.     {
  204.         return $this->departments;
  205.     }
  206.     public function addDepartment(Department $department): self
  207.     {
  208.         if (!$this->departments->contains($department)) {
  209.             $this->departments[] = $department;
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeDepartment(Department $department): self
  214.     {
  215.         $this->departments->removeElement($department);
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection|Office[]
  220.      */
  221.     public function getOffices(): Collection
  222.     {
  223.         return $this->offices;
  224.     }
  225.     public function addOffice(Office $office): self
  226.     {
  227.         if (!$this->offices->contains($office)) {
  228.             $this->offices[] = $office;
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeOffice(Office $office): self
  233.     {
  234.         $this->offices->removeElement($office);
  235.         return $this;
  236.     }
  237.     public function getType(): ?string
  238.     {
  239.         return $this->type;
  240.     }
  241.     public function setType(?string $type): self
  242.     {
  243.         $this->type $type;
  244.         return $this;
  245.     }
  246.     public function getIsRequired(): ?bool
  247.     {
  248.         return $this->isRequired;
  249.     }
  250.     public function setIsRequired(?bool $isRequired): self
  251.     {
  252.         $this->isRequired $isRequired;
  253.         return $this;
  254.     }
  255.     public function getRoles(): ?array
  256.     {
  257.         return $this->roles;
  258.     }
  259.     public function setRoles(?array $roles): self
  260.     {
  261.         $this->roles $roles;
  262.         return $this;
  263.     }
  264.     public function getQuizTimer(): ?int
  265.     {
  266.         return $this->quizTimer;
  267.     }
  268.     public function setQuizTimer(?int $quizTimer): self
  269.     {
  270.         $this->quizTimer $quizTimer;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection|CourseContent[]
  275.      */
  276.     public function getCourseContent(): Collection
  277.     {
  278.         return $this->courseContents;
  279.     }
  280.     
  281.     public function getLevel(): ?string
  282.     {
  283.         return $this->level;
  284.     }
  285.     public function setLevel(?string $level): self
  286.     {
  287.         $this->level $level;
  288.         return $this;
  289.     }
  290.     public function addCreatedAt(CourseContent $courseContent): self
  291.     {
  292.         if (!$this->courseContents->contains($courseContent)) {
  293.             $this->courseContents[] = $courseContent;
  294.             $courseContent->setCourse($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function removeCreatedAt(CourseContent $courseContent): self
  299.     {
  300.         if ($this->courseContents->removeElement($courseContent)) {
  301.             // set the owning side to null (unless already changed)
  302.             if ($courseContent->getCourse() === $this) {
  303.                 $courseContent->setCourse(null);
  304.             }
  305.         }
  306.         return $this;
  307.     }
  308.     /**
  309.      * @return Collection|CourseAutoEnrollment[]
  310.      */
  311.     public function getCourseAutoEnrollments(): Collection
  312.     {
  313.         return $this->courseAutoEnrollments;
  314.     }
  315.     public function addCourseAutoEnrollment(CourseAutoEnrollment $CourseAutoEnrollment): self
  316.     {
  317.         if (!$this->courseAutoEnrollments->contains($CourseAutoEnrollment)) {
  318.             $this->courseAutoEnrollments[] = $CourseAutoEnrollment;
  319.             $CourseAutoEnrollment->setCourse($this);
  320.         }
  321.         return $this;
  322.     }
  323.     public function removeCourseAutoEnrollment(CourseAutoEnrollment $CourseAutoEnrollment): self
  324.     {
  325.         if ($this->courseAutoEnrollments->removeElement($CourseAutoEnrollment)) {
  326.             // set the owning side to null (unless already changed)
  327.             if ($CourseAutoEnrollment->getCourse() === $this) {
  328.                 $CourseAutoEnrollment->setCourse(null);
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * Get the latest CourseAutoEnrollment associated with this Course entity.
  335.      *
  336.      * @return CourseAutoEnrollment|null The latest CourseAutoEnrollment or null if none exists.
  337.      */
  338.     public function getLatestAutoEnrollment(): ?CourseAutoEnrollment
  339.     {
  340.         $latestAutoEnrollment null;
  341.         // Sort the course auto enrollments by createdAt in descending order
  342.         $sortedEnrollments $this->getCourseAutoEnrollments()->toArray();
  343.         usort($sortedEnrollments, function (CourseAutoEnrollment $aCourseAutoEnrollment $b) {
  344.             return $b->getCreatedAt() <=> $a->getCreatedAt();
  345.         });
  346.         // Get the first element from the sorted array (latest enrollment)
  347.         if (!empty($sortedEnrollments)) {
  348.             $latestAutoEnrollment reset($sortedEnrollments);
  349.         }
  350.         return $latestAutoEnrollment;
  351.     }
  352.     public function getCreatedAt(): ?\DateTimeImmutable
  353.     {
  354.         return $this->createdAt;
  355.     }
  356.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  357.     {
  358.         $this->createdAt $createdAt;
  359.         return $this;
  360.     }
  361.     public function getCreatedBy(): ?User
  362.     {
  363.         return $this->createdBy;
  364.     }
  365.     public function setCreatedBy(?User $createdBy): self
  366.     {
  367.         $this->createdBy $createdBy;
  368.         return $this;
  369.     }
  370.     public function getUpdatedAt(): ?\DateTimeImmutable
  371.     {
  372.         return $this->updatedAt;
  373.     }
  374.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  375.     {
  376.         $this->updatedAt $updatedAt;
  377.         return $this;
  378.     }
  379.     public function getDeletedAt(): ?\DateTimeImmutable
  380.     {
  381.         return $this->deletedAt;
  382.     }
  383.     public function setDeletedAt(?\DateTimeImmutable $deletedAt): self
  384.     {
  385.         $this->deletedAt $deletedAt;
  386.         return $this;
  387.     }
  388.     /**
  389.      * @return Collection|CourseQuizQuestion[]
  390.      */
  391.     public function getCourseQuizQuestions(): Collection
  392.     {
  393.         return $this->courseQuizQuestions;
  394.     }
  395.     public function addCourseQuizQuestion(CourseQuizQuestion $courseQuizQuestion): self
  396.     {
  397.         if (!$this->courseQuizQuestions->contains($courseQuizQuestion)) {
  398.             $this->courseQuizQuestions[] = $courseQuizQuestion;
  399.             $courseQuizQuestion->setCourse($this);
  400.         }
  401.         return $this;
  402.     }
  403.     public function removeCourseQuizQuestion(CourseQuizQuestion $courseQuizQuestion): self
  404.     {
  405.         if ($this->courseQuizQuestions->removeElement($courseQuizQuestion)) {
  406.             // set the owning side to null (unless already changed)
  407.             if ($courseQuizQuestion->getCourse() === $this) {
  408.                 $courseQuizQuestion->setCourse(null);
  409.             }
  410.         }
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return Collection|CourseUserEnrollment[]
  415.      */
  416.     public function getCourseUserEnrollments(): Collection
  417.     {
  418.         // return $this->courseUserEnrollments;
  419.         return $this->courseUserEnrollments->filter(function (CourseUserEnrollment $enrollment) {
  420.             return !$enrollment->isDeleted();
  421.         });
  422.     }
  423.     public function addCourseUserEnrollment(CourseUserEnrollment $courseUserEnrollment): self
  424.     {
  425.         if (!$this->courseUserEnrollments->contains($courseUserEnrollment)) {
  426.             $this->courseUserEnrollments[] = $courseUserEnrollment;
  427.             $courseUserEnrollment->setCourse($this);
  428.         }
  429.         return $this;
  430.     }
  431.     public function removeCourseUserEnrollment(CourseUserEnrollment $courseUserEnrollment): self
  432.     {
  433.         if ($this->courseUserEnrollments->removeElement($courseUserEnrollment)) {
  434.             // set the owning side to null (unless already changed)
  435.             if ($courseUserEnrollment->getCourse() === $this) {
  436.                 $courseUserEnrollment->setCourse(null);
  437.             }
  438.         }
  439.         return $this;
  440.     }
  441.     public function getCourseReady(): bool
  442.     {
  443.         if ($this->getCourseContent()->isEmpty()) {
  444.             return false;
  445.         }
  446.         if ($this->getCourseQuizQuestions()->isEmpty()) {
  447.             return false;
  448.         }
  449.         return true;
  450.     }
  451.     public function getIsPublished(): ?int
  452.     {
  453.         return $this->isPublished;
  454.     }
  455.     public function setIsPublished(?int $isPublished): self
  456.     {
  457.         $this->isPublished $isPublished;
  458.         return $this;
  459.     }
  460. }