src/Entity/Question.php line 17

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