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

112 lines
2.4 KiB
PHP
Raw Normal View History

2019-10-25 14:59:20 +02:00
<?php
namespace App\Entity;
2019-11-12 11:26:19 +01:00
use DateTimeInterface;
2019-10-25 14:59:20 +02:00
use Doctrine\ORM\Mapping as ORM;
2019-11-06 14:54:04 +01:00
use JMS\Serializer\Annotation as Serializer;
2019-10-25 14:59:20 +02:00
/**
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
*/
class Vote {
/**
2019-11-12 11:26:19 +01:00
* 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")
2019-10-25 14:59:20 +02:00
*/
public $value;
2019-10-25 14:59:20 +02:00
/**
2019-11-27 17:07:11 +01:00
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
2019-11-06 14:54:04 +01:00
* @Serializer\Type("datetime")
2019-10-25 14:59:20 +02:00
*/
2019-11-06 14:54:04 +01:00
public $creationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
* @ORM\JoinColumn(nullable=false)
2019-11-06 14:54:04 +01:00
* @Serializer\Type("App\Entity\choice")
*/
2019-11-06 14:54:04 +01:00
public $choice;
2019-11-12 11:26:19 +01:00
/**
* @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;
/**
2019-11-27 17:07:11 +01:00
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\StackOfVotes")
*/
private $stackOfVotes;
2019-10-25 14:59:20 +02:00
2019-11-27 10:57:06 +01:00
public function __construct() {
$this->setCreationDate( new \DateTime() );
}
2019-10-25 14:59:20 +02:00
public function getId(): ?int {
2019-11-06 14:54:04 +01:00
return $this->id;
}
2019-10-25 14:59:20 +02:00
public function getPoll(): ?Poll {
2019-11-06 14:54:04 +01:00
return $this->poll;
}
2019-10-25 14:59:20 +02:00
public function setPoll( ?Poll $poll ): self {
2019-11-06 14:54:04 +01:00
$this->poll = $poll;
2019-11-27 17:07:11 +01:00
if ( $poll ) {
$poll->addVote( $this );
}
2019-11-06 14:54:04 +01:00
return $this;
}
public function getChoice(): ?Choice {
return $this->choice;
}
public function setChoice( ?Choice $choice ): self {
$this->choice = $choice;
return $this;
}
2019-11-12 11:26:19 +01:00
public function getValue(): ?string {
return $this->value;
}
public function setValue( ?string $value ): self {
2019-11-12 11:26:19 +01:00
$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;
}
2019-10-25 14:59:20 +02:00
}