src/Entity/UserResponse.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\UserResponseRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserResponseRepository::class)
  11.  */
  12. class UserResponse
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      * @Groups({"user_response:read"})
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="userResponses")
  23.      * @ORM\JoinColumn(nullable=true)
  24.      */
  25.     private $tvUser;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="userResponses")
  28.      * @ORM\JoinColumn(nullable=true)
  29.      * @Assert\NotNull
  30.      */
  31.     private $user;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Question::class, inversedBy="userResponses")
  34.      * @ORM\JoinColumn(nullable=false)
  35.      * @Groups({"user_response:read"})
  36.      */
  37.     private $question;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity=Answer::class)
  40.      * @ORM\JoinColumn(nullable=true)
  41.      * @Groups({"user_response:read"})
  42.      */
  43.     private $answer;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      * @Groups({"user_response:read"})
  47.      */
  48.     private $value;
  49.     /**
  50.      * @ORM\Column(type="datetime")
  51.      * @Gedmo\Timestampable(on="create")
  52.      */
  53.     private $createdAt;
  54.     /**
  55.      * @ORM\Column(type="datetime")
  56.      * @Gedmo\Timestampable(on="update")
  57.      */
  58.     private $updatedAt;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=TvTag::class, inversedBy="userResponses")
  61.      * @Groups({"user_response:read"})
  62.      */
  63.     private $tvTag;
  64.     /**
  65.      * @ORM\Column(type="integer", length=255, nullable=true)
  66.      * @Groups({"user_response:read"})
  67.      */
  68.     private $nbAnswer 1;
  69.     /**
  70.      * @ORM\Column(type="boolean", options={"default": 0})
  71.      * @Groups({"user_response:read"})
  72.      */
  73.     private $stopAsk false;
  74.     /**
  75.      * @ORM\Column(type="json", nullable=true)
  76.      */
  77.     private $datas = [];
  78.     /**
  79.      * @ORM\ManyToOne(targetEntity=Survey::class, inversedBy="userResponses")
  80.      */
  81.     private $survey;
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getTvUser(): ?TvUser
  87.     {
  88.         return $this->tvUser;
  89.     }
  90.     public function setTvUser(?TvUser $tvUser): self
  91.     {
  92.         $this->tvUser $tvUser;
  93.         return $this;
  94.     }
  95.     public function getUser(): ?User
  96.     {
  97.         return $this->user;
  98.     }
  99.     public function setUser(?User $user): self
  100.     {
  101.         $this->user $user;
  102.         return $this;
  103.     }
  104.     public function getQuestion(): ?Question
  105.     {
  106.         return $this->question;
  107.     }
  108.     public function setQuestion(?Question $question): self
  109.     {
  110.         $this->question $question;
  111.         return $this;
  112.     }
  113.     public function getAnswer(): ?Answer
  114.     {
  115.         return $this->answer;
  116.     }
  117.     public function setAnswer(?Answer $answer): self
  118.     {
  119.         $this->answer $answer;
  120.         $question = ($answer instanceof Answer && $answer->getQuestion() instanceof Question) ? $answer->getQuestion() : null;
  121.         $survey = ($question instanceof Question && $question->getSurvey() instanceof Survey) ? $question->getSurvey() : null;
  122.         $value = ($answer instanceof Answer && is_null($this->getValue())) ? $answer->getValue() : $this->getValue();
  123.         $tvTag null;
  124.         if($survey instanceof Survey) {
  125.             $tvTag $survey->getTvTag();
  126.         }
  127.         if($question instanceof Question && empty($tvTag) ) {
  128.             $tvTag $question->getTvTag();
  129.         }
  130.         
  131.         $this->setQuestion($question);
  132.         $this->setSurvey($survey);
  133.         $this->setValue($value);
  134.         $this->setTvTag($tvTag);
  135.         return $this;
  136.     }
  137.     public function getValue(): ?string
  138.     {
  139.         return $this->value;
  140.     }
  141.     public function setValue(?string $value): self
  142.     {
  143.         $this->value $value;
  144.         return $this;
  145.     }
  146.     public function getCreatedAt(): ?\DateTimeInterface
  147.     {
  148.         return $this->createdAt;
  149.     }
  150.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  151.     {
  152.         $this->createdAt $createdAt;
  153.         return $this;
  154.     }
  155.     public function getUpdatedAt(): ?\DateTimeInterface
  156.     {
  157.         return $this->updatedAt;
  158.     }
  159.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  160.     {
  161.         $this->updatedAt $updatedAt;
  162.         return $this;
  163.     }
  164.     public function getTvTag(): ?TvTag
  165.     {
  166.         return $this->tvTag;
  167.     }
  168.     public function setTvTag(?TvTag $tvTag): self
  169.     {
  170.         $this->tvTag $tvTag;
  171.         return $this;
  172.     }
  173.     public function getNbAnswer(): ?int
  174.     {
  175.         return $this->nbAnswer;
  176.     }
  177.     public function setNbAnswer(?int $nbAnswer): self
  178.     {
  179.         $this->nbAnswer $nbAnswer;
  180.         return $this;
  181.     }
  182.     public function getStopAsk(): ?bool
  183.     {
  184.         return $this->stopAsk;
  185.     }
  186.     public function setStopAsk(?bool $stopAsk): self
  187.     {
  188.         $this->stopAsk $stopAsk;
  189.         return $this;
  190.     }
  191.     public function getDatas(): ?array
  192.     {
  193.         return $this->datas;
  194.     }
  195.     public function setDatas(?array $datas): self
  196.     {
  197.         $this->datas $datas;
  198.         return $this;
  199.     }
  200.     public function getSurvey(): ?Survey
  201.     {
  202.         return $this->survey;
  203.     }
  204.     public function setSurvey(?Survey $survey): self
  205.     {
  206.         $this->survey $survey;
  207.         if(!empty($survey)) {
  208.             $nbAnswer $survey->nbSubmited 1;
  209.             $this->setNbAnswer($nbAnswer);
  210.         }
  211.         return $this;
  212.     }
  213. }