<?php
namespace App\Entity;
use App\Repository\ExerciseSortingRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ExerciseSortingRepository::class)
*/
class ExerciseSorting
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=32)
*/
private $name;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="text")
*/
private $question;
/**
* @ORM\Column(type="string", length=32)
*/
private $answerA;
/**
* @ORM\Column(type="string", length=32)
*/
private $answerB;
/**
* @ORM\Column(type="string", length=32)
*/
private $answerC;
/**
* @ORM\Column(type="string", length=32)
*/
private $answerD;
/**
* @ORM\Column(type="integer")
*/
private $position;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $note;
/**
* @ORM\ManyToOne(targetEntity=Kpi::class, inversedBy="exerciseSortings")
* @ORM\JoinColumn(nullable=false)
*/
private $kpi;
/**
* @ORM\Column(type="integer")
*/
private $played;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $evaluationModel;
public function __construct()
{
if(is_null($this->position)){
$this->setPosition(0);
}
if(is_null($this->played)){
$this->setPlayed(0);
}
}
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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getQuestion(): ?string
{
return $this->question;
}
public function getCompleteQuestion(){
$q = $this->getQuestion();
$answers = [
$this->getAnswerA(),
$this->getAnswerB(),
$this->getAnswerC(),
$this->getAnswerD(),
];
shuffle($answers);
$index = range('a','d');
foreach ($answers as $position => $answer){
$q .= " ...".$index[$position].", $answer";
}
$correctAnswers = [
$this->getAnswerA(),
$this->getAnswerB(),
$this->getAnswerC(),
$this->getAnswerD(),
];
$correct = [];
foreach ($correctAnswers as $answer){
$correct[] = array_search($answer,$answers);
}
return [
"question" => $q,
"correctAnswer" => $correct
];
}
public function setQuestion(string $question): self
{
$this->question = $question;
return $this;
}
public function getAnswerA(): ?string
{
return $this->answerA;
}
public function setAnswerA(string $answerA): self
{
$this->answerA = $answerA;
return $this;
}
public function getAnswerB(): ?string
{
return $this->answerB;
}
public function setAnswerB(string $answerB): self
{
$this->answerB = $answerB;
return $this;
}
public function getAnswerC(): ?string
{
return $this->answerC;
}
public function setAnswerC(string $answerC): self
{
$this->answerC = $answerC;
return $this;
}
public function getAnswerD(): ?string
{
return $this->answerD;
}
public function setAnswerD(string $answerD): self
{
$this->answerD = $answerD;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getKpi(): ?Kpi
{
return $this->kpi;
}
public function setKpi(?Kpi $kpi): self
{
$this->kpi = $kpi;
return $this;
}
public function getPlayed(): ?int
{
return $this->played;
}
public function setPlayed(int $played): self
{
$this->played = $played;
return $this;
}
public function incrementPlayed(): self
{
$this->played++;
return $this;
}
public function getEvaluationModel(): ?string
{
return $this->evaluationModel;
}
public function setEvaluationModel(?string $evaluationModel): self
{
$this->evaluationModel = $evaluationModel;
return $this;
}
}