src/Entity/SurveyFormAnswer.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\SurveyFormAnswerRepository")
  10.  */
  11. class SurveyFormAnswer
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  18.      */
  19.     private $id;
  20.     /**
  21.      * @var string
  22.      *
  23.      * @ORM\Column(type="string", length=255,nullable=true)
  24.      * @Assert\Length(max="255")
  25.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  26.      */
  27.     private $value;
  28.     /**
  29.      * @var int
  30.      *
  31.      * @ORM\Column(type="integer",nullable=true)
  32.      * @Assert\Type(type="integer")
  33.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  34.      */
  35.     private $position;
  36.     /**
  37.      * @var float
  38.      *
  39.      * @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
  40.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  41.      */
  42.     private $rating;
  43.     /**
  44.      * @var SurveyFormQuestion
  45.      *
  46.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormQuestion", inversedBy="formAnswers")
  47.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  48.      * @Assert\NotNull()
  49.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  50.      */
  51.     private $formQuestion;
  52.     /**
  53.      * @var bool
  54.      *
  55.      * @ORM\Column(type="boolean")
  56.      * @Assert\Type(type="bool")
  57.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  58.      */
  59.     private $other;
  60.     /**
  61.      * @var bool
  62.      *
  63.      * @ORM\Column(type="boolean")
  64.      * @Assert\Type(type="bool")
  65.      */
  66.     private $isAssociated;
  67.     /**
  68.      * @var ArrayCollection|SurveyFormQuestion[]
  69.      *
  70.      * @ORM\ManyToMany(targetEntity="App\Entity\SurveyFormQuestion")
  71.      * @ORM\OrderBy({"position" = "ASC"})
  72.      * @Groups({"pinpointCampaign:list","surveyContribution:read"})
  73.      */
  74.     private $formQuestions;
  75.     public function __construct()
  76.     {
  77.         $this->position 0;
  78.         $this->other false;
  79.         $this->isAssociated 0;
  80.         $this->formQuestions = new ArrayCollection();
  81.     }
  82.     public function __toString()
  83.     {
  84.         return $this->getValue();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function getValue(): ?string
  91.     {
  92.         return $this->value;
  93.     }
  94.     public function setValue(string $value): self
  95.     {
  96.         $this->value $value;
  97.         return $this;
  98.     }
  99.     public function getPosition(): ?int
  100.     {
  101.         return $this->position;
  102.     }
  103.     public function setPosition(int $position): self
  104.     {
  105.         $this->position $position;
  106.         return $this;
  107.     }
  108.     public function getFormQuestion(): ?SurveyFormQuestion
  109.     {
  110.         return $this->formQuestion;
  111.     }
  112.     public function setFormQuestion(?SurveyFormQuestion $formQuestion): self
  113.     {
  114.         $this->formQuestion $formQuestion;
  115.         if ($this->other && $this->formQuestion) {
  116.             $this->formQuestion->setOtherAnswerText($this->value);
  117.         }
  118.         return $this;
  119.     }
  120.     public function getOther(): ?bool
  121.     {
  122.         return $this->other;
  123.     }
  124.     public function setOther(bool $other): self
  125.     {
  126.         $this->other $other;
  127.         return $this;
  128.     }
  129.     public function getIsAssociated(): ?bool
  130.     {
  131.         return $this->isAssociated;
  132.     }
  133.     public function setIsAssociated(bool $isAssociated): self
  134.     {
  135.         $this->isAssociated $isAssociated;
  136.         return $this;
  137.     }
  138.     public function getRating()
  139.     {
  140.         return $this->rating;
  141.     }
  142.     public function setRating($rating): self
  143.     {
  144.         $this->rating $rating;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection|SurveyFormQuestion[]
  149.      */
  150.     public function getformQuestions(): Collection
  151.     {
  152.         return $this->formQuestions->map(function ($formQuestion) {
  153.             return '/api/survey_form_questions/' $formQuestion->getId();
  154.         });
  155.     }
  156.     public function addFormQuestion(SurveyFormQuestion $formQuestion): self
  157.     {
  158.         if (!$this->formQuestions->contains($formQuestion)) {
  159.             $this->formQuestions[] = $formQuestion;
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeFormQuestion(SurveyFormQuestion $formQuestion): self
  164.     {
  165.         if ($this->formQuestions->contains($formQuestion)) {
  166.             $this->formQuestions->removeElement($formQuestion);
  167.         }
  168.         return $this;
  169.     }
  170. }