<?php
namespace App\Entity;
use App\Annotation\EsUploadable;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Model\BulletPoint;
use App\Annotation\EsElasticIndex;
use App\Filter\SearchWithTagFilter;
use App\Filter\ElCourseArchiveFilter;
use App\Repository\ElCourseRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\UploadMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Interfaces\ElasticMappedInterface;
use App\Entity\Interfaces\ElCopyRestrictInterface;
use App\Entity\Interfaces\ContainerMappedInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Entity\Interfaces\OperationLogMappedInterface;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Interfaces\NewsfeedAssetCreatorInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use Symfony\Component\Serializer\Annotation\SerializedName;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_OPERATOR')", "filters"={"translation.groups"}},
* normalizationContext={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"ElCourse:Write"}},
* collectionOperations={
* "get"={"pagination_use_output_walkers"=true},
* "get_all"={
* "path"="/el_courses/get-all",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_use_output_walkers"=true
* },
* "get_for_instructor"={
* "path"="/el_courses/get-for-instructor",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* "security"="is_granted('ROLE_INSTRUCTOR')",
* "pagination_use_output_walkers"=true
* },
* "get_for_select"={
* "path"="/el_courses/get-for-select",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Select"}, "skip_null_values"=false},
* "pagination_enabled"=false
* },
* "get_for_copy"={
* "path"="/el_courses/get-for-copy",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Select"}, "skip_null_values"=false},
* "pagination_enabled"=false
* },
* "get_my"={
* "path"="/el_courses/get-my",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_use_output_walkers"=true
* },
* "get_user_course"={
* "path"="/el_courses/get-user-course",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_use_output_walkers"=true
* },
* "get_for_public_page"={
* "route_name"="api_pub_el_courses_get_for_public_page_collection",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"ElCourse:PRead"}, "skip_null_values"=false},
* "pagination_enabled"=true
* },
* "get_user_saved"={
* "path"="/el_courses/get-user-saved",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "post"={
* "security"="is_granted('ROLE_OPERATOR') or is_granted('ROLE_INSTRUCTOR')"
* },
* "post_certificate_prepare"={
* "route_name"="api_el_courses_certificate_prepare",
* "method"="POST",
* "denormalization_context"={"groups"={"ElCourse:Clone"}},
* },
* "post_certificate_send"={
* "route_name"="api_el_courses_certificate_send",
* "method"="POST",
* "denormalization_context"={"groups"={"ElCourse:Clone"}},
* },
* "post_reset_submissions"={
* "route_name"="api_el_courses_reset_submissions",
* "method"="POST",
* "denormalization_context"={"groups"={"ElCourse:Clone"}},
* "security"="is_granted('ROLE_ADMIN')"
* },
* "post_copy"={
* "route_name"="api_el_courses_copy",
* "method"="POST",
* "denormalization_context"={"groups"={"ElCourse:Copy"}}
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('IS_AUTHENTICATED_FULLY', object)",
* "normalization_context"={"groups"={"ElCourse:Read", "ElCourse:Detail"}, "skip_null_values"=false}
* },
* "get_detail"={
* "path"="/el_courses/{id}/get-detail",
* "method"="GET",
* "normalization_context"={"groups"={"ElCourse:Read", "ElCourse:Detail"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY', object)"
* },
* "get_for_public_item_page"={
* "route_name"="api_pub_el_courses_get_for_public_page_item",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"ElCourse:PRead", "ElCourse:PIRead"}, "skip_null_values"=false}
* },
* "put"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object)"},
* "patch"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object)"},
* "patch_start_course"={
* "route_name"="api_el_courses_start_course",
* "method"="PATCH",
* "security"="is_granted('IS_AUTHENTICATED_FULLY', object)",
* "denormalization_context"={"groups"={"ElCourse:Start-Course"}}
* },
* "delete"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "container.id": "exact", "elLessions.id": "exact", "elLessionTopics.id": "exact", "elTasks.id": "exact", "elCourseCategory.id": "exact", "elCourseTags.id": "exact", "speakers.id": "exact", "experts.id": "exact", "translations.name": "partial", "users.id": "exact", "elCourseJoins.user.id": "exact", "certificateTemplate.id": "exact", "instructor.id": "exact", "elCourseCredits.creditCategory.id": "exact", "companies.id": "exact"})
* @ApiFilter(SearchWithTagFilter::class, properties={"search_with_tag": "partial"})
* @ApiFilter(DateFilter::class, properties={"start", "end", "availableStart", "availableEnd"})
* @ApiFilter(BooleanFilter::class, properties={"isCertificate"})
* @ApiFilter(ElCourseArchiveFilter::class, properties={"is_archive"})
* @ApiFilter(OrderFilter::class, properties={"translations.name": "ASC", "id", "start", "end", "availableStart", "availableEnd"})
* @ApiFilter(RangeFilter::class, properties={"price", "averageRating", "totalRating", "duration"})
* @ApiFilter(ExistsFilter::class, properties={"price"})
* @ORM\Entity(repositoryClass=ElCourseRepository::class)
* @EsElasticIndex("ElCourse:EL")
*/
class ElCourse extends AbstractTranslatable implements ContainerMappedInterface, UploadMappedInterface, NewsfeedAssetCreatorInterface, OperationLogMappedInterface, ElasticMappedInterface, ElCopyRestrictInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\OneToMany(targetEntity="ElCourseTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
*
* @Groups({"ElCourse:EL", "ElCourse:Write", "ElCourseTranslationGroup", "ElCourse:PRead"})
* @Assert\Valid()
*/
protected $translations;
/**
* @Groups({"ElCourse:Select", "ElCourse:Read", "ElExam:Read", "ElTask:Read", "ElTask:Read-My", "ElExamAttempt:Read", "ElLessionTopic:Read", "ElCourseJoin:Read", "ElCourse:PRead", "ElTask:VideoGallery", "Certificate:Read", "CartItem:Read"})
*/
private $name;
/**
* @Groups({"ElCourse:Read", "ElCourse:PRead"})
*/
private $description;
/**
* @Groups({"ElCourse:Clone"})
*/
private int $cloneId;
/**
* @Groups({"ElCourse:Copy"})
*/
private string $copyType;
public const ELCOURSE_COPYTYPE_COURSE = "COURSE";
public const ELCOURSE_COPYTYPE_LESSION = "LESSION";
public const ELCOURSE_COPYTYPE_TOPIC = "TOPIC";
public const ELCOURSE_COPYTYPE_TASK = "TASK";
public const ELCOURSE_COPYTYPE_EXAM = "EXAM";
/**
* @Groups({"ElCourse:Copy"})
*/
private int $sourceId;
/**
* @Groups({"ElCourse:Copy"})
*/
private int $targetId;
/**
* @Groups({"ElCourse:Copy"})
*/
private ?string $copyLevel = null;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"ElCourse:EL", "ElCourse:Select", "ElCourse:Read", "ElExam:Read", "ElTask:Read", "ElExamAttempt:Read", "ElLessionTopic:Read", "ElCourseJoin:Read", "ElCourse:PRead", "ElTask:VideoGallery", "Certificate:Read", "CartItem:Read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Select", "ElCourse:Read", "ElCourse:Write", "ElCourse:PRead", "CartItem:Read"})
*
* @EsUploadable()
*/
protected $imageName;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $isRegistrationRequired;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElTask:Read", "ElExam:Read"})
*/
private $isStepByStepCompletion;
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"ElCourse:Write", "ElCourse:PRead", "ElCourse:Copy", "CartItem:Read"})
*/
private $container;
/**
* @ORM\ManyToOne(targetEntity=CommonCategory::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead"})
*/
private $elCourseCategory;
/**
* @ORM\ManyToMany(targetEntity=ElCourseTag::class, inversedBy="elCourses", cascade={"persist"})
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $elCourseTags;
/**
* @ORM\ManyToMany(targetEntity=UserGroup::class)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $userGroups;
/**
* @ORM\OneToMany(targetEntity=ElLession::class, mappedBy="elCourse", orphanRemoval=true)
* @Groups({"ElCourse:Detail", "ElCourse:PRead"})
*/
private $elLessions;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:PRead", "ElTask:VideoGallery"})
*/
private $start;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:PRead", "ElTask:VideoGallery"})
*/
private $end;
/**
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="rel_elcourse_speaker")
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:PRead"})
* @ORM\OrderBy({"lastName" = "ASC"})
*/
private $speakers;
/**
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="rel_elcourse_expert")
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:PRead"})
* @ORM\OrderBy({"lastName" = "ASC"})
*/
private $experts;
/**
* @ORM\OneToMany(targetEntity=ElLessionTopic::class, mappedBy="elCourse", orphanRemoval=true)
*/
private $elLessionTopics;
/**
* @ORM\OneToMany(targetEntity=ElTask::class, mappedBy="elCourse", orphanRemoval=true)
*/
private $elTasks;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:PRead"})
*/
private $duration;
/**
* @ORM\OneToMany(targetEntity=ElExam::class, mappedBy="elCourse")
*/
private $elExams;
/**
* @ORM\OneToMany(targetEntity=ElExam::class, mappedBy="elCourseAlways", orphanRemoval=true)
*/
private $elAllExams;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="elCourses")
*/
private $users;
/**
* @ORM\OneToMany(targetEntity=ElCourseJoin::class, mappedBy="elCourse", orphanRemoval=true)
*/
private $elCourseJoins;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $isActive;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:Write", "ElTask:Read", "ElExam:Read", "ElCourse:PRead"})
*/
private $availableStart;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:Write", "ElTask:Read", "ElExam:Read", "ElCourse:PRead"})
*/
private $availableEnd;
/**
* @ORM\Column(type="json", nullable=true)
* @Groups({"ElCourse:Detail", "ElTask:Read", "ElExam:Read", "ElCourse:PIRead"})
*/
private $courseIndex = [];
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $isShowPublic;
/**
* @ORM\Column(type="array", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:Write", "ElCourse:PRead"})
*/
private $bulletPoints = [];
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $isCertificate;
/**
* @ORM\ManyToOne(targetEntity=CertificateTemplate::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $certificateTemplate;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElCourse:EL", "ElCourse:Read", "ElCourse:Write"})
*/
private $isShowDate;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write"})
*/
private $certificateProgress;
/**
* @ORM\OneToMany(targetEntity=ElCourseCredit::class, mappedBy="elCourse", orphanRemoval=true, cascade={"persist"})
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead"})
*/
private $elCourseCredits;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead", "CartItem:Read"})
*/
private $instructor;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead", "CartItem:Read"})
*/
private $originalPrice;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead", "CartItem:Read"})
*/
private $price;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:PRead", "CartItem:Read"})
*/
private $totalRating;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
* @Groups({"ElCourse:Read", "ElCourse:PRead", "CartItem:Read"})
*/
private $averageRating;
/**
* @ORM\OneToMany(targetEntity=ElCourseRating::class, mappedBy="elCourse", orphanRemoval=true)
*/
private $elCourseRatings;
/**
* @ORM\OneToMany(targetEntity=ElCourseSaved::class, mappedBy="elCourse")
*/
private $elCourseSaved;
/**
* @ORM\ManyToMany(targetEntity=Company::class)
* @Groups({"ElCourse:Read", "ElCourse:Write", "ElCourse:PRead"})
*/
private $companies;
public function __construct()
{
parent::__construct();
$this->elCourseTags = new ArrayCollection();
$this->userGroups = new ArrayCollection();
$this->elLessions = new ArrayCollection();
$this->speakers = new ArrayCollection();
$this->experts = new ArrayCollection();
$this->elLessionTopics = new ArrayCollection();
$this->elTasks = new ArrayCollection();
$this->elExams = new ArrayCollection();
$this->elAllExams = new ArrayCollection();
$this->users = new ArrayCollection();
$this->elCourseJoins = new ArrayCollection();
$bulletPointModel = new BulletPoint();
$this->bulletPoints = $bulletPointModel->getProperties();
$this->elCourseCredits = new ArrayCollection();
$this->elCourseRatings = new ArrayCollection();
$this->elCourseSaved = new ArrayCollection();
$this->companies = new ArrayCollection();
}
protected function createTranslation(): TranslationInterface
{
return new ElCourseTranslation();
}
public function addTranslation(TranslationInterface $translation): void
{
$this->setUpdatedAt(new \DateTime());
parent::addTranslation($translation);
}
public function getName(): ?string
{
return $this->getTranslation()->getName();
}
public function setName(string $name): self
{
$this->getTranslation()->setName($name);
return $this;
}
public function getDescription(): ?string
{
return $this->getTranslation()->getDescription();
}
public function setDescription(string $description): self
{
$this->getTranslation()->setDescription($description);
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): self
{
$this->imageName = $imageName;
return $this;
}
public function getIsRegistrationRequired(): ?bool
{
return $this->isRegistrationRequired;
}
public function setIsRegistrationRequired(?bool $isRegistrationRequired): self
{
$this->isRegistrationRequired = $isRegistrationRequired;
return $this;
}
public function getIsStepByStepCompletion(): ?bool
{
return $this->isStepByStepCompletion;
}
public function setIsStepByStepCompletion(?bool $isStepByStepCompletion): self
{
$this->isStepByStepCompletion = $isStepByStepCompletion;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getElCourseCategory(): ?CommonCategory
{
return $this->elCourseCategory;
}
public function setElCourseCategory(?CommonCategory $elCourseCategory): self
{
$this->elCourseCategory = $elCourseCategory;
return $this;
}
/**
* @return Collection|ElCourseTag[]
*/
public function getElCourseTags(): Collection
{
return $this->elCourseTags;
}
/**
* @Groups({"ElCourse:EL"})
* @SerializedName("tags")
*/
public function getTagsArray()
{
$tags = [];
foreach ($this->elCourseTags as $tag) {
$tags[] = $tag->getName();
}
return $tags;
}
public function addElCourseTag(ElCourseTag $elCourseTag): self
{
if (!$this->elCourseTags->contains($elCourseTag)) {
$this->elCourseTags[] = $elCourseTag;
}
return $this;
}
public function removeElCourseTag(ElCourseTag $elCourseTag): self
{
$this->elCourseTags->removeElement($elCourseTag);
return $this;
}
public function reAttachTags(): self
{
$tags = $this->elCourseTags;
foreach ($tags as $tag) {
$nt = clone $tag;
$nt->setContainer($this->getContainer());
$this->removeElCourseTag($tag);
$this->addElCourseTag($nt);
}
return $this;
}
/**
* @return Collection|UserGroup[]
*/
public function getUserGroups(): Collection
{
return $this->userGroups;
}
/**
* @Groups({"ElCourse:EL"})
* @SerializedName("groups")
*/
public function getUserGroupsArray()
{
$groups = [];
foreach ($this->userGroups as $group) {
if (!$group->getIsGenerated()) {
$groups[] = $group->getId();
}
}
return $groups;
}
public function addUserGroup(UserGroup $userGroup): self
{
if (!$this->userGroups->contains($userGroup)) {
$this->userGroups[] = $userGroup;
}
return $this;
}
public function removeUserGroup(UserGroup $userGroup): self
{
$this->userGroups->removeElement($userGroup);
return $this;
}
public function removeAllUserGroups(): self
{
foreach ($this->userGroups as $userGroup) {
$this->removeUserGroup($userGroup);
}
return $this;
}
/**
* @return Collection|ElLession[]
*/
public function getElLessions(): Collection
{
return $this->elLessions;
}
public function addElLession(ElLession $elLession): self
{
if (!$this->elLessions->contains($elLession)) {
$this->elLessions[] = $elLession;
$elLession->setElCourse($this);
}
return $this;
}
public function removeElLession(ElLession $elLession): self
{
if ($this->elLessions->removeElement($elLession)) {
// set the owning side to null (unless already changed)
if ($elLession->getElCourse() === $this) {
$elLession->setElCourse(null);
}
}
return $this;
}
/**
* @Groups({"ElCourse:Read"})
*/
public function getTotalElLessions()
{
if (empty($this->elLessions)) {
return 0;
}
return count($this->elLessions);
}
/**
* @Groups({"ElCourse:PRead"})
*/
public function getTotalElTasks()
{
if (empty($this->elTasks)) {
return 0;
}
return count($this->elTasks);
}
/**
* @Groups({"ElCourse:PRead"})
*/
public function getTotalElExams()
{
if (empty($this->elAllExams)) {
return 0;
}
return count($this->elAllExams);
}
public function getStart(): ?\DateTimeInterface
{
return $this->start;
}
public function setStart(?\DateTimeInterface $start): self
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTimeInterface
{
return $this->end;
}
public function setEnd(?\DateTimeInterface $end): self
{
$this->end = $end;
return $this;
}
/**
* @return Collection|User[]
*/
public function getSpeakers(): Collection
{
return $this->speakers;
}
public function addSpeaker(User $speaker): self
{
if (!$this->speakers->contains($speaker)) {
$this->speakers[] = $speaker;
}
return $this;
}
public function removeSpeaker(User $speaker): self
{
$this->speakers->removeElement($speaker);
return $this;
}
public function removeAllSpeakers(): self
{
$speakers = $this->getSpeakers();
foreach ($speakers as $speaker) {
$this->removeSpeaker($speaker);
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getExperts(): Collection
{
return $this->experts;
}
public function addExpert(User $expert): self
{
if (!$this->experts->contains($expert)) {
$this->experts[] = $expert;
}
return $this;
}
public function removeExpert(User $expert): self
{
$this->experts->removeElement($expert);
return $this;
}
public function removeAllExperts(): self
{
$experts = $this->getExperts();
foreach ($experts as $expert) {
$this->removeExpert($expert);
}
return $this;
}
/**
* @return Collection|ElLessionTopic[]
*/
public function getElLessionTopics(): Collection
{
return $this->elLessionTopics;
}
public function addElLessionTopic(ElLessionTopic $elLessionTopic): self
{
if (!$this->elLessionTopics->contains($elLessionTopic)) {
$this->elLessionTopics[] = $elLessionTopic;
$elLessionTopic->setElCourse($this);
}
return $this;
}
public function removeElLessionTopic(ElLessionTopic $elLessionTopic): self
{
if ($this->elLessionTopics->removeElement($elLessionTopic)) {
// set the owning side to null (unless already changed)
if ($elLessionTopic->getElCourse() === $this) {
$elLessionTopic->setElCourse(null);
}
}
return $this;
}
/**
* @return Collection|ElTask[]
*/
public function getElTasks(): Collection
{
return $this->elTasks;
}
public function addElTask(ElTask $elTask): self
{
if (!$this->elTasks->contains($elTask)) {
$this->elTasks[] = $elTask;
$elTask->setElCourse($this);
}
return $this;
}
public function removeElTask(ElTask $elTask): self
{
if ($this->elTasks->removeElement($elTask)) {
// set the owning side to null (unless already changed)
if ($elTask->getElCourse() === $this) {
$elTask->setElCourse(null);
}
}
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(?int $duration): self
{
$this->duration = $duration;
return $this;
}
/**
* @return Collection|ElExam[]
*/
public function getElExams(): Collection
{
return $this->elExams;
}
public function addElExam(ElExam $elExam): self
{
if (!$this->elExams->contains($elExam)) {
$this->elExams[] = $elExam;
$elExam->setElCourse($this);
}
return $this;
}
public function removeElExam(ElExam $elExam): self
{
if ($this->elExams->removeElement($elExam)) {
// set the owning side to null (unless already changed)
if ($elExam->getElCourse() === $this) {
$elExam->setElCourse(null);
}
}
return $this;
}
/**
* @return Collection|ElExam[]
*/
public function getElAllExams(): Collection
{
return $this->elAllExams;
}
public function addElAllExam(ElExam $elAllExam): self
{
if (!$this->elAllExams->contains($elAllExam)) {
$this->elAllExams[] = $elAllExam;
$elAllExam->setElCourseAlways($this);
}
return $this;
}
public function removeElAllExam(ElExam $elAllExam): self
{
if ($this->elAllExams->removeElement($elAllExam)) {
// set the owning side to null (unless already changed)
if ($elAllExam->getElCourseAlways() === $this) {
$elAllExam->setElCourseAlways(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeUser(User $user): self
{
$this->users->removeElement($user);
return $this;
}
/**
* @return Collection|ElCourseJoin[]
*/
public function getElCourseJoins(): Collection
{
return $this->elCourseJoins;
}
public function addElCourseJoin(ElCourseJoin $elCourseJoin): self
{
if (!$this->elCourseJoins->contains($elCourseJoin)) {
$this->elCourseJoins[] = $elCourseJoin;
$elCourseJoin->setElCourse($this);
}
return $this;
}
public function removeElCourseJoin(ElCourseJoin $elCourseJoin): self
{
if ($this->elCourseJoins->removeElement($elCourseJoin)) {
// set the owning side to null (unless already changed)
if ($elCourseJoin->getElCourse() === $this) {
$elCourseJoin->setElCourse(null);
}
}
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getAvailableStart(): ?\DateTimeInterface
{
return $this->availableStart;
}
public function setAvailableStart(?\DateTimeInterface $availableStart): self
{
$this->availableStart = $availableStart;
return $this;
}
public function getAvailableEnd(): ?\DateTimeInterface
{
return $this->availableEnd;
}
public function setAvailableEnd(?\DateTimeInterface $availableEnd): self
{
$this->availableEnd = $availableEnd;
return $this;
}
public function getCourseIndex(): ?array
{
return $this->courseIndex;
}
public function setCourseIndex(?array $courseIndex): self
{
$this->courseIndex = $courseIndex;
return $this;
}
/**
* @Groups({"ElCourse:Read"})
*/
public function getCurrentTime()
{
return new \DateTime();
}
/**
* @Groups({"ElCourse:Read"})
*/
public function getIsArchive()
{
if ($this->getAvailableEnd() && $this->getCurrentTime() > $this->getAvailableEnd()) {
return true;
}
return false;
}
public function getIsShowPublic(): ?bool
{
return $this->isShowPublic;
}
public function setIsShowPublic(?bool $isShowPublic): self
{
$this->isShowPublic = $isShowPublic;
return $this;
}
public function getBulletPoints(): ?array
{
if ($this->bulletPoints === null) {
$this->bulletPoints = [];
}
return $this->bulletPoints;
}
public function setBulletPoints(?array $bulletPoints): self
{
if (!is_array($bulletPoints)) {
return $this;
}
$this->bulletPoints = $bulletPoints;
return $this;
}
public function getAllBulletPoints($locale = 'en')
{
$bp = [];
foreach ($this->bulletPoints as $c) {
if (isset($c['translations'])) {
foreach ($c['translations'] as $t) {
if ($t['locale'] === $locale) {
$bp[] = $t['info'];
}
}
}
}
return implode('</br>', $bp);
}
public function getIsCertificate(): ?bool
{
return $this->isCertificate;
}
public function setIsCertificate(?bool $isCertificate): self
{
$this->isCertificate = $isCertificate;
return $this;
}
public function getCertificateTemplate(): ?CertificateTemplate
{
return $this->certificateTemplate;
}
public function setCertificateTemplate(?CertificateTemplate $certificateTemplate): self
{
$this->certificateTemplate = $certificateTemplate;
return $this;
}
public function getCloneId()
{
return $this->cloneId;
}
public function setCloneId($cloneId)
{
$this->cloneId = $cloneId;
return $this;
}
public function getIsPostEnable()
{
return true;
}
public function getPostPoster()
{
return $this->getImageName();
}
public function getMetadataTranslation()
{
$translations = [];
foreach ($this->getTranslations() as $translation) {
$translations[] = [
$translation->getLocale() => [
'title' => $translation->getName(),
'description' => $translation->getDescription()
]
];
}
return $translations;
}
public function getPostMetadata()
{
return [
'elCourse' => [
'id' => $this->getId(),
'translations' => $this->getMetadataTranslation(),
'tags' => $this->getTagsArray(),
'elCourseCategory' => $this->getElCourseCategory() ? $this->getElCourseCategory()->getMeta() : null
]
];
}
public function getPostUserGroups()
{
return $this->getUserGroups();
}
public function getPostSubSource()
{
return Newsfeed::POSTSUBTYPE_ELCOURSE;
}
/**
* Get the value of copyType
*/
public function getCopyType()
{
return $this->copyType;
}
/**
* Set the value of copyType
*
* @return self
*/
public function setCopyType($copyType)
{
$this->copyType = $copyType;
return $this;
}
/**
* Get the value of sourceId
*/
public function getSourceId()
{
return $this->sourceId;
}
/**
* Set the value of sourceId
*
* @return self
*/
public function setSourceId($sourceId)
{
$this->sourceId = $sourceId;
return $this;
}
/**
* Get the value of targetId
*/
public function getTargetId()
{
return $this->targetId;
}
/**
* Set the value of targetId
*
* @return self
*/
public function setTargetId($targetId)
{
$this->targetId = $targetId;
return $this;
}
/**
* Get the value of copyLevel
*/
public function getCopyLevel(): ?string
{
return $this->copyLevel;
}
/**
* Set the value of copyLevel
*
* @return self
*/
public function setCopyLevel(?string $copyLevel)
{
$this->copyLevel = $copyLevel;
return $this;
}
public function isIsShowDate(): ?bool
{
return $this->isShowDate;
}
public function setIsShowDate(?bool $isShowDate): self
{
$this->isShowDate = $isShowDate;
return $this;
}
public function getCertificateProgress(): ?int
{
return $this->certificateProgress;
}
public function setCertificateProgress(?int $certificateProgress): self
{
$this->certificateProgress = $certificateProgress;
return $this;
}
/**
* @Groups({"ElCourse:EL"})
*/
public function getCntId()
{
return $this->container->getId();
}
/**
* @Groups({"ElCourse:EL"})
*/
public function getCategory()
{
return $this->getElCourseCategory();
}
/**
* @return Collection<int, ElCourseCredit>
*/
public function getElCourseCredits(): Collection
{
return $this->elCourseCredits;
}
public function addElCourseCredit(ElCourseCredit $elCourseCredit): self
{
if (!$this->elCourseCredits->contains($elCourseCredit)) {
$this->elCourseCredits[] = $elCourseCredit;
$elCourseCredit->setElCourse($this);
}
return $this;
}
public function removeElCourseCredit(ElCourseCredit $elCourseCredit): self
{
// if ($this->elCourseCredits->removeElement($elCourseCredit)) {
// // set the owning side to null (unless already changed)
// if ($elCourseCredit->getElCourse() === $this) {
// $elCourseCredit->setElCourse(null);
// }
// }
$this->elCourseCredits->removeElement($elCourseCredit);
return $this;
}
public function getTotalCredit()
{
$total = 0.0;
foreach ($this->elCourseCredits as $c) {
$total += (float) $c->getCreditPoint();
}
return $total;
}
public function getAllCredit()
{
$allCredit = [];
foreach ($this->elCourseCredits as $c) {
$allCredit[] = $c->getCreditCategory()->getName().': '.$c->getCreditPoint();
}
return implode('</br>', $allCredit);
}
public function getInstructor(): ?User
{
return $this->instructor;
}
public function setInstructor(?User $instructor): self
{
$this->instructor = $instructor;
return $this;
}
public function getOriginalPrice(): ?string
{
return $this->originalPrice;
}
public function setOriginalPrice(?string $originalPrice): self
{
$this->originalPrice = $originalPrice;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(?string $price): self
{
$this->price = $price;
return $this;
}
public function getTotalRating(): ?int
{
return $this->totalRating;
}
public function setTotalRating(?int $totalRating): self
{
$this->totalRating = $totalRating;
return $this;
}
public function getAverageRating(): ?string
{
return $this->averageRating;
}
public function setAverageRating(?string $averageRating): self
{
$this->averageRating = $averageRating;
return $this;
}
/**
* @return Collection<int, ElCourseRating>
*/
public function getElCourseRatings(): Collection
{
return $this->elCourseRatings;
}
public function addElCourseRating(ElCourseRating $elCourseRating): self
{
if (!$this->elCourseRatings->contains($elCourseRating)) {
$this->elCourseRatings[] = $elCourseRating;
$elCourseRating->setElCourse($this);
}
return $this;
}
public function removeElCourseRating(ElCourseRating $elCourseRating): self
{
if ($this->elCourseRatings->removeElement($elCourseRating)) {
// set the owning side to null (unless already changed)
if ($elCourseRating->getElCourse() === $this) {
$elCourseRating->setElCourse(null);
}
}
return $this;
}
/**
* @return Collection<int, ElCourseSaved>
*/
public function getElCourseSaved(): Collection
{
return $this->elCourseSaved;
}
public function addElCourseSaved(ElCourseSaved $elCourseSaved): self
{
if (!$this->elCourseSaved->contains($elCourseSaved)) {
$this->elCourseSaved[] = $elCourseSaved;
$elCourseSaved->setElCourse($this);
}
return $this;
}
public function removeElCourseSaved(ElCourseSaved $elCourseSaved): self
{
if ($this->elCourseSaved->removeElement($elCourseSaved)) {
// set the owning side to null (unless already changed)
if ($elCourseSaved->getElCourse() === $this) {
$elCourseSaved->setElCourse(null);
}
}
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
}
return $this;
}
public function removeCompany(Company $company): self
{
$this->companies->removeElement($company);
return $this;
}
}