src/Entity/SurveyContributionQuestion.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as AppAssert;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\SurveyContributionQuestionRepository")
  11.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::TEXT", validationGroups={"TypeText"})
  12.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::TEXTAREA", validationGroups={"TypeTextarea"})
  13.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::SLIDER", validationGroups={"TypeSlider"})
  14.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::CHOICE_UNIQUE_COLLAPSED", validationGroups={"TypeChoiceUnique"})
  15.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::CHOICE_UNIQUE_EXPANDED", validationGroups={"TypeChoiceUnique"})
  16.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::CHOICE_MULTIPLE_COLLAPSED", validationGroups={"TypeChoiceMultiple"})
  17.  * @AppAssert\DynamicValidationGroups(expression="this.getFormQuestion().getType()", value="App\Enum\SurveyFormQuestionType::CHOICE_MULTIPLE_EXPANDED", validationGroups={"TypeChoiceMultiple"})
  18.  * @AppAssert\DynamicValidationGroups(expression="this.hasOtherFormAnswerSelected()", value=true, validationGroups={"TypeWithOther"})
  19.  */
  20. class SurveyContributionQuestion
  21. {
  22.     /**
  23.      * @ORM\Id()
  24.      * @ORM\GeneratedValue()
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @var SurveyContributionStep
  30.      *
  31.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyContributionStep", inversedBy="contributionQuestions")
  32.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  33.      * @Assert\NotNull()
  34.      */
  35.     private $contributionStep;
  36.     /**
  37.      * @var SurveyFormQuestion
  38.      *
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormQuestion")
  40.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  41.      * @Assert\NotNull()
  42.      * @Groups({"surveyContribution:read"})
  43.      */
  44.     private $formQuestion;
  45.     /**
  46.      * @var SurveyCompanySurveyFormQuestion
  47.      *
  48.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyCompanySurveyFormQuestion")
  49.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  50.      * @Assert\NotNull()
  51.      * @Groups({"surveyContribution:read"})
  52.      */
  53.     private $surveyCompanySurveyFormQuestion;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      * @Groups({"surveyContribution:read"})
  59.      */
  60.     private $value;
  61.     /**
  62.      * @var SurveyFormAnswer
  63.      *
  64.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormAnswer")
  65.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  66.      * @Groups({"surveyContribution:read"})
  67.      */
  68.     private $formAnswer;
  69.     /**
  70.      * @var FileTypeAnswer
  71.      *
  72.      * @ORM\ManyToOne(targetEntity="App\Entity\FileTypeAnswer")
  73.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  74.      */
  75.     private $fileTypeAnswer;
  76.     /**
  77.      * @var ArrayCollection
  78.      *
  79.      * @ORM\ManyToMany(targetEntity="App\Entity\SurveyFormAnswer")
  80.      * @Groups({"surveyContribution:read"})
  81.      */
  82.     private $formAnswers;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity="App\Entity\SurveyContributionRankingAnswer", mappedBy="contributionQuestion", cascade={"persist"})
  85.      * @ORM\OrderBy({"position": "ASC"})
  86.      * @Groups({"surveyContribution:read"})
  87.      */
  88.     private $contributionRankingAnswers;
  89.     /**
  90.      * @ORM\OneToOne(targetEntity="App\Entity\SurveyContributionFileUploadAnswer", mappedBy="contributionQuestion", cascade={"persist"})
  91.      * @ORM\JoinColumn(name="file_type_answer_id", referencedColumnName="id", onDelete="SET NULL")
  92.      * @Groups({"surveyContribution:read"})
  93.      */
  94.     private $contributionFileUploadAnswers;
  95.     /**
  96.      * @ORM\OneToOne(targetEntity="App\Entity\SurveyContributionDateTimeAnswer", mappedBy="contributionQuestion", cascade={"persist"})
  97.      * @ORM\JoinColumn(name="date_time_answers_id", referencedColumnName="id", onDelete="SET NULL")
  98.      * @Groups({"surveyContribution:read"})
  99.      */
  100.     private $contributionDateTimeAnswers;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity="App\Entity\SurveyContributionMultiLineOpenEndedAnswer", mappedBy="contributionQuestion", cascade={"persist"})
  103.      * @Groups({"surveyContribution:read"})
  104.      */
  105.     private $contributionMultiLineOpenEndedAnswers;
  106.     /**
  107.      * @var float
  108.      *
  109.      * @ORM\Column(type="float", nullable=true)
  110.      * @Groups({"surveyContribution:read"})
  111.      */
  112.     private $rating;
  113.     /**
  114.      * @var string
  115.      *
  116.      * @ORM\Column(type="string", length=255, nullable=true)
  117.      * @Assert\NotBlank(groups={"TypeWithOther"})
  118.      * @Groups({"surveyContribution:read"})
  119.      */
  120.     private $other;
  121.     /**
  122.      * @ORM\Column(type="boolean", nullable=true)
  123.      * @Assert\Type("bool")
  124.      */
  125.     private $isDraft;
  126.     /**
  127.      * @var string
  128.      *
  129.      * @ORM\Column(type="string", length=45, nullable=true)
  130.      */
  131.     private $sentimentResult;
  132.     /**
  133.      * @var float
  134.      *
  135.      * @ORM\Column(type="float", nullable=true)
  136.      */
  137.     private $sentimentScorePositive;
  138.     /**
  139.      * @var float
  140.      *
  141.      * @ORM\Column(type="float", nullable=true)
  142.      */
  143.     private $sentimentScoreNegative;
  144.     /**
  145.      * @var float
  146.      *
  147.      * @ORM\Column(type="float", nullable=true)
  148.      */
  149.     private $sentimentScoreNeutral;
  150.     /**
  151.      * @var float
  152.      *
  153.      * @ORM\Column(type="float", nullable=true)
  154.      */
  155.     private $sentimentScoreMixed;
  156.     /**
  157.      * @ORM\OneToMany(targetEntity=SurveyContributionMatrixAnswer::class, mappedBy="contributionQuestion",cascade={"persist"} )
  158.      * @Groups({"surveyContribution:read"})
  159.      */
  160.     private $surveyContributionMatrixAnswers;
  161.     public function __construct()
  162.     {
  163.         $this->formAnswers = new ArrayCollection();
  164.         $this->contributionRankingAnswers = new ArrayCollection();
  165.         $this->contributionMultiLineOpenEndedAnswers = new ArrayCollection();
  166.         $this->surveyContributionMatrixAnswers = new ArrayCollection();
  167.     }
  168.     public function getId(): ?int
  169.     {
  170.         return $this->id;
  171.     }
  172.     public function getValue(): ?string
  173.     {
  174.         return $this->value;
  175.     }
  176.     public function setValue(?string $value): self
  177.     {
  178.         $this->value $value;
  179.         return $this;
  180.     }
  181.     public function getContributionStep(): ?SurveyContributionStep
  182.     {
  183.         return $this->contributionStep;
  184.     }
  185.     public function setContributionStep(?SurveyContributionStep $contributionStep): self
  186.     {
  187.         $this->contributionStep $contributionStep;
  188.         return $this;
  189.     }
  190.     public function getFormQuestion(): ?SurveyFormQuestion
  191.     {
  192.         return $this->formQuestion;
  193.     }
  194.     public function setFormQuestion(?SurveyFormQuestion $formQuestion): self
  195.     {
  196.         $this->formQuestion $formQuestion;
  197.         return $this;
  198.     }
  199.     public function getSurveyCompanySurveyFormQuestion(): ?SurveyCompanySurveyFormQuestion
  200.     {
  201.         return $this->surveyCompanySurveyFormQuestion;
  202.     }
  203.     public function setSurveyCompanySurveyFormQuestion(?SurveyCompanySurveyFormQuestion $surveyCompanySurveyFormQuestion): self
  204.     {
  205.         $this->surveyCompanySurveyFormQuestion $surveyCompanySurveyFormQuestion;
  206.         return $this;
  207.     }
  208.     public function getFormAnswer(): ?SurveyFormAnswer
  209.     {
  210.         return $this->formAnswer;
  211.     }
  212.     public function setFormAnswer(?SurveyFormAnswer $formAnswer): self
  213.     {
  214.         $this->formAnswer $formAnswer;
  215.         return $this;
  216.     }
  217.     public function getRating()
  218.     {
  219.         return $this->rating;
  220.     }
  221.     public function setRating($rating): self
  222.     {
  223.         $this->rating $rating;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection|SurveyFormAnswer[]
  228.      */
  229.     public function getFormAnswers(): Collection
  230.     {
  231.         return $this->formAnswers;
  232.     }
  233.     public function addFormAnswer(SurveyFormAnswer $formAnswer): self
  234.     {
  235.         if (!$this->formAnswers->contains($formAnswer)) {
  236.             $this->formAnswers[] = $formAnswer;
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeFormAnswer(SurveyFormAnswer $formAnswer): self
  241.     {
  242.         if ($this->formAnswers->contains($formAnswer)) {
  243.             $this->formAnswers->removeElement($formAnswer);
  244.         }
  245.         return $this;
  246.     }
  247.     public function getOther(): ?string
  248.     {
  249.         return $this->other;
  250.     }
  251.     public function setOther(?string $other): self
  252.     {
  253.         $this->other $other;
  254.         return $this;
  255.     }
  256.     public function getIsDraft(): ?bool
  257.     {
  258.         return $this->isDraft;
  259.     }
  260.     public function setIsDraft(?bool $isDraft): self
  261.     {
  262.         $this->isDraft $isDraft;
  263.         return $this;
  264.     }
  265.     public function hasOtherFormAnswerSelected(): bool
  266.     {
  267.         // choice unique
  268.         if (null !== $this->formAnswer && true === $this->formAnswer->getOther()) {
  269.             return true;
  270.         }
  271.         // choice multiple
  272.         foreach ($this->formAnswers as $formAnswer) {
  273.             /** @var SurveyFormAnswer $formAnswer */
  274.             if (true === $formAnswer->getOther()) {
  275.                 return true;
  276.             }
  277.         }
  278.         return false;
  279.     }
  280.     /**
  281.      * @return Collection|SurveyContributionRankingAnswer[]
  282.      */
  283.     public function getContributionRankingAnswers(): Collection
  284.     {
  285.         return $this->contributionRankingAnswers;
  286.     }
  287.     public function addContributionRankingAnswer(SurveyContributionRankingAnswer $contributionRankingAnswer): self
  288.     {
  289.         if (!$this->contributionRankingAnswers->contains($contributionRankingAnswer)) {
  290.             $this->contributionRankingAnswers[] = $contributionRankingAnswer;
  291.             $contributionRankingAnswer->setContributionQuestion($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeContributionRankingAnswer(SurveyContributionRankingAnswer $contributionRankingAnswer): self
  296.     {
  297.         if ($this->contributionRankingAnswers->contains($contributionRankingAnswer)) {
  298.             $this->contributionRankingAnswers->removeElement($contributionRankingAnswer);
  299.             // set the owning side to null (unless already changed)
  300.             if ($contributionRankingAnswer->getContributionQuestion() === $this) {
  301.                 $contributionRankingAnswer->setContributionQuestion(null);
  302.             }
  303.         }
  304.         return $this;
  305.     }
  306.     // #################################################################################################################
  307.     /**
  308.      * @return Collection|SurveyContributionMultiLineOpenEndedAnswer[]
  309.      */
  310.     public function getContributionMultiLineOpenEndedAnswers(): Collection
  311.     {
  312.         return $this->contributionMultiLineOpenEndedAnswers;
  313.     }
  314.     public function addContributionMultiLineOpenEndedAnswer(SurveyContributionMultiLineOpenEndedAnswer $contributionMultiLineOpenEndedAnswer): self
  315.     {
  316.         if (!$this->contributionMultiLineOpenEndedAnswers->contains($contributionMultiLineOpenEndedAnswer)) {
  317.             $this->contributionMultiLineOpenEndedAnswers[] = $contributionMultiLineOpenEndedAnswer;
  318.             $contributionMultiLineOpenEndedAnswer->setContributionQuestion($this);
  319.         }
  320.         return $this;
  321.     }
  322.     public function removeContributionMultiLineOpenEndedAnswers(SurveyContributionMultiLineOpenEndedAnswer $contributionMultiLineOpenEndedAnswer): self
  323.     {
  324.         if ($this->contributionMultiLineOpenEndedAnswers->contains($contributionMultiLineOpenEndedAnswer)) {
  325.             $this->contributionMultiLineOpenEndedAnswers->removeElement($contributionMultiLineOpenEndedAnswer);
  326.             // set the owning side to null (unless already changed)
  327.             if ($contributionMultiLineOpenEndedAnswer->getContributionQuestion() === $this) {
  328.                 $contributionMultiLineOpenEndedAnswer->setContributionQuestion(null);
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     // ##################################################################################################################
  334.     public function isAnswered(): bool
  335.     {
  336.         return null !== $this->getValue() || null !== $this->getFormAnswer() || $this->getFormAnswers()->count() || null !== $this->getRating() || null !== $this->getOther();
  337.     }
  338.     public function getSentimentResult(): ?string
  339.     {
  340.         return $this->sentimentResult;
  341.     }
  342.     public function setSentimentResult(?string $sentimentResult): self
  343.     {
  344.         $this->sentimentResult $sentimentResult;
  345.         return $this;
  346.     }
  347.     public function getSentimentScorePositive(): ?float
  348.     {
  349.         return $this->sentimentScorePositive;
  350.     }
  351.     public function setSentimentScorePositive(?float $sentimentScorePositive): self
  352.     {
  353.         $this->sentimentScorePositive $sentimentScorePositive;
  354.         return $this;
  355.     }
  356.     public function getSentimentScoreNegative(): ?float
  357.     {
  358.         return $this->sentimentScoreNegative;
  359.     }
  360.     public function setSentimentScoreNegative(?float $sentimentScoreNegative): self
  361.     {
  362.         $this->sentimentScoreNegative $sentimentScoreNegative;
  363.         return $this;
  364.     }
  365.     public function getSentimentScoreNeutral(): ?float
  366.     {
  367.         return $this->sentimentScoreNeutral;
  368.     }
  369.     public function setSentimentScoreNeutral(?float $sentimentScoreNeutral): self
  370.     {
  371.         $this->sentimentScoreNeutral $sentimentScoreNeutral;
  372.         return $this;
  373.     }
  374.     public function getSentimentScoreMixed(): ?float
  375.     {
  376.         return $this->sentimentScoreMixed;
  377.     }
  378.     public function setSentimentScoreMixed(?float $sentimentScoreMixed): self
  379.     {
  380.         $this->sentimentScoreMixed $sentimentScoreMixed;
  381.         return $this;
  382.     }
  383.     public function getContributionFileUploadAnswers(): ?SurveyContributionFileUploadAnswer
  384.     {
  385.         return $this->contributionFileUploadAnswers;
  386.     }
  387.     public function setContributionFileUploadAnswers(SurveyContributionFileUploadAnswer $contributionFileUploadAnswers): self
  388.     {
  389.         if ($contributionFileUploadAnswers) {
  390.             $this->contributionFileUploadAnswers $contributionFileUploadAnswers;
  391.             return $this;
  392.         }
  393.     }
  394.     public function getContributionDateTimeAnswers(): ?SurveyContributionDateTimeAnswer
  395.     {
  396.         return $this->contributionDateTimeAnswers;
  397.     }
  398.     public function setContributionDateTimeAnswers(?SurveyContributionDateTimeAnswer $contributionDateTimeAnswers): self
  399.     {
  400.         if ($contributionDateTimeAnswers) {
  401.             $this->contributionDateTimeAnswers $contributionDateTimeAnswers;
  402.             return $this;
  403.         }
  404.     }
  405.     public function getFileTypeAnswer(): ?FileTypeAnswer
  406.     {
  407.         return $this->fileTypeAnswer;
  408.     }
  409.     public function setFileTypeAnswer(FileTypeAnswer $fileTypeAnswer): self
  410.     {
  411.         if ($fileTypeAnswer) {
  412.             $this->fileTypeAnswer $fileTypeAnswer;
  413.             return $this;
  414.         }
  415.     }
  416.     /**
  417.      * @return Collection|SurveyContributionMatrixAnswer[]
  418.      */
  419.     public function getSurveyContributionMatrixAnswers(): Collection
  420.     {
  421.         return $this->surveyContributionMatrixAnswers;
  422.     }
  423.     public function addSurveyContributionMatrixAnswer(SurveyContributionMatrixAnswer $surveyContributionMatrixAnswer): self
  424.     {
  425.         if (!$this->surveyContributionMatrixAnswers->contains($surveyContributionMatrixAnswer)) {
  426.             $this->surveyContributionMatrixAnswers[] = $surveyContributionMatrixAnswer;
  427.             $surveyContributionMatrixAnswer->setContributionQuestion($this);
  428.         }
  429.         return $this;
  430.     }
  431.     public function removeSurveyContributionMatrixAnswer(SurveyContributionMatrixAnswer $surveyContributionMatrixAnswer): self
  432.     {
  433.         if ($this->surveyContributionMatrixAnswers->removeElement($surveyContributionMatrixAnswer)) {
  434.             // set the owning side to null (unless already changed)
  435.             if ($surveyContributionMatrixAnswer->getContributionQuestion() === $this) {
  436.                 $surveyContributionMatrixAnswer->setContributionQuestion(null);
  437.             }
  438.         }
  439.         return $this;
  440.     }
  441. }