<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\ElExamTranslation;
use App\Entity\Model\BulletPoint;
use App\Repository\ElExamRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\OrderMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Interfaces\ElCopyRestrictInterface;
use App\Entity\Interfaces\ContainerMappedInterface;
use App\Entity\Interfaces\NewsfeedCreatorInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Entity\Interfaces\OperationLogMappedInterface;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Interfaces\ElCourseIndexUpdateInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
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"={"ElExam:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"ElExam:Write"}},
* collectionOperations={
* "get"={"pagination_use_output_walkers"=true},
* "get_for_select"={
* "path"="/el_exams/get-for-select",
* "method"="GET",
* "normalization_context"={"groups"={"ElExam:Select"}, "skip_null_values"=false},
* "pagination_enabled"=false
* },
* "get_public"={
* "path"="/el_exams/get-public",
* "method"="GET",
* "normalization_context"={"groups"={"ElExam:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "get_my"={
* "path"="/el_exams/get-my",
* "method"="GET",
* "normalization_context"={"groups"={"ElExam:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')",
* "pagination_use_output_walkers"=true
* },
* "post"={
* "security"="is_granted('ROLE_OPERATOR') or is_granted('ROLE_INSTRUCTOR')"
* },
* "post_clone"={
* "route_name"="api_el_exams_clone_collection",
* "method"="POST",
* "denormalization_context"={"groups"={"ElExam:Clone"}}
* },
* "post_send_result"={
* "route_name"="api_el_exams_send_result_collection",
* "method"="POST",
* "denormalization_context"={"groups"={"ElExam:SendResult"}}
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('IS_AUTHENTICATED_FULLY', object)",
* "normalization_context"={"groups"={"ElExam:Read"}, "skip_null_values"=false}
* },
* "get_with_solution"={
* "path"="/el_exams/{id}/get-with-solution",
* "method"="GET",
* "security"="is_granted('IS_AUTHENTICATED_FULLY', object)",
* "normalization_context"={"groups"={"ElExam:Read", "ElExam:Read-Solution"}, "skip_null_values"=false}
* },
* "put"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object.elCourseAlways)"},
* "patch"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object.elCourseAlways)"},
* "patch_change_ord"={
* "path"="/el_exams/{id}/change-ord",
* "method"="PATCH",
* "denormalization_context"={"groups"={"ElExam:ChangeOrd", "ElExam:Move"}},
* "security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object.elCourseAlways)"
* },
* "delete"={"security"="is_granted('IS_CO_OPR', object) or is_granted('IS_CO_INS_SPE_COURSE', object.elCourseAlways)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "container.id": "exact", "elCourseAlways.id": "exact", "elCourse.id": "exact", "elLession.id": "exact", "elLesstionTopic.id": "exact", "elTask.id": "exact", "solutionType": "exact", "translations.title": "partial", "elExamTags.id": "exact", "examLevel": "exact"})
* @ApiFilter(BooleanFilter::class, properties={"isConsiderForPass"})
* @ApiFilter(DateFilter::class, properties={"start", "end"})
* @ApiFilter(OrderFilter::class, properties={"ord": "ASC", "translations.name", "id"})
* @ORM\Entity(repositoryClass=ElExamRepository::class)
*/
class ElExam extends AbstractTranslatable implements ContainerMappedInterface, OrderMappedInterface, ElCourseIndexUpdateInterface, NewsfeedCreatorInterface, OperationLogMappedInterface, ElCopyRestrictInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\OneToMany(targetEntity="ElExamTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
*
* @Groups({"ElExam:Write", "ElExamTranslationGroup", "ElCourse:Read", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read"})
* @Assert\Valid()
*/
protected $translations;
/**
* @Groups({"ElExam:Read", "ElCourse:Read", "ElLession:Detail", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read", "ElExam:Select", "Survey:Read"})
*/
private $title;
/**
* @Groups({"ElExam:Read"})
*/
private $description;
/**
* @Groups({"ElExam:Read"})
*/
private $instruction;
/**
* @Groups({"ElExam:Read-Solution"})
*/
private $uploadVideo;
/**
* @Groups({"ElExam:Read-Solution"})
*/
private $session;
/**
* @Groups({"ElExam:Read-Solution"})
*/
private $solutionDescription;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"ElExam:Read", "ElCourse:Read", "ElLession:Detail", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read", "ElExam:Select", "Survey:Read"})
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $passingPoint;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElCourse:Read", "ElLession:Detail", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read"})
*/
private $duration;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isShowLeaderBoard;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAllowShowSolution;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAllowShowResult;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAllowShowShortResult;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAllowReAttempt;
/**
* @ORM\Column(type="string", length=16, nullable=true)
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "enum"={self::SOLUTIONTYPE_DOCUMENT, self::SOLUTIONTYPE_VIDEO, self::SOLUTIONTYPE_SESSION}
* }
* }
* )
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $solutionType;
public const SOLUTIONTYPE_DOCUMENT = "DOCUMENT";
public const SOLUTIONTYPE_VIDEO = "VIDEO";
public const SOLUTIONTYPE_SESSION = "SESSION";
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"ElExam:Write"})
*/
private $container;
/**
* @ORM\ManyToOne(targetEntity=ElTask::class, inversedBy="elExams")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read", "ElExam:Clone", "ElExam:Move"})
*/
private $elTask;
/**
* @ORM\OneToMany(targetEntity=ElExamQuestion::class, mappedBy="elExam", orphanRemoval=true, cascade={"persist"})
*/
private $elExamQuestions;
/**
* @ORM\ManyToOne(targetEntity=ElLessionTopic::class, inversedBy="elExams")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read", "ElExam:Clone", "ElExam:Move"})
*/
private $elLesstionTopic;
/**
* @ORM\ManyToOne(targetEntity=ElLession::class, inversedBy="elExams")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read", "ElExam:Clone", "ElExam:Move"})
*/
private $elLession;
/**
* @ORM\ManyToOne(targetEntity=ElCourse::class, inversedBy="elExams")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read", "ElExam:Clone", "ElExam:Move"})
*/
private $elCourse;
/**
* @ORM\ManyToOne(targetEntity=ElCourse::class, inversedBy="elAllExams")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read", "ElExam:Clone"})
*/
public $elCourseAlways;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElLession:Detail", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read"})
*/
private $isConsiderForPass;
/**
* @ORM\Column(type="string", length=16)
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "enum"={self::EXAMLEVEL_TASK, self::EXAMLEVEL_LESSIONTOPIC, self::EXAMLEVEL_LESSION, self::EXAMLEVEL_COURSE}
* }
* }
* )
*
* @Groups({"ElExam:Read", "ElExam:Write", "ElExam:Clone", "ElExam:Move"})
*/
private $examLevel;
public const EXAMLEVEL_TASK = "TASK";
public const EXAMLEVEL_LESSIONTOPIC = "LESSIONTOPIC";
public const EXAMLEVEL_LESSION = "LESSION";
public const EXAMLEVEL_COURSE = "COURSE";
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElCourse:Read", "ElLession:Detail", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read", "ElTask:Get-Topic"})
*/
private $ord;
/**
* @ORM\ManyToMany(targetEntity=ElExamTag::class, inversedBy="elExams", cascade={"persist"})
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $elExamTags;
/**
* @ORM\OneToMany(targetEntity=ElExamAttempt::class, mappedBy="elExam", orphanRemoval=true)
*/
private $elExamAttempts;
/**
* @ORM\ManyToMany(targetEntity=DocFile::class)
* @Groups({"ElExam:Write", "ElExam:Read-Solution"})
*/
private $documents;
/**
* @Groups({"ElExam:ChangeOrd"})
*/
private int $newOrd;
private $ordChangeDirection;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElCourse:Read", "ElLession:Detail", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read"})
*/
private $start;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElCourse:Read", "ElLession:Detail", "ElLession:Read", "ElLessionTopic:Read", "ElTask:Read", "ElTask:Get-Topic", "ElExamAttempt:Read"})
*/
private $end;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $reminderBefore;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $reminderAfter;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isReminderBefore;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isReminderAfter;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAllowRandom;
/**
* @ORM\OneToMany(targetEntity=CommonComment::class, mappedBy="elExam")
*/
private $commonComments;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isCommentEnable;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isReviewEnable;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isShowPoints;
/**
* @Groups({"ElExam:Clone", "ElExam:SendResult"})
*/
private int $cloneId;
/**
* @ORM\ManyToMany(targetEntity=UserGroup::class)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $userGroups;
/**
* @ORM\Column(type="array", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $bulletPoints = [];
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write", "ElExamAttempt:Read"})
*/
private $isStepByStep;
/**
* @ORM\OneToMany(targetEntity=SurveyTrigger::class, mappedBy="elExam")
*/
private $surveyTriggers;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isAutoResultSend;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isOnlyChoiceQuestion;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ElExam:Read", "ElExam:Write"})
*/
private $isOnlyContinueOnPass;
public function __construct()
{
parent::__construct();
$this->elExamQuestions = new ArrayCollection();
$this->elExamTags = new ArrayCollection();
$this->elExamAttempts = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->commonComments = new ArrayCollection();
$this->userGroups = new ArrayCollection();
$this->surveyTriggers = new ArrayCollection();
$bulletPointModel = new BulletPoint();
$this->bulletPoints = $bulletPointModel->getProperties();
}
protected function createTranslation(): TranslationInterface
{
return new ElExamTranslation();
}
public function getTitle(): ?string
{
return $this->getTranslation()->getTitle();
}
public function setTitle(string $title): self
{
$this->getTranslation()->setTitle($title);
return $this;
}
public function getDescription(): ?string
{
return $this->getTranslation()->getDescription();
}
public function setDescription(string $description): self
{
$this->getTranslation()->setDescription($description);
return $this;
}
public function getInstruction(): ?string
{
return $this->getTranslation()->getInstruction();
}
public function setInstruction(string $instruction): self
{
$this->getTranslation()->setInstruction($instruction);
return $this;
}
public function getUploadVideo(): ?string
{
return $this->getTranslation()->getUploadVideo();
}
public function setUploadVideo(string $uploadVideo): self
{
$this->getTranslation()->setUploadVideo($uploadVideo);
return $this;
}
public function getSession()
{
return $this->getTranslation()->getSession();
}
public function setSession($session): self
{
$this->getTranslation()->setSession($session);
return $this;
}
public function getSolutionDescription(): ?string
{
return $this->getTranslation()->getSolutionDescription();
}
public function setSolutionDescription(string $solutionDescription): self
{
$this->getTranslation()->setSolutionDescription($solutionDescription);
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getPassingPoint(): ?int
{
return $this->passingPoint;
}
public function setPassingPoint(?int $passingPoint): self
{
$this->passingPoint = $passingPoint;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(?int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getIsShowLeaderBoard(): ?bool
{
return $this->isShowLeaderBoard;
}
public function setIsShowLeaderBoard(?bool $isShowLeaderBoard): self
{
$this->isShowLeaderBoard = $isShowLeaderBoard;
return $this;
}
public function getIsAllowShowSolution(): ?bool
{
return $this->isAllowShowSolution;
}
public function setIsAllowShowSolution(?bool $isAllowShowSolution): self
{
$this->isAllowShowSolution = $isAllowShowSolution;
return $this;
}
public function getIsAllowShowResult(): ?bool
{
return $this->isAllowShowResult;
}
public function setIsAllowShowResult(?bool $isAllowShowResult): self
{
$this->isAllowShowResult = $isAllowShowResult;
return $this;
}
public function getIsAllowShowShortResult(): ?bool
{
return $this->isAllowShowShortResult;
}
public function setIsAllowShowShortResult(?bool $isAllowShowShortResult): self
{
$this->isAllowShowShortResult = $isAllowShowShortResult;
return $this;
}
public function getIsAllowReAttempt(): ?bool
{
return $this->isAllowReAttempt;
}
public function setIsAllowReAttempt(?bool $isAllowReAttempt): self
{
$this->isAllowReAttempt = $isAllowReAttempt;
return $this;
}
public function getSolutionType(): ?string
{
return $this->solutionType;
}
public function setSolutionType(?string $solutionType): self
{
$this->solutionType = $solutionType;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getElTask(): ?ElTask
{
return $this->elTask;
}
public function setElTask(?ElTask $elTask): self
{
$this->elTask = $elTask;
return $this;
}
/**
* @return Collection|ElExamQuestion[]
*/
public function getElExamQuestions(): Collection
{
return $this->elExamQuestions;
}
public function addElExamQuestion(ElExamQuestion $elExamQuestion): self
{
if (!$this->elExamQuestions->contains($elExamQuestion)) {
$this->elExamQuestions[] = $elExamQuestion;
$elExamQuestion->setElExam($this);
}
return $this;
}
public function removeElExamQuestion(ElExamQuestion $elExamQuestion): self
{
if ($this->elExamQuestions->removeElement($elExamQuestion)) {
// set the owning side to null (unless already changed)
if ($elExamQuestion->getElExam() === $this) {
$elExamQuestion->setElExam(null);
}
}
return $this;
}
/**
* @Groups({"ElExam:Read"})
*/
public function getTotalElExamQuestions()
{
return count($this->elExamQuestions);
}
public function getElLesstionTopic(): ?ElLessionTopic
{
return $this->elLesstionTopic;
}
public function setElLesstionTopic(?ElLessionTopic $elLesstionTopic): self
{
$this->elLesstionTopic = $elLesstionTopic;
return $this;
}
public function getElLession(): ?ElLession
{
return $this->elLession;
}
public function setElLession(?ElLession $elLession): self
{
$this->elLession = $elLession;
return $this;
}
public function getElCourse(): ?ElCourse
{
return $this->elCourse;
}
public function setElCourse(?ElCourse $elCourse): self
{
$this->elCourse = $elCourse;
return $this;
}
public function getElCourseAlways(): ?ElCourse
{
return $this->elCourseAlways;
}
public function setElCourseAlways(?ElCourse $elCourseAlways): self
{
$this->elCourseAlways = $elCourseAlways;
return $this;
}
public function getIsConsiderForPass(): ?bool
{
return $this->isConsiderForPass;
}
public function setIsConsiderForPass(?bool $isConsiderForPass): self
{
$this->isConsiderForPass = $isConsiderForPass;
return $this;
}
public function getExamLevel(): ?string
{
return $this->examLevel;
}
public function setExamLevel(string $examLevel): self
{
$this->examLevel = $examLevel;
return $this;
}
public function getOrd(): ?int
{
return $this->ord;
}
public function setOrd(?int $ord): self
{
$this->ord = $ord;
return $this;
}
public function getOrdParents(): array
{
$parents = [
'container' => $this->getContainer()
];
if ($this->getExamLevel() === self::EXAMLEVEL_COURSE) {
$parents['elCourse'] = $this->getElCourse();
} elseif ($this->getExamLevel() === self::EXAMLEVEL_LESSION) {
$parents['elLession'] = $this->getElLession();
} elseif ($this->getExamLevel() === self::EXAMLEVEL_LESSIONTOPIC) {
$parents['elLesstionTopic'] = $this->getElLesstionTopic();
} elseif ($this->getExamLevel() === self::EXAMLEVEL_TASK) {
$parents['elTask'] = $this->getElTask();
}
return $parents;
}
public function getOrdChangeDirection()
{
return $this->ordChangeDirection;
}
/**
* @return Collection|ElExamTag[]
*/
public function getElExamTags(): Collection
{
return $this->elExamTags;
}
public function getTagsArray()
{
$tags = [];
foreach ($this->elExamTags as $tag) {
$tags[] = $tag->getName();
}
return $tags;
}
public function addElExamTag(ElExamTag $elExamTag): self
{
if (!$this->elExamTags->contains($elExamTag)) {
$this->elExamTags[] = $elExamTag;
}
return $this;
}
public function removeElExamTag(ElExamTag $elExamTag): self
{
$this->elExamTags->removeElement($elExamTag);
return $this;
}
public function reAttachTags(): self
{
$tags = $this->elExamTags;
foreach ($tags as $tag) {
$nt = clone $tag;
$nt->setContainer($this->getContainer());
$this->removeElExamTag($tag);
$this->addElExamTag($nt);
}
return $this;
}
/**
* @return Collection|ElExamAttempt[]
*/
public function getElExamAttempts(): Collection
{
return $this->elExamAttempts;
}
public function addElExamAttempt(ElExamAttempt $elExamAttempt): self
{
if (!$this->elExamAttempts->contains($elExamAttempt)) {
$this->elExamAttempts[] = $elExamAttempt;
$elExamAttempt->setElExam($this);
}
return $this;
}
public function removeElExamAttempt(ElExamAttempt $elExamAttempt): self
{
if ($this->elExamAttempts->removeElement($elExamAttempt)) {
// set the owning side to null (unless already changed)
if ($elExamAttempt->getElExam() === $this) {
$elExamAttempt->setElExam(null);
}
}
return $this;
}
/**
* @return Collection|DocFile[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(DocFile $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
}
return $this;
}
public function removeDocument(DocFile $document): self
{
$this->documents->removeElement($document);
return $this;
}
public function getClone(ElExam $source = null): self
{
if (empty($source)) {
$source = $this;
}
$target = new ElExam();
$target
->setPassingPoint($source->getPassingPoint())
->setDuration($source->getDuration())
->setIsShowLeaderBoard($source->getIsShowLeaderBoard())
->setIsAllowShowSolution($source->getIsAllowShowSolution())
->setIsAllowShowResult($source->getIsAllowShowResult())
->setIsAllowShowShortResult($source->getIsAllowShowShortResult())
->setIsAllowReAttempt($source->getIsAllowReAttempt())
->setSolutionType($source->getSolutionType())
->setContainer($source->getContainer())
->setElTask($source->getElTask())
->setElCourseAlways($source->getElCourseAlways())
->setIsConsiderForPass($source->getIsConsiderForPass())
->setExamLevel($source->getExamLevel())
->setStart($source->getElCourseAlways()->getAvailableStart())
->setEnd($source->getElCourseAlways()->getAvailableEnd())
;
foreach ($source->getTranslations() as $s) {
$newT = new ElExamTranslation();
$newT
->setTitle($s->getTitle())
->setDescription($s->getDescription())
->setInstruction($s->getInstruction())
->setUploadVideo($s->getUploadVideo())
->setSession($s->getSession())
->setSolutionDescription($s->getSolutionDescription())
->setLocale($s->getLocale())
;
$target->addTranslation($newT);
}
foreach ($source->getElExamTags() as $s) {
$target->addElExamTag($s);
}
foreach ($source->getDocuments() as $s) {
$target->addDocument($s);
}
foreach ($source->getElExamQuestions() as $s) {
$target->addElExamQuestion($s->getClone());
}
return $target;
}
public function getNewOrd(): int
{
return $this->newOrd ?? 0;
}
public function setNewOrd(int $newOrd): self
{
$oldOrd = $this->ord;
$this->newOrd = $newOrd;
$this->ord = $newOrd;
$this->ordChangeDirection = ($this->newOrd < $oldOrd) ? 'desc' : 'asc';
return $this;
}
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;
}
public function getReminderBefore(): ?int
{
return $this->reminderBefore;
}
public function setReminderBefore(?int $reminderBefore): self
{
$this->reminderBefore = $reminderBefore;
return $this;
}
public function getReminderAfter(): ?int
{
return $this->reminderAfter;
}
public function setReminderAfter(?int $reminderAfter): self
{
$this->reminderAfter = $reminderAfter;
return $this;
}
public function getIsReminderBefore(): ?bool
{
return $this->isReminderBefore;
}
public function setIsReminderBefore(?bool $isReminderBefore): self
{
$this->isReminderBefore = $isReminderBefore;
return $this;
}
public function getIsReminderAfter(): ?bool
{
return $this->isReminderAfter;
}
public function setIsReminderAfter(?bool $isReminderAfter): self
{
$this->isReminderAfter = $isReminderAfter;
return $this;
}
public function getIsAllowRandom(): ?bool
{
return $this->isAllowRandom;
}
public function setIsAllowRandom(?bool $isAllowRandom): self
{
$this->isAllowRandom = $isAllowRandom;
return $this;
}
public function getParentCourse()
{
return $this->elCourseAlways;
}
public function getForIndex()
{
$translations = [];
foreach ($this->getTranslations() as $translation) {
$translations[] = [
$translation->getLocale() => [
'title' => $translation->getTitle()
]
];
}
$data = [
'id' => $this->getId(),
'ord' => $this->getOrd(),
'examLevel' => $this->getExamLevel(),
'duration' => $this->getDuration(),
'isConsiderForPass' => $this->getIsConsiderForPass(),
'elCourseAlways' => $this->getElCourseAlways()->getId(),
];
$userGroups = [];
foreach ($this->getUserGroups() as $ug) {
$userGroups[] = $ug->getId();
}
$data['userGroups'] = $userGroups;
if ($this->getElTask()) {
$data['elTask'] = $this->getElTask()->getId();
}
if ($this->getElLesstionTopic()) {
$data['elLesstionTopic'] = $this->getElLesstionTopic()->getId();
}
if ($this->getElLession()) {
$data['elLession'] = $this->getElLession()->getId();
}
if ($this->getElCourse()) {
$data['elCourse'] = $this->getElCourse()->getId();
}
$data['translations'] = $translations;
return $data;
}
/**
* @return Collection|CommonComment[]
*/
public function getCommonComments(): Collection
{
return $this->commonComments;
}
public function addCommonComment(CommonComment $commonComment): self
{
if (!$this->commonComments->contains($commonComment)) {
$this->commonComments[] = $commonComment;
$commonComment->setElExam($this);
}
return $this;
}
public function removeCommonComment(CommonComment $commonComment): self
{
if ($this->commonComments->removeElement($commonComment)) {
// set the owning side to null (unless already changed)
if ($commonComment->getElExam() === $this) {
$commonComment->setElExam(null);
}
}
return $this;
}
public function getIsPostEnable()
{
return true;
}
public function getPostText()
{
$postText = [];
foreach ($this->getTranslations() as $translation) {
$postText[] = $translation->getTitle();
}
return implode('###', $postText);
}
public function getPostPoster()
{
return '';
}
public function getMetadataTranslation()
{
$translations = [];
foreach ($this->getTranslations() as $translation) {
$translations[] = [
$translation->getLocale() => [
'title' => $translation->getTitle(),
'description' => $translation->getDescription()
]
];
}
return $translations;
}
public function getPostMetadata()
{
$metadata = [
'elExam' => [
'id' => $this->getId(),
'translations' => $this->getMetadataTranslation(),
'examLevel' => $this->getExamLevel(),
'tags' => $this->getTagsArray()
],
'elCourseAlways' => [
'id' => $this->getElCourseAlways()->getId(),
'translations' => $this->getElCourseAlways()->getMetadataTranslation(),
'elCourseCategory' => $this->getElCourseAlways()->getElCourseCategory() ? $this->getElCourseAlways()->getElCourseCategory()->getMeta() : null,
]
];
switch ($this->getExamLevel()) {
case self::EXAMLEVEL_LESSIONTOPIC:
$metadata['elLessionTopic'] = [
'id' => $this->getElLessionTopic()->getId(),
'translations' => $this->getElLessionTopic()->getMetadataTranslation()
];
break;
case self::EXAMLEVEL_LESSION:
$metadata['elLession'] = [
'id' => $this->getElLession()->getId(),
'translations' => $this->getElLession()->getMetadataTranslation()
];
break;
case self::EXAMLEVEL_TASK:
$metadata['elTask'] = [
'id' => $this->getElTask()->getId(),
'translations' => $this->getElTask()->getMetadataTranslation()
];
break;
}
return $metadata;
}
public function getPostUserGroups()
{
return $this->getUserGroups();
}
public function getPostSource()
{
return CommonComment::SOURCE_ELEXAM;
}
public function getPostSubSource()
{
return '';
}
public function getIsCommentEnable(): ?bool
{
return $this->isCommentEnable;
}
public function setIsCommentEnable(?bool $isCommentEnable): self
{
$this->isCommentEnable = $isCommentEnable;
return $this;
}
public function getIsReviewEnable(): ?bool
{
return $this->isReviewEnable;
}
public function setIsReviewEnable(?bool $isReviewEnable): self
{
$this->isReviewEnable = $isReviewEnable;
return $this;
}
public function getIsShowPoints(): ?bool
{
return $this->isShowPoints;
}
public function setIsShowPoints(?bool $isShowPoints): self
{
$this->isShowPoints = $isShowPoints;
return $this;
}
public function getCloneId()
{
return $this->cloneId;
}
public function setCloneId($cloneId)
{
$this->cloneId = $cloneId;
return $this;
}
/**
* @return Collection<int, UserGroup>
*/
public function getUserGroups(): Collection
{
return $this->userGroups;
}
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;
}
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 isIsStepByStep(): ?bool
{
return $this->isStepByStep;
}
public function setIsStepByStep(?bool $isStepByStep): self
{
$this->isStepByStep = $isStepByStep;
return $this;
}
/**
* @return Collection|SurveyTrigger[]
*/
public function getSurveyTriggers(): Collection
{
return $this->surveyTriggers;
}
public function addSurveyTrigger(SurveyTrigger $surveyTrigger): self
{
if (!$this->surveyTriggers->contains($surveyTrigger)) {
$this->surveyTriggers[] = $surveyTrigger;
$surveyTrigger->setElExam($this);
}
return $this;
}
public function removeSurveyTrigger(SurveyTrigger $surveyTrigger): self
{
if ($this->surveyTriggers->removeElement($surveyTrigger)) {
// set the owning side to null (unless already changed)
if ($surveyTrigger->getElExam() === $this) {
$surveyTrigger->setElExam(null);
}
}
return $this;
}
/**
* @Groups({"ElExam:Read", "ElLession:Detail"})
*/
public function isSurvey(): bool
{
return $this->surveyTriggers?->count() > 0;
}
public function getIsAutoResultSend(): ?bool
{
return $this->isAutoResultSend;
}
public function setIsAutoResultSend(?bool $isAutoResultSend): self
{
$this->isAutoResultSend = $isAutoResultSend;
return $this;
}
public function getIsOnlyChoiceQuestion(): ?bool
{
return $this->isOnlyChoiceQuestion;
}
public function setIsOnlyChoiceQuestion(?bool $isOnlyChoiceQuestion): self
{
$this->isOnlyChoiceQuestion = $isOnlyChoiceQuestion;
return $this;
}
public function getIsOnlyContinueOnPass(): ?bool
{
return $this->isOnlyContinueOnPass;
}
public function setIsOnlyContinueOnPass(?bool $isOnlyContinueOnPass): self
{
$this->isOnlyContinueOnPass = $isOnlyContinueOnPass;
return $this;
}
}