<?php
namespace App\Entity;
use App\Repository\TopicRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(TopicRepository::class)]
class Topic
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id;
#[ORM\Column()]
private ?string $name;
#[ORM\OneToMany('topic', Question::class)]
private Collection $questions;
public function __construct()
{
$this->questions = new ArrayCollection();
}
public function __toString(): string
{
return $this->codename;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Question>
*/
public function getQuestions(): Collection
{
return $this->questions;
}
public function addQuestion(Question $question): self
{
if (!$this->questions->contains($question)) {
$this->questions->add($question);
$question->setTopic($this);
}
return $this;
}
public function removeQuestion(Question $question): self
{
if ($this->questions->removeElement($question)) {
// set the owning side to null (unless already changed)
if ($question->getTopic() === $this) {
$question->setTopic(null);
}
}
return $this;
}
}