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\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
|
|
|
*/
|
2019-11-06 10:07:07 +01: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
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $customUrl;
|
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
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $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
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $creationDate;
|
2019-10-25 14:59:20 +02:00
|
|
|
/**
|
|
|
|
* @ORM\Column(type="datetime")
|
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $expiracyDate;
|
2019-10-25 14:59:20 +02:00
|
|
|
/**
|
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
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $owner;
|
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)
|
2019-11-06 14:35:07 +01:00
|
|
|
* @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)
|
2019-11-06 14:35:07 +01:00
|
|
|
* @Serializer\Type("boolean")
|
2019-11-05 17:22:30 +01:00
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $mailOnComment;
|
2019-11-05 17:22:30 +01:00
|
|
|
/**
|
|
|
|
* send a mail on a new vote
|
|
|
|
* @ORM\Column(type="boolean", nullable=true)
|
2019-11-06 14:35:07 +01:00
|
|
|
* @Serializer\Type("boolean")
|
2019-11-05 17:22:30 +01:00
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $mailOnVote;
|
2019-11-05 17:22:30 +01:00
|
|
|
/**
|
|
|
|
* hide publicly results
|
|
|
|
* @ORM\Column(type="boolean", nullable=true)
|
2019-11-06 14:35:07 +01:00
|
|
|
* @Serializer\Type("boolean")
|
2019-11-05 17:22:30 +01:00
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $hideResults;
|
2019-11-05 17:22:30 +01:00
|
|
|
/**
|
|
|
|
* show publicly results even if there is a password to access the vote
|
|
|
|
* @ORM\Column(type="boolean", nullable=true)
|
2019-11-06 14:35:07 +01:00
|
|
|
* @Serializer\Type("boolean")
|
2019-11-05 17:22:30 +01:00
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $showResultEvenIfPasswords;
|
2019-11-05 17:22:30 +01:00
|
|
|
/**
|
2019-11-12 11:26:19 +01:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
|
2019-11-06 12:27:46 +01:00
|
|
|
* @Serializer\Type("App\Entity\Vote")
|
2019-11-05 17:22:30 +01:00
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $votes;
|
2019-11-06 14:35:07 +01:00
|
|
|
/**
|
2019-11-12 11:26:19 +01:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
|
|
|
|
* @Serializer\Type("App\Entity\StackOfVotes")
|
|
|
|
*/
|
|
|
|
public $stackOfVotes;
|
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
|
2019-11-06 14:35:07 +01:00
|
|
|
* @Serializer\Type("App\Entity\Choice")
|
|
|
|
*/
|
2019-11-06 14:54:04 +01:00
|
|
|
public $choices;
|
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll")
|
|
|
|
* @Serializer\Type("App\Entity\Comment")
|
|
|
|
*/
|
|
|
|
public $comments;
|
2019-11-12 11:26:19 +01:00
|
|
|
/**
|
|
|
|
* vote restricted by a password in md5 format
|
|
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
|
|
|
*/
|
|
|
|
private $password;
|
|
|
|
/**
|
|
|
|
* used to allow administration
|
|
|
|
* @ORM\Column(type="string", length=255)
|
|
|
|
* @Serializer\Type("string")
|
|
|
|
*/
|
|
|
|
private $adminKey;
|
|
|
|
/**
|
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes")
|
|
|
|
*/
|
|
|
|
private $stacksOfVotes;
|
2019-11-11 10:44:19 +01:00
|
|
|
|
2019-11-05 17:22:30 +01:00
|
|
|
public function __construct() {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->votes = new ArrayCollection();
|
|
|
|
$this->choices = new ArrayCollection();
|
|
|
|
$this->comments = new ArrayCollection();
|
|
|
|
$this->stackOfVotes = new ArrayCollection();
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
|
|
|
|
public function getId(): ?int {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->id;
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
|
|
|
|
public function getTitle(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->title;
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
|
|
|
|
public function setTitle( string $title ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->title = $title;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
public function getCreationDate(): ?DateTimeInterface {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->creationDate;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
public function setCreationDate( DateTimeInterface $creationDate ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->creationDate = $creationDate;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->expiracyDate = $expiracyDate;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
|
|
|
|
public function getOwner(): ?Owner {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->owner;
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
|
|
|
|
public function setOwner( ?Owner $owner ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->owner = $owner;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|Vote[]
|
|
|
|
*/
|
|
|
|
public function getVotes(): Collection {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->votes;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
public function getAdminKey(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->adminKey;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setAdminKey( string $adminKey ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->adminKey = $adminKey;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getDescription(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->description;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setDescription( string $description ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->description = $description;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getKind(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->kind;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setKind( string $kind ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->kind = $kind;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getCustomUrl(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->customUrl;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setCustomUrl( string $customUrl ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->customUrl = $customUrl;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getPassword(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->password;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setPassword( string $password ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getModificationPolicy(): ?string {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->modificationPolicy;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setModificationPolicy( string $modificationPolicy ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->modificationPolicy = $modificationPolicy;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getMailOnComment(): ?bool {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->mailOnComment;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setMailOnComment( bool $mailOnComment ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->mailOnComment = $mailOnComment;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getMailOnVote(): ?bool {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->mailOnVote;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setMailOnVote( bool $mailOnVote ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->mailOnVote = $mailOnVote;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getHideResults(): ?bool {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->hideResults;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setHideResults( bool $hideResults ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->hideResults = $hideResults;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function getShowResultEvenIfPasswords(): ?bool {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->showResultEvenIfPasswords;
|
|
|
|
}
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-06 14:35:07 +01:00
|
|
|
|
2019-11-06 14:54:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|Comment[]
|
|
|
|
*/
|
|
|
|
public function getComments(): Collection {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->comments;
|
|
|
|
}
|
2019-11-06 14:54:04 +01:00
|
|
|
|
|
|
|
public function addComment( Comment $comment ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
if ( ! $this->comments->contains( $comment ) ) {
|
|
|
|
$this->comments[] = $comment;
|
|
|
|
$comment->setPoll( $this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-06 14:54:04 +01:00
|
|
|
|
|
|
|
public function removeComment( Comment $comment ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
if ( $this->comments->contains( $comment ) ) {
|
|
|
|
$this->comments->removeElement( $comment );
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ( $comment->getPoll() === $this ) {
|
|
|
|
$comment->setPoll( null );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
public function getStacksOfVotes(): ?StackOfVotes {
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->stacksOfVotes;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
|
2019-11-12 17:26:56 +01:00
|
|
|
$this->stacksOfVotes = $stacksOfVotes;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|StackOfVotes[]
|
|
|
|
*/
|
|
|
|
public function getStackOfVotes(): Collection {
|
|
|
|
return $this->stackOfVotes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
|
|
|
|
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
|
|
|
|
$this->stackOfVotes[] = $stackOfVote;
|
|
|
|
$stackOfVote->setPoll( $this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
|
|
|
|
if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
|
|
|
|
$this->stackOfVotes->removeElement( $stackOfVote );
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ( $stackOfVote->getPoll() === $this ) {
|
|
|
|
$stackOfVote->setPoll( null );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExpiracyDate(): ?\DateTimeInterface {
|
|
|
|
return $this->expiracyDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-12 17:26:56 +01:00
|
|
|
* @return Collection|Choice[]
|
2019-11-12 11:26:19 +01:00
|
|
|
*/
|
2019-11-12 17:26:56 +01:00
|
|
|
public function getChoices(): Collection
|
2019-11-11 10:44:19 +01:00
|
|
|
{
|
2019-11-12 17:26:56 +01:00
|
|
|
return $this->choices;
|
2019-11-12 11:26:19 +01:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:26:56 +01:00
|
|
|
public function addChoice(Choice $choice): self
|
2019-11-12 11:26:19 +01:00
|
|
|
{
|
2019-11-12 17:26:56 +01:00
|
|
|
if (!$this->choices->contains($choice)) {
|
|
|
|
$this->choices[] = $choice;
|
|
|
|
$choice->setPoll($this);
|
2019-11-12 11:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
2019-11-11 10:44:19 +01:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:26:56 +01:00
|
|
|
public function removeChoice(Choice $choice): self
|
2019-11-11 10:44:19 +01:00
|
|
|
{
|
2019-11-12 17:26:56 +01:00
|
|
|
if ($this->choices->contains($choice)) {
|
|
|
|
$this->choices->removeElement($choice);
|
2019-11-12 11:26:19 +01:00
|
|
|
// set the owning side to null (unless already changed)
|
2019-11-12 17:26:56 +01:00
|
|
|
if ($choice->getPoll() === $this) {
|
|
|
|
$choice->setPoll(null);
|
2019-11-12 11:26:19 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-11 10:44:19 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-10-25 14:59:20 +02:00
|
|
|
}
|