1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00
date-poll-api/src/Entity/Vote.php

125 lines
2.8 KiB
PHP
Raw Normal View History

2019-10-25 14:59:20 +02:00
<?php
2020-02-04 12:38:07 +01:00
namespace App\Entity;
2019-10-25 14:59:20 +02:00
2020-02-04 12:38:07 +01:00
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
2019-10-25 14:59:20 +02:00
/**
2020-02-04 12:38:07 +01:00
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
* @Serializer\ExclusionPolicy("all")
2019-10-25 14:59:20 +02:00
*/
2020-02-04 12:38:07 +01:00
class Vote {
/**
* for a text kind of choice: could be "yes" "no" "maybe" and empty.
2020-02-04 12:38:07 +01:00
* for a date kind, the choice linked is equivalent to the value selected
* @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Type("string")
* @Serializer\Expose()
*/
public $value;
/**
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
* @Serializer\Type("datetime")
* @Serializer\Expose()
*/
public $creationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\choice")
* @Serializer\Expose()
*/
public $choice;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Serializer\Type("integer")
* @Serializer\Expose()
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $poll;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\StackOfVotes")
*/
private $stacksOfVotes;
public function display() {
return [
'id' => $this->getId(),
'value' => $this->getValue(),
'choice_id' => $this->getChoice()->getId(),
'text' => $this->getChoice()->getName(),
];
}
2019-11-27 10:57:06 +01:00
2020-02-04 12:38:07 +01:00
public function __construct() {
$this->setCreationDate( new \DateTime() );
}
2019-10-25 14:59:20 +02:00
2020-02-04 12:38:07 +01:00
public function getId(): ?int {
return $this->id;
}
2019-10-25 14:59:20 +02:00
2020-02-04 12:38:07 +01:00
public function getPoll(): ?Poll {
return $this->poll;
2019-11-27 17:07:11 +01:00
}
2019-11-06 14:54:04 +01:00
2020-02-04 12:38:07 +01:00
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
if ( $poll ) {
$poll->addVote( $this );
}
2019-11-06 14:54:04 +01:00
2020-02-04 12:38:07 +01:00
return $this;
}
2019-11-06 14:54:04 +01:00
2020-02-04 12:38:07 +01:00
public function getChoice(): ?Choice {
return $this->choice;
}
2019-11-06 14:54:04 +01:00
2020-02-04 12:38:07 +01:00
public function setChoice( ?Choice $choice ): self {
$this->choice = $choice;
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
return $this;
}
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
public function getValue(): ?string {
return $this->value;
}
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
public function setValue( ?string $value ): self {
$this->value = $value;
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
return $this;
}
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate;
}
2019-11-12 11:26:19 +01:00
2020-02-04 12:38:07 +01:00
public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
2020-02-04 12:38:07 +01:00
return $this;
}
public function getStacksOfVotes(): ?StackOfVotes {
return $this->stacksOfVotes;
}
2020-02-04 12:38:07 +01:00
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes;
2020-02-04 12:38:07 +01:00
return $this;
}
}