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

112 lines
2.4 KiB
PHP

<?php
namespace App\Entity;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
*/
class Vote {
/**
* for a text kind of choice: could be "yes" "no" "maybe" and emptu.
* for a date kind, the choice linked is equivalent to the value selected
* @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Type("string")
*/
public $value;
/**
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
* @Serializer\Type("datetime")
*/
public $creationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\choice")
*/
public $choice;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Serializer\Type("integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes")
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\Poll")
*/
private $poll;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\StackOfVotes")
*/
private $stackOfVotes;
public function __construct() {
$this->setCreationDate( new \DateTime() );
}
public function getId(): ?int {
return $this->id;
}
public function getPoll(): ?Poll {
return $this->poll;
}
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
if ( $poll ) {
$poll->addVote( $this );
}
return $this;
}
public function getChoice(): ?Choice {
return $this->choice;
}
public function setChoice( ?Choice $choice ): self {
$this->choice = $choice;
return $this;
}
public function getValue(): ?string {
return $this->value;
}
public function setValue( ?string $value ): self {
$this->value = $value;
return $this;
}
public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate;
}
public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
return $this;
}
public function getStackOfVotes(): ?StackOfVotes {
return $this->stackOfVotes;
}
public function setStackOfVotes( ?StackOfVotes $stackOfVotes ): self {
$this->stackOfVotes = $stackOfVotes;
return $this;
}
}