120 lines
2.3 KiB
PHP
120 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\OptionRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* @ORM\Entity(repositoryClass=OptionRepository::class)
|
|
* @ORM\Table(name="`option`")
|
|
*/
|
|
class Option
|
|
{
|
|
/**
|
|
* @ORM\Id()
|
|
* @ORM\GeneratedValue()
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @ORM\Column(name="date", type="datetime")
|
|
*/
|
|
private $date;
|
|
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
private $choiced;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="option", cascade={"persist"}, orphanRemoval=true)
|
|
*/
|
|
private $votes;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Survey", inversedBy="options")
|
|
*/
|
|
private $survey;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->votes = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getDate(): ?\DateTimeInterface
|
|
{
|
|
return $this->date;
|
|
}
|
|
|
|
public function setDate(\DateTimeInterface $date): self
|
|
{
|
|
$this->date = $date;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getChoiced(): ?bool
|
|
{
|
|
return $this->choiced;
|
|
}
|
|
|
|
public function setChoiced(bool $choiced): self
|
|
{
|
|
$this->choiced = $choiced;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Vote[]
|
|
*/
|
|
public function getVotes(): Collection
|
|
{
|
|
return $this->votes;
|
|
}
|
|
|
|
public function addVote(Vote $vote): self
|
|
{
|
|
if (!$this->votes->contains($vote)) {
|
|
$this->votes[] = $vote;
|
|
$vote->setOption($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeVote(Vote $vote): self
|
|
{
|
|
if ($this->votes->removeElement($vote)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($vote->getOption() === $this) {
|
|
$vote->setOption(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSurvey(): ?Survey
|
|
{
|
|
return $this->survey;
|
|
}
|
|
|
|
public function setSurvey(?Survey $survey): self
|
|
{
|
|
$this->survey = $survey;
|
|
|
|
return $this;
|
|
}
|
|
|
|
}
|