date-poll-api/src/Entity/Choice.php

130 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Entity;
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;
/**
* @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")
*/
private $name;
/**
* @ORM\Column(type="datetime", nullable=true)
2019-11-06 14:54:04 +01:00
* @Serializer\Type("datetime")
*/
private $dateTime;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
2019-11-06 14:54:04 +01:00
* @Serializer\Type("App\Entity\Poll")
*/
private $poll;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="choice")
2019-11-06 14:54:04 +01:00
* @Serializer\Type("App\Entity\Choice")
*/
private $votes;
2019-11-06 14:54:04 +01:00
public function __construct() {
$this->poll = new ArrayCollection();
$this->votes = new ArrayCollection();
}
public function getId(): ?int {
2019-11-06 14:54:04 +01:00
return $this->id;
}
public function getName(): ?string {
2019-11-06 14:54:04 +01:00
return $this->name;
}
public function setName( string $name ): self {
2019-11-06 14:54:04 +01:00
$this->name = $name;
return $this;
}
public function getDateTime(): ?\DateTimeInterface {
2019-11-06 14:54:04 +01:00
return $this->dateTime;
}
public function setDateTime( ?\DateTimeInterface $dateTime ): self {
2019-11-06 14:54:04 +01:00
$this->dateTime = $dateTime;
return $this;
}
/**
* @return Collection|Poll[]
*/
public function getPoll(): Collection {
return $this->poll;
}
public function addPoll( Poll $poll ): self {
if ( ! $this->poll->contains( $poll ) ) {
$this->poll[] = $poll;
$poll->setChoices( $this );
}
return $this;
}
public function removePoll( Poll $poll ): self {
if ( $this->poll->contains( $poll ) ) {
$this->poll->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getChoices() === $this ) {
$poll->setChoices( null );
}
}
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getVotes(): Collection {
return $this->votes;
}
public function addVote( Choice $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setChoice( $this );
}
return $this;
}
public function removeVote( Choice $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;
}
}