<?php namespace App\Entity; use App\Repository\AnswerRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=AnswerRepository::class) */ class Answer { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $text; /** * @ORM\Column(type="boolean", options={"default":false}) */ private $isRight = FALSE; /** * @ORM\Column(type="integer", nullable=true) */ private $orderIndex; /** * @ORM\ManyToOne(targetEntity=Question::class, inversedBy="answers") */ private $question; /** * @ORM\OneToMany(targetEntity=UserAnswer::class, mappedBy="answer") */ private $userAnswers; public function __construct() { $this->userAnswers = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getText(): ?string { return $this->text; } public function setText( string $text ): self { $this->text = $text; return $this; } public function getIsRight(): ?bool { return $this->isRight; } public function setIsRight( bool $isRight ): self { $this->isRight = $isRight; return $this; } public function getOrderIndex(): ?int { return $this->orderIndex; } public function setOrderIndex( ?int $orderIndex ): self { $this->orderIndex = $orderIndex; return $this; } public function getQuestion(): ?Question { return $this->question; } public function setQuestion( ?Question $question ): self { $this->question = $question; return $this; } /** * @return Collection|UserAnswer[] */ public function getUserAnswers(): Collection { return $this->userAnswers; } public function addUserAnswer( UserAnswer $userAnswer ): self { if ( !$this->userAnswers->contains( $userAnswer ) ) { $this->userAnswers[] = $userAnswer; $userAnswer->setAnswer( $this ); } return $this; } public function removeUserAnswer( UserAnswer $userAnswer ): self { if ( $this->userAnswers->removeElement( $userAnswer ) ) { // set the owning side to null (unless already changed) if ( $userAnswer->getAnswer() === $this ) { $userAnswer->setAnswer( NULL ); } } return $this; } }