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

132 lines
3.1 KiB
PHP
Raw Normal View History

2019-10-25 14:59:20 +02:00
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\PollRepository")
*/
class Poll {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="datetime")
*/
private $creationDate;
/**
* @ORM\Column(type="datetime")
*/
private $expiracyDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="polls")
* @ORM\JoinColumn(nullable=false)
*/
private $owner;
/**
* used to allow administration
* @ORM\Column(type="string", length=255)
*/
private $adminKey;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true)
*/
private $votes;
public function __construct()
{
$this->votes = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
public function getTitle(): ?string {
return $this->title;
}
public function setTitle( string $title ): self {
$this->title = $title;
return $this;
}
public function getCreationDate(): ?\DateTimeInterface {
return $this->creationDate;
}
public function setCreationDate( \DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
return $this;
}
public function getExpiracyDate(): ?\DateTimeInterface {
return $this->expiracyDate;
}
public function setExpiracyDate( \DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate;
return $this;
}
public function getOwner(): ?Owner {
return $this->owner;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
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->setPoll($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->getPoll() === $this) {
$vote->setPoll(null);
}
}
return $this;
}
}