src/Entity/SurveyResponse.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SurveyResponseRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassSurveyResponseRepository::class)]
  8. class SurveyResponse
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\ManyToOne(inversedBy'responses')]
  15.     #[ORM\JoinColumn(nullablefalse)]
  16.     private ?Survey $survey null;
  17.     #[ORM\Column]
  18.     private ?\DateTimeImmutable $submittedAt null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $respondentName null;
  21.     #[ORM\OneToMany(mappedBy'surveyResponse'targetEntityQuestionResponse::class, cascade: ['persist''remove'])]
  22.     private Collection $questionResponses;
  23.     public function __construct()
  24.     {
  25.         $this->questionResponses = new ArrayCollection();
  26.         $this->submittedAt = new \DateTimeImmutable();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getSurvey(): ?Survey
  33.     {
  34.         return $this->survey;
  35.     }
  36.     public function setSurvey(?Survey $survey): self
  37.     {
  38.         $this->survey $survey;
  39.         return $this;
  40.     }
  41.     public function getSubmittedAt(): ?\DateTimeImmutable
  42.     {
  43.         return $this->submittedAt;
  44.     }
  45.     public function getRespondentName(): ?string
  46.     {
  47.         return $this->respondentName;
  48.     }
  49.     public function setRespondentName(?string $respondentName): self
  50.     {
  51.         $this->respondentName $respondentName;
  52.         return $this;
  53.     }
  54.     /**
  55.      * @return Collection<int, QuestionResponse>
  56.      */
  57.     public function getQuestionResponses(): Collection
  58.     {
  59.         return $this->questionResponses;
  60.     }
  61.     public function addQuestionResponse(QuestionResponse $questionResponse): self
  62.     {
  63.         if (!$this->questionResponses->contains($questionResponse)) {
  64.             $this->questionResponses->add($questionResponse);
  65.             $questionResponse->setSurveyResponse($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeQuestionResponse(QuestionResponse $questionResponse): self
  70.     {
  71.         if ($this->questionResponses->removeElement($questionResponse)) {
  72.             if ($questionResponse->getSurveyResponse() === $this) {
  73.                 $questionResponse->setSurveyResponse(null);
  74.             }
  75.         }
  76.         return $this;
  77.     }
  78. }