<?php
namespace App\Entity\Gos\Uniqskills;
use App\Entity\Gos\CertificatePath;
use App\Entity\Gos\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\TestRepository")
* @ORM\HasLifecycleCallbacks
*/
class Test
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $isOneQuestionPerPage;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=191, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="string")
*/
private $type;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $share;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateStart;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $shareDays;
/**
* @ORM\Column(type="float")
*/
private $pointsGoodAnswer;
/**
* @ORM\Column(type="float")
*/
private $pointsWrongAnswer;
/**
* @ORM\Column(type="float")
*/
private $minimumScore;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $educationPointsPerScorePoint;
/**
* @ORM\Column(type="integer")
*/
private $numberRepetitions;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $infiniteRepeatTest;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $timeToRepeatTest;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
/**
* @ORM\OneToOne(targetEntity="Module", inversedBy="test")
* @ORM\JoinColumn(name="module_id", referencedColumnName="id", onDelete="cascade")
*/
private $module;
/**
* @ORM\ManyToOne(targetEntity="Course", inversedBy="test")
* @ORM\JoinColumn(name="course_id", referencedColumnName="id", onDelete="cascade")
*/
private $course;
/**
* @ORM\OneToMany(targetEntity="Question", mappedBy="test")
*/
private $question;
/**
* @ORM\OneToMany(targetEntity="UserTest", mappedBy="test")
*/
private $userTest;
/**
* @ORM\OneToMany(targetEntity="UserAnswer", mappedBy="test")
*/
private $userAnswer;
// /**
// * @ORM\OneToOne(targetEntity="Certificate", mappedBy="test")
// */
// private $certificate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\User", inversedBy="test")
* @ORM\JoinColumn()
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=CertificatePath::class, mappedBy="test")
*/
private $certificatePaths;
public function __construct()
{
$this->question = new ArrayCollection();
$this->userTest = new ArrayCollection();
$this->userAnswer = new ArrayCollection();
$this->certificatePaths = new ArrayCollection();
}
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return (string) $this->name;
}
public function isCompletedTestByUser($user)
{
if (!$this->hasQuestions())
{
return true;
}
foreach ($this->userTest as $userTest)
{
if ($userTest->getUser() && $userTest->getUser()->getId() == $user->getId())
{
return true;
}
}
return false;
}
public function canUserRepeatTest($user)
{
if ($this->infiniteRepeatTest && $this->hasQuestions())
{
return true;
}
if ($this->numberRepetitions > 0 && $this->hasQuestions())
{
foreach ($this->userTest as $userTest)
{
if ($userTest->getUser() && $userTest->getUser()->getId() == $user->getId())
{
$date = (new \DateTime())->format('U');
$userTestTime = $userTest->getCreatedAt()->format('U');
if (
(
($date - $userTestTime) / 3600 > $this->timeToRepeatTest
)
&& $userTest->getSumCompleted() <= $this->numberRepetitions
)
{
return true;
}
}
}
}
return false;
}
public function getClientTestByUser($user)
{
foreach ($this->userTest as $userTest)
{
if ($userTest->getUser() && $userTest->getUser()->getId() == $user->getId())
{
return $userTest;
}
}
return null;
}
public function hasOpenQuestions()
{
foreach ($this->question as $question)
{
if (count($question->getAnswer()) === 0)
{
return true;
}
}
return false;
}
public function __clone()
{
$this->id = null;
$this->updatedAt = null;
}
public function getId(): ?int
{
return $this->id;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getIsOneQuestionPerPage(): ?bool
{
return $this->isOneQuestionPerPage;
}
public function setIsOneQuestionPerPage(bool $isOneQuestionPerPage): self
{
$this->isOneQuestionPerPage = $isOneQuestionPerPage;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getShare(): ?string
{
return $this->share;
}
public function setShare(string $share): self
{
$this->share = $share;
return $this;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart(?\DateTimeInterface $dateStart): self
{
$this->dateStart = $dateStart;
return $this;
}
public function getShareDays(): ?int
{
return $this->shareDays;
}
public function setShareDays(?int $shareDays): self
{
$this->shareDays = $shareDays;
return $this;
}
public function getPointsGoodAnswer(): ?float
{
return $this->pointsGoodAnswer;
}
public function setPointsGoodAnswer(float $pointsGoodAnswer): self
{
$this->pointsGoodAnswer = $pointsGoodAnswer;
return $this;
}
public function getPointsWrongAnswer(): ?float
{
return $this->pointsWrongAnswer;
}
public function setPointsWrongAnswer(float $pointsWrongAnswer): self
{
$this->pointsWrongAnswer = $pointsWrongAnswer;
return $this;
}
public function getMinimumScore(): ?float
{
return $this->minimumScore;
}
public function setMinimumScore(float $minimumScore): self
{
$this->minimumScore = $minimumScore;
return $this;
}
public function getEducationPointsPerScorePoint(): ?float
{
return $this->educationPointsPerScorePoint;
}
public function setEducationPointsPerScorePoint(?float $educationPointsPerScorePoint): self
{
$this->educationPointsPerScorePoint = $educationPointsPerScorePoint;
return $this;
}
public function getNumberRepetitions(): ?int
{
return $this->numberRepetitions;
}
public function setNumberRepetitions(int $numberRepetitions): self
{
$this->numberRepetitions = $numberRepetitions;
return $this;
}
public function getInfiniteRepeatTest(): ?bool
{
return $this->infiniteRepeatTest;
}
public function setInfiniteRepeatTest(?bool $infiniteRepeatTest): self
{
$this->infiniteRepeatTest = $infiniteRepeatTest;
return $this;
}
public function getTimeToRepeatTest(): ?int
{
return $this->timeToRepeatTest;
}
public function setTimeToRepeatTest(?int $timeToRepeatTest): self
{
$this->timeToRepeatTest = $timeToRepeatTest;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getModule(): ?Module
{
return $this->module;
}
public function setModule(?Module $module): self
{
$this->module = $module;
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function getCourseName(): string
{
if ($this->getCourse())
{
return $this->getCourse()->getName();
}
elseif ($this->getModule())
{
return $this->getModule()->getCourse()->getName();
}
return '';
}
public function setCourse(?Course $course): self
{
$this->course = $course;
return $this;
}
/**
* @return Collection|Question[]
*/
public function getQuestion(): Collection
{
return $this->question;
}
public function hasQuestions(): bool
{
return !$this->getQuestion()->isEmpty();
}
public function addQuestion(Question $question): self
{
if (!$this->question->contains($question)) {
$this->question[] = $question;
$question->setTest($this);
}
return $this;
}
public function removeQuestion(Question $question): self
{
if ($this->question->contains($question)) {
$this->question->removeElement($question);
// set the owning side to null (unless already changed)
if ($question->getTest() === $this) {
$question->setTest(null);
}
}
return $this;
}
/**
* @return Collection|UserTest[]
*/
public function getUserTest(): Collection
{
return $this->userTest;
}
public function addUserTest(UserTest $userTest): self
{
if (!$this->userTest->contains($userTest)) {
$this->userTest[] = $userTest;
$userTest->setTest($this);
}
return $this;
}
public function removeUserTest(UserTest $userTest): self
{
if ($this->userTest->contains($userTest)) {
$this->userTest->removeElement($userTest);
// set the owning side to null (unless already changed)
if ($userTest->getTest() === $this) {
$userTest->setTest(null);
}
}
return $this;
}
/**
* @return Collection|UserAnswer[]
*/
public function getUserAnswer(): Collection
{
return $this->userAnswer;
}
public function addUserAnswer(UserAnswer $userAnswer): self
{
if (!$this->userAnswer->contains($userAnswer)) {
$this->userAnswer[] = $userAnswer;
$userAnswer->setTest($this);
}
return $this;
}
public function removeUserAnswer(UserAnswer $userAnswer): self
{
if ($this->userAnswer->contains($userAnswer)) {
$this->userAnswer->removeElement($userAnswer);
// set the owning side to null (unless already changed)
if ($userAnswer->getTest() === $this) {
$userAnswer->setTest(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|CertificatePath[]
*/
public function getCertificatePaths(): Collection
{
return $this->certificatePaths;
}
public function addCertificatePath(CertificatePath $certificatePath): self
{
if (!$this->certificatePaths->contains($certificatePath)) {
$this->certificatePaths[] = $certificatePath;
$certificatePath->setTest($this);
}
return $this;
}
public function removeCertificatePath(CertificatePath $certificatePath): self
{
if ($this->certificatePaths->contains($certificatePath)) {
$this->certificatePaths->removeElement($certificatePath);
// set the owning side to null (unless already changed)
if ($certificatePath->getTest() === $this) {
$certificatePath->setTest(null);
}
}
return $this;
}
}