2019-11-06 14:35:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
2019-11-12 11:26:19 +01:00
|
|
|
use DateTimeInterface;
|
2019-11-06 14:35:07 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-11-06 14:54:04 +01:00
|
|
|
use JMS\Serializer\Annotation as Serializer;
|
2019-11-06 14:35:07 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-12 11:26:19 +01:00
|
|
|
* one poll choice, could be a text or a date
|
2019-11-06 14:35:07 +01:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
|
|
|
|
*/
|
|
|
|
class Choice {
|
|
|
|
/**
|
|
|
|
* @ORM\Id()
|
|
|
|
* @ORM\GeneratedValue()
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
2019-11-06 14:54:04 +01:00
|
|
|
* @Serializer\Type("string")
|
2019-11-06 14:35:07 +01:00
|
|
|
*/
|
2019-11-27 20:55:59 +01:00
|
|
|
public $name;
|
2019-11-06 14:35:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="datetime", nullable=true)
|
2019-11-06 14:54:04 +01:00
|
|
|
* @Serializer\Type("datetime")
|
2019-11-06 14:35:07 +01:00
|
|
|
*/
|
2019-11-27 20:55:59 +01:00
|
|
|
public $dateTime;
|
2019-11-06 14:35:07 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-28 11:51:25 +01:00
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="choices", cascade={"persist"})
|
2019-11-06 14:54:04 +01:00
|
|
|
* @Serializer\Type("App\Entity\Poll")
|
2019-11-06 14:35:07 +01:00
|
|
|
*/
|
|
|
|
private $poll;
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-28 11:51:25 +01:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
|
2019-11-12 11:26:19 +01:00
|
|
|
* @Serializer\Type("App\Entity\Vote")
|
|
|
|
*/
|
2019-11-27 20:55:59 +01:00
|
|
|
public $votes;
|
2019-11-06 14:35:07 +01:00
|
|
|
|
2019-11-06 14:54:04 +01:00
|
|
|
public function __construct() {
|
2019-11-28 11:51:25 +01:00
|
|
|
$this->poll = new ArrayCollection();
|
|
|
|
$this->votes = new ArrayCollection();
|
|
|
|
$this->setDateTime( new \DateTime() );
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
public function getId(): ?int {
|
2019-11-28 11:51:25 +01:00
|
|
|
return $this->id;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
|
|
|
public function getName(): ?string {
|
2019-11-28 11:51:25 +01:00
|
|
|
return $this->name;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
2019-11-27 16:14:49 +01:00
|
|
|
public function setName( $name ): self {
|
2019-11-28 11:51:25 +01:00
|
|
|
if ( is_a( $name, 'DateTime' ) ) {
|
|
|
|
$this->setDateTime( $name );
|
|
|
|
$name = $name->format( 'D Y-m-d' );
|
|
|
|
}
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
2019-11-12 11:26:19 +01:00
|
|
|
public function getDateTime(): ?DateTimeInterface {
|
2019-11-28 11:51:25 +01:00
|
|
|
return $this->dateTime;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
2019-11-12 11:26:19 +01:00
|
|
|
public function setDateTime( ?DateTimeInterface $dateTime ): self {
|
2019-11-28 11:51:25 +01:00
|
|
|
$this->dateTime = $dateTime;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-27 11:26:21 +01:00
|
|
|
|
2019-11-27 10:57:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|Vote[]
|
|
|
|
*/
|
2019-11-27 11:26:21 +01:00
|
|
|
public function getVotes(): Collection {
|
2019-11-28 11:51:25 +01:00
|
|
|
return $this->votes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addVote( Vote $vote ): self {
|
|
|
|
if ( ! $this->votes->contains( $vote ) ) {
|
|
|
|
$this->votes[] = $vote;
|
|
|
|
$vote->setChoice( $this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeVote( Vote $vote ): self {
|
|
|
|
if ( $this->votes->contains( $vote ) ) {
|
|
|
|
$this->votes->removeElement( $vote );
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ( $vote->getChoice() === $this ) {
|
|
|
|
$vote->setChoice( null );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPoll(): ?Poll
|
|
|
|
{
|
|
|
|
return $this->poll;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPoll(?Poll $poll): self
|
|
|
|
{
|
|
|
|
$this->poll = $poll;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
}
|