src/Entity/Activity.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Timestampable;
  4. use App\Repository\ActivityRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. // Activité interactive auto-corrigée (QCM, vrai/faux, réponse courte,
  9. // association, remise en ordre) portée par un CapsuleBlock de type
  10. // `activity`. Association optionnelle à une LearningCompetency — PAS à
  11. // App\Entity\Competence (système de notation trimestriel existant) : sur
  12. // demande explicite, cette compétence-ci n'a aucun rapport avec le trimestre,
  13. // elle sert seulement à suivre la progression continue de l'élève sur un
  14. // savoir-faire au travers de plusieurs activités (voir StudentActivityAttempt).
  15. #[ORM\HasLifecycleCallbacks]
  16. #[ORM\Entity(repositoryClassActivityRepository::class)]
  17. class Activity
  18. {
  19.     use Timestampable;
  20.     public const TYPE_QCM 'qcm';
  21.     public const TYPE_TRUE_FALSE 'true_false';
  22.     public const TYPE_SHORT_ANSWER 'short_answer';
  23.     public const TYPE_MATCHING 'matching';
  24.     public const TYPE_ORDERING 'ordering';
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     private ?int $id null;
  29.     #[ORM\Column(length20)]
  30.     private ?string $type null;
  31.     #[ORM\Column(type'text'nullabletrue)]
  32.     private ?string $instructions null;
  33.     #[ORM\ManyToOne]
  34.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  35.     private ?LearningCompetency $learningCompetency null;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?int $maxAttempts null;
  38.     // Temps limite (en secondes) pour répondre à CETTE activité (quiz
  39.     // chronométré), indépendant de Capsule::timeLimitSeconds — les deux sont
  40.     // cumulables. Null = pas de limite propre à l'activité.
  41.     #[ORM\Column(nullabletrue)]
  42.     private ?int $timeLimitSeconds null;
  43.     #[ORM\ManyToOne]
  44.     #[ORM\JoinColumn(nullablefalse)]
  45.     private ?User $author null;
  46.     #[ORM\ManyToOne]
  47.     private ?User $editor null;
  48.     // Côté inverse de CapsuleBlock::$activity (qui porte la FK) — permet de
  49.     // remonter school/year/subject pour le scoping des endpoints de sync
  50.     // (Activity n'a pas de lien direct vers Subject/School/SchoolYear).
  51.     #[ORM\OneToOne(mappedBy'activity')]
  52.     private ?CapsuleBlock $block null;
  53.     #[ORM\OneToMany(mappedBy'activity'targetEntityQuestion::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  54.     #[ORM\OrderBy(['position' => 'ASC'])]
  55.     private Collection $questions;
  56.     public function __construct()
  57.     {
  58.         $this->questions = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getType(): ?string
  65.     {
  66.         return $this->type;
  67.     }
  68.     public function setType(string $type): static
  69.     {
  70.         $this->type $type;
  71.         return $this;
  72.     }
  73.     public function getInstructions(): ?string
  74.     {
  75.         return $this->instructions;
  76.     }
  77.     public function setInstructions(?string $instructions): static
  78.     {
  79.         $this->instructions $instructions;
  80.         return $this;
  81.     }
  82.     public function getLearningCompetency(): ?LearningCompetency
  83.     {
  84.         return $this->learningCompetency;
  85.     }
  86.     public function setLearningCompetency(?LearningCompetency $learningCompetency): static
  87.     {
  88.         $this->learningCompetency $learningCompetency;
  89.         return $this;
  90.     }
  91.     public function getMaxAttempts(): ?int
  92.     {
  93.         return $this->maxAttempts;
  94.     }
  95.     public function setMaxAttempts(?int $maxAttempts): static
  96.     {
  97.         $this->maxAttempts $maxAttempts;
  98.         return $this;
  99.     }
  100.     public function getTimeLimitSeconds(): ?int
  101.     {
  102.         return $this->timeLimitSeconds;
  103.     }
  104.     public function setTimeLimitSeconds(?int $timeLimitSeconds): static
  105.     {
  106.         $this->timeLimitSeconds $timeLimitSeconds;
  107.         return $this;
  108.     }
  109.     public function getAuthor(): ?User
  110.     {
  111.         return $this->author;
  112.     }
  113.     public function setAuthor(?User $author): static
  114.     {
  115.         $this->author $author;
  116.         return $this;
  117.     }
  118.     public function getEditor(): ?User
  119.     {
  120.         return $this->editor;
  121.     }
  122.     public function setEditor(?User $editor): static
  123.     {
  124.         $this->editor $editor;
  125.         return $this;
  126.     }
  127.     public function getBlock(): ?CapsuleBlock
  128.     {
  129.         return $this->block;
  130.     }
  131.     /** @return Collection<int, Question> */
  132.     public function getQuestions(): Collection
  133.     {
  134.         return $this->questions;
  135.     }
  136.     public function addQuestion(Question $question): static
  137.     {
  138.         if (!$this->questions->contains($question)) {
  139.             $this->questions->add($question);
  140.             $question->setActivity($this);
  141.         }
  142.         return $this;
  143.     }
  144.     public function removeQuestion(Question $question): static
  145.     {
  146.         if ($this->questions->removeElement($question)) {
  147.             if ($question->getActivity() === $this) {
  148.                 $question->setActivity(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153. }