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

330 lines
6.9 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;
2019-11-05 17:31:07 +01:00
use JMS\Serializer\Annotation as Serializer;
2019-10-25 14:59:20 +02:00
/**
* @ORM\Entity(repositoryClass="App\Repository\PollRepository")
*/
class Poll {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
2019-11-06 11:23:43 +01:00
* @Serializer\Expose()
2019-11-06 12:27:46 +01:00
* @Serializer\Type("integer")
2019-10-25 14:59:20 +02:00
*/
2019-11-06 11:23:43 +01:00
public $id;
2019-10-25 14:59:20 +02:00
/**
* @ORM\Column(type="string", length=255)
2019-11-06 11:23:43 +01:00
* @Serializer\Expose()
2019-11-06 12:27:46 +01:00
* @Serializer\Type("string")
2019-10-25 14:59:20 +02:00
*/
public $title;
2019-11-05 17:22:30 +01:00
/**
* @ORM\Column(type="string", length=255, nullable=true)
2019-11-06 11:23:43 +01:00
* @Serializer\Expose()
2019-11-06 12:27:46 +01:00
* @Serializer\Type("string")
2019-11-05 17:22:30 +01:00
*/
private $customUrl;
/**
2019-11-05 17:31:07 +01:00
* vote restricted by a password in md5 format
2019-11-05 17:22:30 +01:00
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $password;
2019-11-05 17:31:07 +01:00
2019-11-05 17:22:30 +01:00
/**
* @ORM\Column(type="string", length=1000)
2019-11-06 11:23:43 +01:00
* @Serializer\Expose()
2019-11-06 12:27:46 +01:00
* @Serializer\Type("string")
2019-11-05 17:22:30 +01:00
*/
private $description;
2019-10-25 14:59:20 +02:00
/**
* @ORM\Column(type="datetime")
2019-11-06 11:23:43 +01:00
* @Serializer\Expose()
2019-10-25 14:59:20 +02:00
*/
private $creationDate;
/**
* @ORM\Column(type="datetime")
*/
private $expiracyDate;
/**
2019-11-06 12:27:46 +01:00
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="polls",cascade={"persist"})
2019-10-25 14:59:20 +02:00
* @ORM\JoinColumn(nullable=false)
2019-11-06 12:27:46 +01:00
* @Serializer\Type("App\Entity\Owner")
2019-10-25 14:59:20 +02:00
*/
private $owner;
/**
* used to allow administration
* @ORM\Column(type="string", length=255)
2019-11-06 12:27:46 +01:00
* @Serializer\Type("string")
2019-10-25 14:59:20 +02:00
*/
private $adminKey;
2019-11-05 17:22:30 +01:00
/**
* kind of poll, text or date
* @ORM\Column(type="string", length=255)
2019-11-06 12:27:46 +01:00
* @Serializer\Type("string")
* @Serializer\Expose()
2019-11-05 17:22:30 +01:00
*/
2019-11-06 12:27:46 +01:00
public $kind;
2019-11-05 17:22:30 +01:00
/**
* kind of way the people can modify the poll
* everybody - can modify votes
* self - one can only modify its own vote
* nobody - no one can modify the votes (excepted admin), pray to have it right at first
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
2019-11-05 17:22:30 +01:00
*/
2019-11-06 12:27:46 +01:00
public $modificationPolicy;
2019-11-05 17:22:30 +01:00
/**
* send a mail on a new comment
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
2019-11-05 17:22:30 +01:00
*/
private $mailOnComment;
/**
* send a mail on a new vote
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
2019-11-05 17:22:30 +01:00
*/
private $mailOnVote;
/**
* hide publicly results
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
2019-11-05 17:22:30 +01:00
*/
private $hideResults;
/**
* show publicly results even if there is a password to access the vote
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
2019-11-05 17:22:30 +01:00
*/
private $showResultEvenIfPasswords;
2019-10-25 14:59:20 +02:00
2019-11-05 17:22:30 +01:00
/**
2019-11-06 12:27:46 +01:00
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
* @Serializer\Type("App\Entity\Vote")
2019-11-05 17:22:30 +01:00
*/
private $votes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
* @Serializer\Type("App\Entity\Choice")
*/
private $choices;
2019-10-25 14:59:20 +02:00
2019-11-05 17:22:30 +01:00
public function __construct() {
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
2019-11-05 17:22:30 +01:00
}
2019-10-25 14:59:20 +02:00
public function getId(): ?int {
2019-11-05 17:22:30 +01:00
return $this->id;
}
2019-10-25 14:59:20 +02:00
public function getTitle(): ?string {
2019-11-05 17:22:30 +01:00
return $this->title;
}
2019-10-25 14:59:20 +02:00
public function setTitle( string $title ): self {
2019-11-05 17:22:30 +01:00
$this->title = $title;
return $this;
}
2019-10-25 14:59:20 +02:00
public function getCreationDate(): ?\DateTimeInterface {
2019-11-05 17:22:30 +01:00
return $this->creationDate;
}
2019-10-25 14:59:20 +02:00
public function setCreationDate( \DateTimeInterface $creationDate ): self {
2019-11-05 17:22:30 +01:00
$this->creationDate = $creationDate;
return $this;
}
2019-10-25 14:59:20 +02:00
public function getExpiracyDate(): ?\DateTimeInterface {
2019-11-05 17:22:30 +01:00
return $this->expiracyDate;
}
2019-10-25 14:59:20 +02:00
public function setExpiracyDate( \DateTimeInterface $expiracyDate ): self {
2019-11-05 17:22:30 +01:00
$this->expiracyDate = $expiracyDate;
return $this;
}
2019-10-25 14:59:20 +02:00
public function getOwner(): ?Owner {
2019-11-05 17:22:30 +01:00
return $this->owner;
}
2019-10-25 14:59:20 +02:00
public function setOwner( ?Owner $owner ): self {
2019-11-05 17:22:30 +01:00
$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;
}
public function getAdminKey(): ?string {
return $this->adminKey;
}
public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey;
return $this;
}
public function getDescription(): ?string {
return $this->description;
}
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
public function getKind(): ?string {
return $this->kind;
}
public function setKind( string $kind ): self {
$this->kind = $kind;
return $this;
}
public function getCustomUrl(): ?string {
return $this->customUrl;
}
public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl;
return $this;
}
public function getPassword(): ?string {
return $this->password;
}
public function setPassword( string $password ): self {
$this->password = $password;
return $this;
}
public function getModificationPolicy(): ?string {
return $this->modificationPolicy;
}
public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy;
return $this;
}
public function getMailOnComment(): ?bool {
return $this->mailOnComment;
}
public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment;
return $this;
}
public function getMailOnVote(): ?bool {
return $this->mailOnVote;
}
public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote;
return $this;
}
public function getHideResults(): ?bool {
return $this->hideResults;
}
public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults;
return $this;
}
public function getShowResultEvenIfPasswords(): ?bool {
return $this->showResultEvenIfPasswords;
}
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection {
return $this->choices;
}
public function addChoice( Choice $choice ): self {
if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice;
$choice->setPoll( $this );
}
return $this;
}
public function removeChoice( Choice $choice ): self {
if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice );
// set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) {
$choice->setPoll( null );
}
}
return $this;
}
2019-10-25 14:59:20 +02:00
}