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

131 lines
2.7 KiB
PHP
Raw Normal View History

2019-10-25 14:59:20 +02:00
<?php
2021-04-27 10:21:21 +02:00
namespace App\Entity;
2019-10-25 14:59:20 +02:00
2021-04-27 12:51:10 +02:00
use App\Traits\TimeStampableTrait;
2021-04-27 10:22:16 +02:00
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
2019-10-25 14:59:20 +02:00
2021-04-27 10:21:21 +02:00
/**
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
* @Serializer\ExclusionPolicy("all")
*/
class Vote {
2021-04-27 12:51:10 +02:00
use TimeStampableTrait;
2019-10-25 14:59:20 +02:00
/**
2021-04-27 10:21:21 +02:00
* for a text kind of choice: could be "yes" "no" "maybe" and empty.
* 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()
2019-10-25 14:59:20 +02:00
*/
2021-04-27 10:21:21 +02:00
public $value;
2021-04-27 12:51:10 +02:00
2021-04-27 10:21:21 +02:00
/**
* @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;
2021-04-27 10:22:16 +02:00
public function __construct() {
2021-04-27 12:51:10 +02:00
$this->setCreatedAt( new DateTime());
2021-04-27 10:22:16 +02:00
}
2021-04-27 10:21:21 +02:00
public function display() {
$value = $this->getValue();
if ( ! $value ) {
return null;
} else {
2020-02-04 12:38:07 +01:00
return [
2021-04-27 10:21:21 +02:00
'id' => $this->getId(),
'value' => $this->getValue(),
'choice_id' => $this->getChoice()->getId(),
'text' => $this->getChoice()->getName(),
2020-02-04 12:38:07 +01:00
];
}
2021-04-27 10:21:21 +02:00
}
2019-11-27 10:57:06 +01:00
2021-04-27 10:22:16 +02:00
public function getValue(): ?string {
return $this->value;
2021-04-27 10:21:21 +02:00
}
2019-10-25 14:59:20 +02:00
2021-04-27 10:22:16 +02:00
public function setValue( ?string $value ): self {
$this->value = $value;
2019-11-06 14:54:04 +01:00
2021-04-27 10:22:16 +02:00
return $this;
2021-04-27 10:21:21 +02:00
}
2019-11-06 14:54:04 +01:00
2021-04-27 10:22:16 +02:00
public function getId(): ?int {
return $this->id;
2021-04-27 10:21:21 +02:00
}
2019-11-06 14:54:04 +01:00
2021-04-27 10:21:21 +02:00
public function getChoice(): ?Choice {
return $this->choice;
}
2019-11-12 11:26:19 +01:00
2021-04-27 10:21:21 +02:00
public function setChoice( ?Choice $choice ): self {
$this->choice = $choice;
2019-11-12 11:26:19 +01:00
2021-04-27 10:21:21 +02:00
return $this;
}
2019-11-12 11:26:19 +01:00
2021-04-27 10:22:16 +02:00
public function getPoll(): ?Poll {
return $this->poll;
2021-04-27 10:21:21 +02:00
}
2019-11-12 11:26:19 +01:00
2021-04-27 10:22:16 +02:00
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
if ( $poll ) {
$poll->addVote( $this );
}
2019-11-12 11:26:19 +01:00
2021-04-27 10:21:21 +02:00
return $this;
}
2019-11-12 11:26:19 +01:00
2021-04-27 10:21:21 +02:00
public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate;
}
2021-04-27 10:21:21 +02:00
public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
2020-02-04 12:38:07 +01:00
2021-04-27 10:21:21 +02:00
return $this;
}
public function getStacksOfVotes(): ?StackOfVotes {
return $this->stacksOfVotes;
}
2021-04-27 10:21:21 +02:00
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes;
2021-04-27 10:21:21 +02:00
return $this;
}
2021-04-27 10:21:21 +02:00
}