src/Entity/Question.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuestionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=QuestionRepository::class)
  9.  * @ORM\Table(name="app_question")
  10.  */
  11. class Question
  12. {
  13.     const TYPE_CHOICE   'choice';
  14.     const TYPE_MULTI    'multi';
  15.     const TYPE_IMG      'img';
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private int $id;
  22.     /**
  23.      * Текст вопроса
  24.      * @ORM\Column(type="text", length=500, nullable=true)
  25.      */
  26.     private ?string $text null;
  27.     /**
  28.      * Текст вопроса
  29.      * @ORM\Column(type="text", length=500, nullable=true)
  30.      */
  31.     private ?string $textLocal null;
  32.     /**
  33.      * Тип вопроса (например, single_choice, multiple_choice, yes_no, etc.)
  34.      * @ORM\Column(type="string", length=50, nullable=true)
  35.      */
  36.     private ?string $type null;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\Survey", inversedBy="questions")
  39.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  40.      */
  41.     private ?Survey $survey;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity="App\Entity\Answer", mappedBy="question", cascade={"persist", "remove"})
  44.      */
  45.     private Collection $answers;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity="App\Entity\QuestionImage", mappedBy="question", cascade={"persist", "remove"}, orphanRemoval=true)
  48.      */
  49.     private Collection $images;
  50.     /**
  51.      * @ORM\Column(type="boolean", options={"default": false})
  52.      */
  53.     private bool $isAddBalance false;
  54.     public function __construct()
  55.     {
  56.         $this->answers = new ArrayCollection();
  57.         $this->images = new ArrayCollection();
  58.     }
  59.     public function getId(): int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function __toString(): ?string
  64.     {
  65.         return $this->getText() ?? $this->getId();
  66.     }
  67.     public function getText(): ?string
  68.     {
  69.         return $this->text;
  70.     }
  71.     public function setText(?string $text): self
  72.     {
  73.         $this->text $text;
  74.         return $this;
  75.     }
  76.     public function getTextLocal(): ?string
  77.     {
  78.         return $this->textLocal;
  79.     }
  80.     public function setTextLocal(?string $textLocal): self
  81.     {
  82.         $this->textLocal $textLocal;
  83.         return $this;
  84.     }
  85.     public function getType(): ?string
  86.     {
  87.         return $this->type;
  88.     }
  89.     public function setType(?string $type): self
  90.     {
  91.         $this->type $type;
  92.         return $this;
  93.     }
  94.     public function getSurvey(): ?Survey
  95.     {
  96.         return $this->survey;
  97.     }
  98.     public function setSurvey(?Survey $survey): self
  99.     {
  100.         $this->survey $survey;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection|Answer[]
  105.      */
  106.     public function getAnswers(): Collection
  107.     {
  108.         return $this->answers;
  109.     }
  110.     public function addAnswer(Answer $answer): self
  111.     {
  112.         if (!$this->answers->contains($answer)) {
  113.             $this->answers[] = $answer;
  114.             $answer->setQuestion($this);
  115.         } elseif ($answer->getQuestion() !== $this) {
  116.             $answer->setQuestion($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeAnswer(Answer $answer): self
  121.     {
  122.         if ($this->answers->removeElement($answer)) {
  123.             // set the owning side to null
  124.             if ($answer->getQuestion() === $this) {
  125.                 $answer->setQuestion(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130.     public function getImages(): Collection
  131.     {
  132.         return $this->images;
  133.     }
  134.     public function addImage(QuestionImage $image): self
  135.     {
  136.         if (!$this->images->contains($image)) {
  137.             $this->images[] = $image;
  138.             $image->setQuestion($this);
  139.         } elseif ($image->getQuestion() !== $this) {
  140.             $image->setQuestion($this);
  141.         }
  142.         return $this;
  143.     }
  144.     public function removeImage(QuestionImage $image): self
  145.     {
  146.         if ($this->images->removeElement($image)) {
  147.             if ($image->getQuestion() === $this) {
  148.                 $image->setQuestion(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153.     public function setAnswers(Collection $answers): self
  154.     {
  155.         $this->answers = new ArrayCollection();
  156.         foreach ($answers as $answer) {
  157.             $this->addAnswer($answer);
  158.         }
  159.         return $this;
  160.     }
  161.     public function setImages(Collection $images): self
  162.     {
  163.         $this->images = new ArrayCollection();
  164.         foreach ($images as $image) {
  165.             $this->addImage($image);
  166.         }
  167.         return $this;
  168.     }
  169.     public function isAddBalance(): bool
  170.     {
  171.         return $this->isAddBalance;
  172.     }
  173.     public function setIsAddBalance(bool $isAddBalance): self
  174.     {
  175.         $this->isAddBalance $isAddBalance;
  176.         return $this;
  177.     }
  178. }