src/Entity/Channel/PositioningTest/Question.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel\PositioningTest;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  7. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  8. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  9. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  12. #[
  13.     ORM\Entity(),
  14.     ORM\Table(name'channel_positioning_test_questions'),
  15. ]
  16. class Question implements TimestampInterfaceBlameInterface
  17. {
  18.     use TimestampTrait;
  19.     use BlameTrait;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type'integer')]
  23.     private ?int $id null;
  24.     #[ORM\Column(type'boolean')]
  25.     private bool $multiple false;
  26.     #[ORM\Column(type'string'length255)]
  27.     #[
  28.         Assert\NotBlank(message'positioningTest.question.label.NotBlank'),
  29.         Assert\Length(
  30.             max255,
  31.             maxMessage'positioningTest.question.label.Length.max'
  32.         )
  33.     ]
  34.     private ?string $label null;
  35.     #[ORM\Column(type'text'length5000nullabletrue)]
  36.     #[
  37.         Assert\Length(
  38.             max5000,
  39.             maxMessage'positioningTest.question.description.Length.max'
  40.         )
  41.     ]
  42.     private ?string $description null;
  43.     #[ORM\Column(type'text'length5000nullabletrue)]
  44.     #[
  45.         Assert\Length(
  46.             max5000,
  47.             maxMessage'positioningTest.question.video_url.Length.max'
  48.         )
  49.     ]
  50.     private ?string $videoUrl null;
  51.     #[ORM\Column(type'integer')]
  52.     private ?int $rank null;
  53.     #[ORM\ManyToOne(targetEntityBlock::class, inversedBy'questions')]
  54.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  55.     private ?Block $block null;
  56.     #[ORM\OneToMany(mappedBy'question'targetEntityFileQuestion::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  57.     private ?Collection $files;
  58.     #[ORM\OneToMany(mappedBy'question'targetEntityQuestionAnswer::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  59.     private ?Collection $answers;
  60.     public function __construct()
  61.     {
  62.         $this->files = new ArrayCollection();
  63.         $this->answers = new ArrayCollection();
  64.     }
  65.     #[Assert\Callback]
  66.     public function validateAnswers(ExecutionContextInterface  $context): void
  67.     {
  68.         if (!$this->getAnswers()->exists(fn($kQuestionAnswer $questionAnswer) => $questionAnswer->isValid())) {
  69.             $context->buildViolation('positioningTest.question.answers.hasValid')
  70.                 ->atPath('answers')
  71.                 ->addViolation()
  72.             ;
  73.         }
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function isMultiple(): bool
  80.     {
  81.         return $this->multiple;
  82.     }
  83.     public function setMultiple(bool $multiple): static
  84.     {
  85.         $this->multiple $multiple;
  86.         return $this;
  87.     }
  88.     public function getLabel(): ?string
  89.     {
  90.         return $this->label;
  91.     }
  92.     public function setLabel(?string $label): static
  93.     {
  94.         $this->label $label;
  95.         return $this;
  96.     }
  97.     public function getDescription(): ?string
  98.     {
  99.         return $this->description;
  100.     }
  101.     public function setDescription(?string $description): static
  102.     {
  103.         $this->description $description;
  104.         return $this;
  105.     }
  106.     public function getVideoUrl(): ?string
  107.     {
  108.         return $this->videoUrl;
  109.     }
  110.     public function setVideoUrl(?string $videoUrl): static
  111.     {
  112.         $this->videoUrl $videoUrl;
  113.         return $this;
  114.     }
  115.     public function getRank(): ?int
  116.     {
  117.         return $this->rank;
  118.     }
  119.     public function setRank(?int $rank): static
  120.     {
  121.         $this->rank $rank;
  122.         return $this;
  123.     }
  124.     public function getBlock(): ?Block
  125.     {
  126.         return $this->block;
  127.     }
  128.     public function setBlock(?Block $block): static
  129.     {
  130.         $this->block $block;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, FileQuestion>|null
  135.      */
  136.     public function getFiles(): ?Collection
  137.     {
  138.         return $this->files;
  139.     }
  140.     public function addFile(FileQuestion $file): self
  141.     {
  142.         if (!$this->files->contains($file)) {
  143.             $file->setQuestion($this);
  144.             $this->files[] = $file;
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeFile(FileQuestion $file): self
  149.     {
  150.         if ($this->files->contains($file)) {
  151.             $this->files->removeElement($file);
  152.         }
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, QuestionAnswer>|null
  157.      */
  158.     public function getAnswers(): ?Collection
  159.     {
  160.         return $this->answers;
  161.     }
  162.     public function addAnswer(QuestionAnswer $answer): self
  163.     {
  164.         if (!$this->answers->contains($answer)) {
  165.             $answer->setQuestion($this);
  166.             $this->answers->add($answer);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeAnswer(QuestionAnswer $answer): self
  171.     {
  172.         if ($this->answers->contains($answer)) {
  173.             $this->answers->removeElement($answer);
  174.         }
  175.         return $this;
  176.     }
  177. }