src/Entity/ExerciseSorting.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ExerciseSortingRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=ExerciseSortingRepository::class)
  7.  */
  8. class ExerciseSorting
  9. {
  10.     /**
  11.      * @ORM\Id
  12.      * @ORM\GeneratedValue
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\Column(type="string", length=32)
  18.      */
  19.     private $name;
  20.     /**
  21.      * @ORM\Column(type="text")
  22.      */
  23.     private $description;
  24.     /**
  25.      * @ORM\Column(type="text")
  26.      */
  27.     private $question;
  28.     /**
  29.      * @ORM\Column(type="string", length=32)
  30.      */
  31.     private $answerA;
  32.     /**
  33.      * @ORM\Column(type="string", length=32)
  34.      */
  35.     private $answerB;
  36.     /**
  37.      * @ORM\Column(type="string", length=32)
  38.      */
  39.     private $answerC;
  40.     /**
  41.      * @ORM\Column(type="string", length=32)
  42.      */
  43.     private $answerD;
  44.     /**
  45.      * @ORM\Column(type="integer")
  46.      */
  47.     private $position;
  48.     /**
  49.      * @ORM\Column(type="text", nullable=true)
  50.      */
  51.     private $note;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=Kpi::class, inversedBy="exerciseSortings")
  54.      * @ORM\JoinColumn(nullable=false)
  55.      */
  56.     private $kpi;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $played;
  61.     /**
  62.      * @ORM\Column(type="text", nullable=true)
  63.      */
  64.     private $evaluationModel;
  65.     public function __construct()
  66.     {
  67.         if(is_null($this->position)){
  68.             $this->setPosition(0);
  69.         }
  70.         if(is_null($this->played)){
  71.             $this->setPlayed(0);
  72.         }
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     public function getDescription(): ?string
  88.     {
  89.         return $this->description;
  90.     }
  91.     public function setDescription(string $description): self
  92.     {
  93.         $this->description $description;
  94.         return $this;
  95.     }
  96.     public function getQuestion(): ?string
  97.     {
  98.         return $this->question;
  99.     }
  100.     public function getCompleteQuestion(){
  101.         $q $this->getQuestion();
  102.         $answers = [
  103.             $this->getAnswerA(),
  104.             $this->getAnswerB(),
  105.             $this->getAnswerC(),
  106.             $this->getAnswerD(),
  107.         ];
  108.         shuffle($answers);
  109.         $index range('a','d');
  110.         foreach ($answers as $position => $answer){
  111.             $q .= " ...".$index[$position].", $answer";
  112.         }
  113.         $correctAnswers = [
  114.             $this->getAnswerA(),
  115.             $this->getAnswerB(),
  116.             $this->getAnswerC(),
  117.             $this->getAnswerD(),
  118.         ];
  119.         $correct = [];
  120.         foreach ($correctAnswers as $answer){
  121.             $correct[] = array_search($answer,$answers);
  122.         }
  123.         return [
  124.             "question" => $q,
  125.             "correctAnswer" => $correct
  126.         ];
  127.     }
  128.     public function setQuestion(string $question): self
  129.     {
  130.         $this->question $question;
  131.         return $this;
  132.     }
  133.     public function getAnswerA(): ?string
  134.     {
  135.         return $this->answerA;
  136.     }
  137.     public function setAnswerA(string $answerA): self
  138.     {
  139.         $this->answerA $answerA;
  140.         return $this;
  141.     }
  142.     public function getAnswerB(): ?string
  143.     {
  144.         return $this->answerB;
  145.     }
  146.     public function setAnswerB(string $answerB): self
  147.     {
  148.         $this->answerB $answerB;
  149.         return $this;
  150.     }
  151.     public function getAnswerC(): ?string
  152.     {
  153.         return $this->answerC;
  154.     }
  155.     public function setAnswerC(string $answerC): self
  156.     {
  157.         $this->answerC $answerC;
  158.         return $this;
  159.     }
  160.     public function getAnswerD(): ?string
  161.     {
  162.         return $this->answerD;
  163.     }
  164.     public function setAnswerD(string $answerD): self
  165.     {
  166.         $this->answerD $answerD;
  167.         return $this;
  168.     }
  169.     public function getPosition(): ?int
  170.     {
  171.         return $this->position;
  172.     }
  173.     public function setPosition(int $position): self
  174.     {
  175.         $this->position $position;
  176.         return $this;
  177.     }
  178.     public function getNote(): ?string
  179.     {
  180.         return $this->note;
  181.     }
  182.     public function setNote(?string $note): self
  183.     {
  184.         $this->note $note;
  185.         return $this;
  186.     }
  187.     public function getKpi(): ?Kpi
  188.     {
  189.         return $this->kpi;
  190.     }
  191.     public function setKpi(?Kpi $kpi): self
  192.     {
  193.         $this->kpi $kpi;
  194.         return $this;
  195.     }
  196.     public function getPlayed(): ?int
  197.     {
  198.         return $this->played;
  199.     }
  200.     public function setPlayed(int $played): self
  201.     {
  202.         $this->played $played;
  203.         return $this;
  204.     }
  205.     public function incrementPlayed(): self
  206.     {
  207.         $this->played++;
  208.         return $this;
  209.     }
  210.     public function getEvaluationModel(): ?string
  211.     {
  212.         return $this->evaluationModel;
  213.     }
  214.     public function setEvaluationModel(?string $evaluationModel): self
  215.     {
  216.         $this->evaluationModel $evaluationModel;
  217.         return $this;
  218.     }
  219. }