2019-11-11 10:44:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-11-27 17:07:11 +01:00
|
|
|
use JMS\Serializer\Annotation as Serializer;
|
2019-11-11 10:44:19 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-12 11:26:19 +01:00
|
|
|
* contains the votes for one answer to a poll
|
2019-11-11 10:44:19 +01:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
|
|
|
|
*/
|
2019-11-12 11:26:19 +01:00
|
|
|
class StackOfVotes {
|
|
|
|
/**
|
|
|
|
* @ORM\Id()
|
|
|
|
* @ORM\GeneratedValue()
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
2019-11-27 17:07:11 +01:00
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=255)
|
|
|
|
* @Serializer\Type("string")
|
|
|
|
* @Serializer\Expose()
|
|
|
|
*/
|
|
|
|
public $pseudo;
|
2019-11-12 11:26:19 +01:00
|
|
|
/**
|
2019-11-27 11:26:21 +01:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
|
2019-11-12 11:26:19 +01:00
|
|
|
*/
|
|
|
|
private $votes;
|
2019-11-27 11:26:21 +01:00
|
|
|
/**
|
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
|
|
|
|
*/
|
|
|
|
private $poll;
|
2019-11-12 11:26:19 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-27 17:07:11 +01:00
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
|
2019-11-12 11:26:19 +01:00
|
|
|
*/
|
|
|
|
private $owner;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->votes = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): ?int {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|poll[]
|
|
|
|
*/
|
|
|
|
public function getVotes(): Collection {
|
|
|
|
return $this->votes;
|
|
|
|
}
|
|
|
|
|
2019-11-27 11:26:21 +01:00
|
|
|
public function addVote( Vote $vote ): self {
|
2019-11-12 11:26:19 +01:00
|
|
|
if ( ! $this->votes->contains( $vote ) ) {
|
2019-11-27 17:07:11 +01:00
|
|
|
$vote->setPoll( $this->getPoll() );
|
|
|
|
|
2019-11-12 11:26:19 +01:00
|
|
|
$this->votes[] = $vote;
|
2019-11-27 11:26:21 +01:00
|
|
|
$vote->setStackOfVotes( $this );
|
2019-11-12 11:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-11-27 11:26:21 +01:00
|
|
|
public function removeVote( Vote $vote ): self {
|
2019-11-12 11:26:19 +01:00
|
|
|
if ( $this->votes->contains( $vote ) ) {
|
|
|
|
$this->votes->removeElement( $vote );
|
|
|
|
// set the owning side to null (unless already changed)
|
2019-11-27 11:26:21 +01:00
|
|
|
if ( $vote->getStackOfVotes() === $this ) {
|
|
|
|
$vote->setStackOfVotes( null );
|
2019-11-12 11:26:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPseudo(): ?string {
|
|
|
|
return $this->pseudo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPseudo( ?string $pseudo ): self {
|
|
|
|
$this->pseudo = $pseudo;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOwner(): ?Owner {
|
|
|
|
return $this->owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOwner( ?Owner $owner ): self {
|
|
|
|
$this->owner = $owner;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-27 11:26:21 +01:00
|
|
|
|
|
|
|
public function getPoll(): ?Poll {
|
|
|
|
return $this->poll;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPoll( ?Poll $poll ): self {
|
|
|
|
$this->poll = $poll;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-11-11 10:44:19 +01:00
|
|
|
}
|