<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\SurveyFormAnswerRepository")
*/
class SurveyFormAnswer
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255,nullable=true)
* @Assert\Length(max="255")
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $value;
/**
* @var int
*
* @ORM\Column(type="integer",nullable=true)
* @Assert\Type(type="integer")
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $position;
/**
* @var float
*
* @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $rating;
/**
* @var SurveyFormQuestion
*
* @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormQuestion", inversedBy="formAnswers")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Assert\NotNull()
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $formQuestion;
/**
* @var bool
*
* @ORM\Column(type="boolean")
* @Assert\Type(type="bool")
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $other;
/**
* @var bool
*
* @ORM\Column(type="boolean")
* @Assert\Type(type="bool")
*/
private $isAssociated;
/**
* @var ArrayCollection|SurveyFormQuestion[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\SurveyFormQuestion")
* @ORM\OrderBy({"position" = "ASC"})
* @Groups({"pinpointCampaign:list","surveyContribution:read"})
*/
private $formQuestions;
public function __construct()
{
$this->position = 0;
$this->other = false;
$this->isAssociated = 0;
$this->formQuestions = new ArrayCollection();
}
public function __toString()
{
return $this->getValue();
}
public function getId(): ?int
{
return $this->id;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(string $value): self
{
$this->value = $value;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getFormQuestion(): ?SurveyFormQuestion
{
return $this->formQuestion;
}
public function setFormQuestion(?SurveyFormQuestion $formQuestion): self
{
$this->formQuestion = $formQuestion;
if ($this->other && $this->formQuestion) {
$this->formQuestion->setOtherAnswerText($this->value);
}
return $this;
}
public function getOther(): ?bool
{
return $this->other;
}
public function setOther(bool $other): self
{
$this->other = $other;
return $this;
}
public function getIsAssociated(): ?bool
{
return $this->isAssociated;
}
public function setIsAssociated(bool $isAssociated): self
{
$this->isAssociated = $isAssociated;
return $this;
}
public function getRating()
{
return $this->rating;
}
public function setRating($rating): self
{
$this->rating = $rating;
return $this;
}
/**
* @return Collection|SurveyFormQuestion[]
*/
public function getformQuestions(): Collection
{
return $this->formQuestions->map(function ($formQuestion) {
return '/api/survey_form_questions/' . $formQuestion->getId();
});
}
public function addFormQuestion(SurveyFormQuestion $formQuestion): self
{
if (!$this->formQuestions->contains($formQuestion)) {
$this->formQuestions[] = $formQuestion;
}
return $this;
}
public function removeFormQuestion(SurveyFormQuestion $formQuestion): self
{
if ($this->formQuestions->contains($formQuestion)) {
$this->formQuestions->removeElement($formQuestion);
}
return $this;
}
}