src/Entity/StudentAnswer.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Timestampable;
  4. use App\Repository\StudentAnswerRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. // Réponse d'un élève à une Question, dans le cadre d'une StudentActivityAttempt.
  7. // `rawAnswer` porte soit du texte libre (short_answer), soit un JSON encodé
  8. // (tableau d'ids QuestionOption sélectionnés pour qcm/true_false/matching, ou
  9. // tableau d'ids dans l'ordre proposé par l'élève pour ordering).
  10. #[ORM\HasLifecycleCallbacks]
  11. #[ORM\Entity(repositoryClassStudentAnswerRepository::class)]
  12. class StudentAnswer
  13. {
  14.     use Timestampable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\ManyToOne(inversedBy'answers')]
  20.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  21.     private ?StudentActivityAttempt $attempt null;
  22.     #[ORM\ManyToOne]
  23.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  24.     private ?Question $question null;
  25.     #[ORM\Column(type'text'nullabletrue)]
  26.     private ?string $rawAnswer null;
  27.     #[ORM\Column(nullabletrue)]
  28.     private ?bool $isCorrect null;
  29.     #[ORM\Column(nullabletrue)]
  30.     private ?float $pointsEarned null;
  31.     // Surclassement manuel par un enseignant, pour les réponses ouvertes
  32.     // (short_answer) que la correction automatique (exact/ci/contains) juge
  33.     // insatisfaisant. Quand renseigné, prime sur pointsEarned/isCorrect pour
  34.     // le calcul du score de la tentative (voir CapsuleGradingService).
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?float $teacherPointsEarned null;
  37.     #[ORM\Column(type'text'nullabletrue)]
  38.     private ?string $teacherFeedback null;
  39.     #[ORM\ManyToOne]
  40.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  41.     private ?User $gradedBy null;
  42.     #[ORM\Column(type'datetime'nullabletrue)]
  43.     private ?\DateTimeInterface $gradedAt null;
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getAttempt(): ?StudentActivityAttempt
  49.     {
  50.         return $this->attempt;
  51.     }
  52.     public function setAttempt(?StudentActivityAttempt $attempt): static
  53.     {
  54.         $this->attempt $attempt;
  55.         return $this;
  56.     }
  57.     public function getQuestion(): ?Question
  58.     {
  59.         return $this->question;
  60.     }
  61.     public function setQuestion(?Question $question): static
  62.     {
  63.         $this->question $question;
  64.         return $this;
  65.     }
  66.     public function getRawAnswer(): ?string
  67.     {
  68.         return $this->rawAnswer;
  69.     }
  70.     public function setRawAnswer(?string $rawAnswer): static
  71.     {
  72.         $this->rawAnswer $rawAnswer;
  73.         return $this;
  74.     }
  75.     public function isCorrect(): ?bool
  76.     {
  77.         return $this->isCorrect;
  78.     }
  79.     public function setIsCorrect(?bool $isCorrect): static
  80.     {
  81.         $this->isCorrect $isCorrect;
  82.         return $this;
  83.     }
  84.     public function getPointsEarned(): ?float
  85.     {
  86.         return $this->pointsEarned;
  87.     }
  88.     public function setPointsEarned(?float $pointsEarned): static
  89.     {
  90.         $this->pointsEarned $pointsEarned;
  91.         return $this;
  92.     }
  93.     public function getTeacherPointsEarned(): ?float
  94.     {
  95.         return $this->teacherPointsEarned;
  96.     }
  97.     public function setTeacherPointsEarned(?float $teacherPointsEarned): static
  98.     {
  99.         $this->teacherPointsEarned $teacherPointsEarned;
  100.         return $this;
  101.     }
  102.     public function getTeacherFeedback(): ?string
  103.     {
  104.         return $this->teacherFeedback;
  105.     }
  106.     public function setTeacherFeedback(?string $teacherFeedback): static
  107.     {
  108.         $this->teacherFeedback $teacherFeedback;
  109.         return $this;
  110.     }
  111.     public function getGradedBy(): ?User
  112.     {
  113.         return $this->gradedBy;
  114.     }
  115.     public function setGradedBy(?User $gradedBy): static
  116.     {
  117.         $this->gradedBy $gradedBy;
  118.         return $this;
  119.     }
  120.     public function getGradedAt(): ?\DateTimeInterface
  121.     {
  122.         return $this->gradedAt;
  123.     }
  124.     public function setGradedAt(?\DateTimeInterface $gradedAt): static
  125.     {
  126.         $this->gradedAt $gradedAt;
  127.         return $this;
  128.     }
  129.     /**
  130.      * Score effectif de cette réponse : la correction manuelle prime sur le
  131.      * calcul automatique quand elle a été saisie.
  132.      */
  133.     public function getEffectivePointsEarned(): ?float
  134.     {
  135.         return $this->teacherPointsEarned ?? $this->pointsEarned;
  136.     }
  137.     /**
  138.      * true seulement pour les réponses ouvertes (short_answer) — les seules
  139.      * pouvant faire l'objet d'une correction manuelle (QCM/vrai-faux/
  140.      * appariement/ordonnancement restent toujours entièrement auto-corrigés).
  141.      */
  142.     public function isManuallyGradable(): bool
  143.     {
  144.         return $this->question?->getType() === Activity::TYPE_SHORT_ANSWER;
  145.     }
  146. }