src/Entity/StudentActivityAttempt.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Timestampable;
  4. use App\Repository\StudentActivityAttemptRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. // Une tentative d'un élève sur une Activity. `attemptNumber` s'incrémente à
  9. // chaque nouvelle tentative (voir Activity::maxAttempts pour la limite
  10. // éventuelle). `score`/`maxScore`/`success` sont calculés côté serveur à la
  11. // soumission (voir StudentAnswer pour le détail par question).
  12. #[ORM\HasLifecycleCallbacks]
  13. #[ORM\Entity(repositoryClassStudentActivityAttemptRepository::class)]
  14. class StudentActivityAttempt
  15. {
  16.     use Timestampable;
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\ManyToOne]
  22.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  23.     private ?Student $student null;
  24.     #[ORM\ManyToOne]
  25.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  26.     private ?Activity $activity null;
  27.     #[ORM\Column]
  28.     private int $attemptNumber 1;
  29.     #[ORM\Column(nullabletrue)]
  30.     private ?float $score null;
  31.     #[ORM\Column(nullabletrue)]
  32.     private ?float $maxScore null;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?bool $success null;
  35.     // true = soumise automatiquement par le mobile suite à un dépassement de
  36.     // temps limite (Activity::timeLimitSeconds ou Capsule::timeLimitSeconds),
  37.     // false = soumise volontairement par l'élève. Sert à distinguer les deux
  38.     // cas dans le tableau de résultats enseignant.
  39.     #[ORM\Column(options: ['default' => false])]
  40.     private bool $autoSubmitted false;
  41.     #[ORM\Column(type'datetime'nullabletrue)]
  42.     private ?\DateTimeInterface $startedAt null;
  43.     #[ORM\Column(type'datetime'nullabletrue)]
  44.     private ?\DateTimeInterface $completedAt null;
  45.     #[ORM\OneToMany(mappedBy'attempt'targetEntityStudentAnswer::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  46.     private Collection $answers;
  47.     public function __construct()
  48.     {
  49.         $this->answers = new ArrayCollection();
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getStudent(): ?Student
  56.     {
  57.         return $this->student;
  58.     }
  59.     public function setStudent(?Student $student): static
  60.     {
  61.         $this->student $student;
  62.         return $this;
  63.     }
  64.     public function getActivity(): ?Activity
  65.     {
  66.         return $this->activity;
  67.     }
  68.     public function setActivity(?Activity $activity): static
  69.     {
  70.         $this->activity $activity;
  71.         return $this;
  72.     }
  73.     public function getAttemptNumber(): int
  74.     {
  75.         return $this->attemptNumber;
  76.     }
  77.     public function setAttemptNumber(int $attemptNumber): static
  78.     {
  79.         $this->attemptNumber $attemptNumber;
  80.         return $this;
  81.     }
  82.     public function getScore(): ?float
  83.     {
  84.         return $this->score;
  85.     }
  86.     public function setScore(?float $score): static
  87.     {
  88.         $this->score $score;
  89.         return $this;
  90.     }
  91.     public function getMaxScore(): ?float
  92.     {
  93.         return $this->maxScore;
  94.     }
  95.     public function setMaxScore(?float $maxScore): static
  96.     {
  97.         $this->maxScore $maxScore;
  98.         return $this;
  99.     }
  100.     public function isSuccess(): ?bool
  101.     {
  102.         return $this->success;
  103.     }
  104.     public function setSuccess(?bool $success): static
  105.     {
  106.         $this->success $success;
  107.         return $this;
  108.     }
  109.     public function isAutoSubmitted(): bool
  110.     {
  111.         return $this->autoSubmitted;
  112.     }
  113.     public function setAutoSubmitted(bool $autoSubmitted): static
  114.     {
  115.         $this->autoSubmitted $autoSubmitted;
  116.         return $this;
  117.     }
  118.     public function getStartedAt(): ?\DateTimeInterface
  119.     {
  120.         return $this->startedAt;
  121.     }
  122.     public function setStartedAt(?\DateTimeInterface $startedAt): static
  123.     {
  124.         $this->startedAt $startedAt;
  125.         return $this;
  126.     }
  127.     public function getCompletedAt(): ?\DateTimeInterface
  128.     {
  129.         return $this->completedAt;
  130.     }
  131.     public function setCompletedAt(?\DateTimeInterface $completedAt): static
  132.     {
  133.         $this->completedAt $completedAt;
  134.         return $this;
  135.     }
  136.     /** @return Collection<int, StudentAnswer> */
  137.     public function getAnswers(): Collection
  138.     {
  139.         return $this->answers;
  140.     }
  141.     public function addAnswer(StudentAnswer $answer): static
  142.     {
  143.         if (!$this->answers->contains($answer)) {
  144.             $this->answers->add($answer);
  145.             $answer->setAttempt($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeAnswer(StudentAnswer $answer): static
  150.     {
  151.         if ($this->answers->removeElement($answer)) {
  152.             if ($answer->getAttempt() === $this) {
  153.                 $answer->setAttempt(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158. }