<?php
namespace App\Entity;
use App\Repository\SurveyResponseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SurveyResponseRepository::class)]
class SurveyResponse
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'responses')]
#[ORM\JoinColumn(nullable: false)]
private ?Survey $survey = null;
#[ORM\Column]
private ?\DateTimeImmutable $submittedAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $respondentName = null;
#[ORM\OneToMany(mappedBy: 'surveyResponse', targetEntity: QuestionResponse::class, cascade: ['persist', 'remove'])]
private Collection $questionResponses;
public function __construct()
{
$this->questionResponses = new ArrayCollection();
$this->submittedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
public function getSubmittedAt(): ?\DateTimeImmutable
{
return $this->submittedAt;
}
public function getRespondentName(): ?string
{
return $this->respondentName;
}
public function setRespondentName(?string $respondentName): self
{
$this->respondentName = $respondentName;
return $this;
}
/**
* @return Collection<int, QuestionResponse>
*/
public function getQuestionResponses(): Collection
{
return $this->questionResponses;
}
public function addQuestionResponse(QuestionResponse $questionResponse): self
{
if (!$this->questionResponses->contains($questionResponse)) {
$this->questionResponses->add($questionResponse);
$questionResponse->setSurveyResponse($this);
}
return $this;
}
public function removeQuestionResponse(QuestionResponse $questionResponse): self
{
if ($this->questionResponses->removeElement($questionResponse)) {
if ($questionResponse->getSurveyResponse() === $this) {
$questionResponse->setSurveyResponse(null);
}
}
return $this;
}
}