<?php
namespace App\Entity\Gos\Uniqskills;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\QuestionRepository")
* @ORM\HasLifecycleCallbacks
*/
class Question
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="text")
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=191, unique=true)
*/
private $slug;
/**
* @var integer
* @ORM\Column(type="integer")
*/
private $position;
/**
* @var integer
* @ORM\Column(type="integer", nullable=true)
*/
private $points;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $fileWithAnswer;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", nullable=true)
*
* @Assert\File(mimeTypes={ "image/png", "image/jpeg", "image/gif" })
*/
private $image;
/**
* @ORM\ManyToOne(targetEntity="Test", inversedBy="question")
* @ORM\JoinColumn(name="test_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $test;
/**
* @ORM\OneToMany(targetEntity="Answer", mappedBy="question", cascade={"persist"}, orphanRemoval=true)
*/
private $answer;
/**
* @ORM\OneToMany(targetEntity="UserAnswer", mappedBy="question")
*/
private $userAnswer;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sendAnswerTo;
public function __construct()
{
$this->answer = new ArrayCollection();
$this->userAnswer = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->updatedAt = null;
}
public function getImage()
{
return $this->image;
}
public function setImage($image)
{
$this->image = $image;
return $this;
}
public function getImageLink($dir)
{
return $dir.'/'.$this->getTest()->getId().'/'.$this->image;
}
/** @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 setAnswers($answers)
{
if (count($answers) > 0) {
foreach ($answers as $a) {
$this->addAnswer($a);
}
}
return $this;
}
/**
* Add answer
*
* @param Answer $answer
* @return Question
*/
public function addAnswer(Answer $answer)
{
$answer->setQuestion($this);
$this->answer[] = $answer;
return $this;
}
/**
* Remove answer
*
* @param Answer $answer
*/
public function removeAnswer(Answer $answer)
{
$this->answer->removeElement($answer);
}
/**
* Get answer
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAnswer()
{
return $this->answer;
}
public function getId(): ?int
{
return $this->id;
}
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($slug): self
{
$this->slug = $slug;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getPoints(): ?int
{
return $this->points;
}
public function setPoints(?int $points): self
{
$this->points = $points;
return $this;
}
public function getFileWithAnswer(): ?bool
{
return $this->fileWithAnswer;
}
public function setFileWithAnswer(bool $fileWithAnswer): self
{
$this->fileWithAnswer = $fileWithAnswer;
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 getTest(): ?Test
{
return $this->test;
}
public function setTest(?Test $test): self
{
$this->test = $test;
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->setQuestion($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->getQuestion() === $this) {
$userAnswer->setQuestion(null);
}
}
return $this;
}
public function getSendAnswerTo(): ?string
{
return $this->sendAnswerTo;
}
public function setSendAnswerTo(?string $sendAnswerTo): self
{
$this->sendAnswerTo = $sendAnswerTo;
return $this;
}
public function getType(): string
{
$counter = 0;
foreach ($this->getAnswer() as $answer)
{
if ($answer->getIsTrue()) $counter++;
}
if ($counter === 0)
{
return 'textarea';
}
if ($counter === 1)
{
return 'radio';
}
return 'checkbox';
}
}