<?php
namespace App\Entity\Survey;
use App\Entity\PrimaryIdTrait;
use App\Repository\Survey\QuestionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: QuestionRepository::class)]
class Question
{
public const TEXT = 0;
public const TEXTAREA = 1;
public const RADIOBUTTON = 2;
public const CHECKBOX = 3;
public const SELECT = 4;
public const CHECKBOXONE = 5;
public const TYPE = [
self::TEXT => 'question.type.text',
self::TEXTAREA => 'question.type.textarea',
self::RADIOBUTTON => 'question.type.radiobutton',
self::CHECKBOX => 'question.type.checkbox',
self::SELECT => 'question.type.select',
self::CHECKBOXONE => 'question.type.checkboxone'
];
public const REQUIRING_ANSWER = [
self::TEXT => 0,
self::TEXTAREA => 0,
self::RADIOBUTTON => 1,
self::CHECKBOX => 1,
self::SELECT => 1,
self::CHECKBOXONE => 0
];
public const NO = 0;
public const YES = 1;
public const REQUIRED = [
self::NO => 'question.required.no',
self::YES => 'question.required.yes'
];
use PrimaryIdTrait;
use TimestampableEntity;
#[ORM\Column(type: 'string')]
#[Groups(['survey', 'childrenQuestions'])]
private string $wording;
#[ORM\Column(type: 'integer')]
#[Groups(['survey', 'childrenQuestions'])]
private int $type;
#[ORM\Column(type: 'boolean')]
#[Groups(['survey', 'childrenQuestions'])]
private bool $required;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\SurveyQuestion', mappedBy: 'question', cascade: ['remove'])]
public $surveyQuestion;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\QuestionAnswer', mappedBy: 'question', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['sort' => 'ASC'])]
#[Groups(['survey', 'childrenQuestions'])]
public $questionAnswer;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\SurveyResultData', mappedBy: 'question', cascade: ['remove'])]
public $surveyResultData;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\AnswerQuestion', mappedBy: 'question', cascade: ['remove'])]
public $answerQuestion;
public function __construct()
{
$this->surveyQuestion = new ArrayCollection();
$this->questionAnswer = new ArrayCollection();
$this->surveyResultData = new ArrayCollection();
$this->answerQuestion = new ArrayCollection();
}
public function getWording(): string
{
return $this->wording;
}
public function setWording(string $wording): void
{
$this->wording = $wording;
}
public function getType(): int
{
return $this->type;
}
public function setType(int $type): void
{
$this->type = $type;
}
public function getRequired(): bool
{
return $this->required;
}
public function setRequired(bool $required): void
{
$this->required = $required;
}
/**
* @return Collection|SurveyQuestion[]
*/
public function getSurveyQuestion(): Collection
{
return $this->surveyQuestion;
}
/**
* @return Collection|QuestionAnswer[]
*/
public function getQuestionAnswer(): Collection
{
return $this->questionAnswer;
}
public function addQuestionAnswer(QuestionAnswer $questionAnswer): void
{
$questionAnswer->setQuestion($this);
$this->questionAnswer->add($questionAnswer);
}
public function removeQuestionAnswer(QuestionAnswer $questionAnswer): void
{
if ($this->questionAnswer->contains($questionAnswer)) {
$this->questionAnswer->removeElement($questionAnswer);
}
}
/**
* @return Collection|SurveyResultData[]
*/
public function getSurveyResultData(): Collection
{
return $this->surveyResultData;
}
/**
* @return Collection|AnswerQuestion[]
*/
public function getAnswerQuestion(): Collection
{
return $this->answerQuestion;
}
}