<?php
namespace App\Entity;
use App\Repository\QuestionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=QuestionRepository::class)
* @ORM\Table(name="app_question")
*/
class Question
{
const TYPE_CHOICE = 'choice';
const TYPE_MULTI = 'multi';
const TYPE_IMG = 'img';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* Текст вопроса
* @ORM\Column(type="text", length=500, nullable=true)
*/
private ?string $text = null;
/**
* Текст вопроса
* @ORM\Column(type="text", length=500, nullable=true)
*/
private ?string $textLocal = null;
/**
* Тип вопроса (например, single_choice, multiple_choice, yes_no, etc.)
* @ORM\Column(type="string", length=50, nullable=true)
*/
private ?string $type = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Survey", inversedBy="questions")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private ?Survey $survey;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Answer", mappedBy="question", cascade={"persist", "remove"})
*/
private Collection $answers;
/**
* @ORM\OneToMany(targetEntity="App\Entity\QuestionImage", mappedBy="question", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private Collection $images;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $isAddBalance = false;
public function __construct()
{
$this->answers = new ArrayCollection();
$this->images = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function __toString(): ?string
{
return $this->getText() ?? $this->getId();
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
public function getTextLocal(): ?string
{
return $this->textLocal;
}
public function setTextLocal(?string $textLocal): self
{
$this->textLocal = $textLocal;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
/**
* @return Collection|Answer[]
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
$answer->setQuestion($this);
} elseif ($answer->getQuestion() !== $this) {
$answer->setQuestion($this);
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
if ($this->answers->removeElement($answer)) {
// set the owning side to null
if ($answer->getQuestion() === $this) {
$answer->setQuestion(null);
}
}
return $this;
}
public function getImages(): Collection
{
return $this->images;
}
public function addImage(QuestionImage $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setQuestion($this);
} elseif ($image->getQuestion() !== $this) {
$image->setQuestion($this);
}
return $this;
}
public function removeImage(QuestionImage $image): self
{
if ($this->images->removeElement($image)) {
if ($image->getQuestion() === $this) {
$image->setQuestion(null);
}
}
return $this;
}
public function setAnswers(Collection $answers): self
{
$this->answers = new ArrayCollection();
foreach ($answers as $answer) {
$this->addAnswer($answer);
}
return $this;
}
public function setImages(Collection $images): self
{
$this->images = new ArrayCollection();
foreach ($images as $image) {
$this->addImage($image);
}
return $this;
}
public function isAddBalance(): bool
{
return $this->isAddBalance;
}
public function setIsAddBalance(bool $isAddBalance): self
{
$this->isAddBalance = $isAddBalance;
return $this;
}
}