src/Entity/Question.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use App\Repository\QuestionRepository;
  8. use DateTimeImmutable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassQuestionRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['profile','read','readDeep','readQuestions']],
  15.     denormalizationContext: ['groups' => ['profile','write']],
  16.     
  17.     )]
  18.     #[ApiFilter(ExistsFilter::class, properties: ['originAnswer'])]
  19. class Question
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column(type'integer')]
  24.     #[Groups(["read","readDeep",'profile'])]
  25.     private $id;
  26.    
  27.     #[ORM\Column(type'string'length255nullabletrue)]
  28.     #[Groups(["read","readDeep"])]
  29.     private $content;
  30.     #[ORM\Column(type'datetime_immutable')]
  31.     private $createdAt;
  32.     #[ORM\Column(type'boolean'nullabletrue)]
  33.     private $isEnabled;
  34.     #[ORM\Column(type'integer'nullabletrue)]
  35.     private $position;
  36.     #[ORM\OneToMany(mappedBy'question'targetEntityAnswer::class , cascade: ["persist"])]
  37.     #[Groups(["read","readDeep"])]
  38.     private $answers;
  39.     #[ORM\Column(type'boolean'nullabletrue)]
  40.     // #[Groups(["read","readDeep"])]
  41.     #[Groups(["read","readDeep"])]
  42.     private $isRequired;
  43.     #[ORM\Column(type'integer'nullabletrue)]
  44.     // #[Groups(["read","readDeep"])]
  45.     #[Groups(["read","readDeep"])]
  46.     private $min;
  47.     #[ORM\Column(type'integer'nullabletrue)]
  48.     // #[Groups(["read","readDeep"])]
  49.     #[Groups(["read","readDeep"])]
  50.     private $max;
  51.     #[ORM\OneToMany(mappedBy'question'targetEntityQuestionTranslation::class,cascade:["persist","remove"])]
  52.      #[Groups(["read","readDeep"])]
  53.     private Collection $translations;
  54.     #[ORM\OneToOne(mappedBy'subQuestion'cascade: ['persist''remove'])]
  55.     private ?Answer $originAnswer null;
  56.     #[ORM\Column(length255nullabletrue)]
  57.     private ?string $type null;
  58.     #[ORM\Column(nullabletrue)]
  59.     #[Groups(["read","readDeep"])]
  60.     private ?bool $isMultipleChoices null;
  61.     #[ORM\Column(nullabletrue)]
  62.     #[Groups(["read","readDeep"])]
  63.     private ?int $minChoices null;
  64.     public function __construct()
  65.     {
  66.         $this->answers = new ArrayCollection();
  67.         $this->createdAt = new DateTimeImmutable();
  68.         $this->translations = new ArrayCollection();
  69.     }
  70.     public function __toString()
  71.     {
  72.         return (string)$this->content;
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getContent(): ?string
  79.     {
  80.         return $this->content;
  81.     }
  82.     public function setContent(string $content): self
  83.     {
  84.         $this->content $content;
  85.         return $this;
  86.     }
  87.     public function getCreatedAt(): ?\DateTimeImmutable
  88.     {
  89.         return $this->createdAt;
  90.     }
  91.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  92.     {
  93.         $this->createdAt $createdAt;
  94.         return $this;
  95.     }
  96.     public function isIsEnabled(): ?bool
  97.     {
  98.         return $this->isEnabled;
  99.     }
  100.     public function setIsEnabled(?bool $isEnabled): self
  101.     {
  102.         $this->isEnabled $isEnabled;
  103.         return $this;
  104.     }
  105.     public function getPosition(): ?int
  106.     {
  107.         return $this->position;
  108.     }
  109.     public function setPosition(?int $position): self
  110.     {
  111.         $this->position $position;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection<int, Answer>
  116.      */
  117.     public function getAnswers(): Collection
  118.     {
  119.         return $this->answers;
  120.     }
  121.     public function addAnswer(Answer $answer): self
  122.     {
  123.         if (!$this->answers->contains($answer)) {
  124.             $this->answers[] = $answer;
  125.             $answer->setQuestion($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeAnswer(Answer $answer): self
  130.     {
  131.         if ($this->answers->removeElement($answer)) {
  132.             // set the owning side to null (unless already changed)
  133.             if ($answer->getQuestion() === $this) {
  134.                 $answer->setQuestion(null);
  135.             }
  136.         }
  137.         return $this;
  138.     }
  139.     public function getIsRequired(): ?bool
  140.     {
  141.         return $this->isRequired;
  142.     }
  143.     public function setIsRequired(?bool $isRequired): self
  144.     {
  145.         $this->isRequired $isRequired;
  146.         return $this;
  147.     }
  148.     public function getMin(): ?int
  149.     {
  150.         return $this->min;
  151.     }
  152.     public function setMin(?int $min): self
  153.     {
  154.         $this->min $min;
  155.         return $this;
  156.     }
  157.     public function getMax(): ?int
  158.     {
  159.         return $this->max;
  160.     }
  161.     public function setMax(?int $max): self
  162.     {
  163.         $this->max $max;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return Collection<int, QuestionTranslation>
  168.      */
  169.     public function getTranslations(): Collection
  170.     {
  171.         return $this->translations;
  172.     }
  173.     public function addTranslation(QuestionTranslation $translation): self
  174.     {
  175.         if (!$this->translations->contains($translation)) {
  176.             $this->translations->add($translation);
  177.             $translation->setQuestion($this);
  178.         }
  179.         return $this;
  180.     }
  181.     public function removeTranslation(QuestionTranslation $translation): self
  182.     {
  183.         if ($this->translations->removeElement($translation)) {
  184.             // set the owning side to null (unless already changed)
  185.             if ($translation->getQuestion() === $this) {
  186.                 $translation->setQuestion(null);
  187.             }
  188.         }
  189.         return $this;
  190.     }
  191.     public function getOriginAnswer(): ?Answer
  192.     {
  193.         return $this->originAnswer;
  194.     }
  195.     public function setOriginAnswer(?Answer $originAnswer): static
  196.     {
  197.         // unset the owning side of the relation if necessary
  198.         if ($originAnswer === null && $this->originAnswer !== null) {
  199.             $this->originAnswer->setSubQuestion(null);
  200.         }
  201.         // set the owning side of the relation if necessary
  202.         if ($originAnswer !== null && $originAnswer->getSubQuestion() !== $this) {
  203.             $originAnswer->setSubQuestion($this);
  204.         }
  205.         $this->originAnswer $originAnswer;
  206.         return $this;
  207.     }
  208.     public function getType(): ?string
  209.     {
  210.         return $this->type;
  211.     }
  212.     public function setType(?string $type): static
  213.     {
  214.         $this->type $type;
  215.         return $this;
  216.     }
  217.     public function isIsMultipleChoices(): ?bool
  218.     {
  219.         return $this->isMultipleChoices;
  220.     }
  221.     public function setIsMultipleChoices(?bool $isMultipleChoices): static
  222.     {
  223.         $this->isMultipleChoices $isMultipleChoices;
  224.         return $this;
  225.     }
  226.     public function getMinChoices(): ?int
  227.     {
  228.         return $this->minChoices;
  229.     }
  230.     public function setMinChoices(?int $minChoices): static
  231.     {
  232.         $this->minChoices $minChoices;
  233.         return $this;
  234.     }
  235. }