⚡ add choices and votes links in DB
This commit is contained in:
parent
7340b020ec
commit
9123faf3f1
|
@ -126,7 +126,7 @@ class DefaultController extends AbstractController {
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a poll ' . $precision,
|
'message' => 'you created a poll ' . $precision,
|
||||||
// 'data' => $jsonContent,
|
'data' => $newpoll,
|
||||||
|
|
||||||
],
|
],
|
||||||
203 );
|
203 );
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
|
||||||
|
*/
|
||||||
|
class Choice {
|
||||||
|
/**
|
||||||
|
* @ORM\Id()
|
||||||
|
* @ORM\GeneratedValue()
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
|
*/
|
||||||
|
private $dateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
|
||||||
|
*/
|
||||||
|
private $poll;
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="choice")
|
||||||
|
*/
|
||||||
|
private $votes;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->poll = new ArrayCollection();
|
||||||
|
$this->votes = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getId(): ?int {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): ?string {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName( string $name ): self {
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateTime(): ?\DateTimeInterface {
|
||||||
|
return $this->dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateTime( ?\DateTimeInterface $dateTime ): self {
|
||||||
|
$this->dateTime = $dateTime;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection|Poll[]
|
||||||
|
*/
|
||||||
|
public function getPoll(): Collection
|
||||||
|
{
|
||||||
|
return $this->poll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPoll(Poll $poll): self
|
||||||
|
{
|
||||||
|
if (!$this->poll->contains($poll)) {
|
||||||
|
$this->poll[] = $poll;
|
||||||
|
$poll->setChoices($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removePoll(Poll $poll): self
|
||||||
|
{
|
||||||
|
if ($this->poll->contains($poll)) {
|
||||||
|
$this->poll->removeElement($poll);
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($poll->getChoices() === $this) {
|
||||||
|
$poll->setChoices(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection|Choice[]
|
||||||
|
*/
|
||||||
|
public function getVotes(): Collection
|
||||||
|
{
|
||||||
|
return $this->votes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVote(Choice $vote): self
|
||||||
|
{
|
||||||
|
if (!$this->votes->contains($vote)) {
|
||||||
|
$this->votes[] = $vote;
|
||||||
|
$vote->setChoice($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeVote(Choice $vote): self
|
||||||
|
{
|
||||||
|
if ($this->votes->contains($vote)) {
|
||||||
|
$this->votes->removeElement($vote);
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($vote->getChoice() === $this) {
|
||||||
|
$vote->setChoice(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,14 +21,16 @@ class Owner {
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $email;
|
private $email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $pseudo;
|
public $pseudo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist"})
|
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist"})
|
||||||
|
|
|
@ -83,26 +83,31 @@ class Poll {
|
||||||
* self - one can only modify its own vote
|
* self - one can only modify its own vote
|
||||||
* nobody - no one can modify the votes (excepted admin), pray to have it right at first
|
* nobody - no one can modify the votes (excepted admin), pray to have it right at first
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
|
* @Serializer\Type("string")
|
||||||
*/
|
*/
|
||||||
public $modificationPolicy;
|
public $modificationPolicy;
|
||||||
/**
|
/**
|
||||||
* send a mail on a new comment
|
* send a mail on a new comment
|
||||||
* @ORM\Column(type="boolean", nullable=true)
|
* @ORM\Column(type="boolean", nullable=true)
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
*/
|
*/
|
||||||
private $mailOnComment;
|
private $mailOnComment;
|
||||||
/**
|
/**
|
||||||
* send a mail on a new vote
|
* send a mail on a new vote
|
||||||
* @ORM\Column(type="boolean", nullable=true)
|
* @ORM\Column(type="boolean", nullable=true)
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
*/
|
*/
|
||||||
private $mailOnVote;
|
private $mailOnVote;
|
||||||
/**
|
/**
|
||||||
* hide publicly results
|
* hide publicly results
|
||||||
* @ORM\Column(type="boolean", nullable=true)
|
* @ORM\Column(type="boolean", nullable=true)
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
*/
|
*/
|
||||||
private $hideResults;
|
private $hideResults;
|
||||||
/**
|
/**
|
||||||
* show publicly results even if there is a password to access the vote
|
* show publicly results even if there is a password to access the vote
|
||||||
* @ORM\Column(type="boolean", nullable=true)
|
* @ORM\Column(type="boolean", nullable=true)
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
*/
|
*/
|
||||||
private $showResultEvenIfPasswords;
|
private $showResultEvenIfPasswords;
|
||||||
|
|
||||||
|
@ -111,9 +116,15 @@ class Poll {
|
||||||
* @Serializer\Type("App\Entity\Vote")
|
* @Serializer\Type("App\Entity\Vote")
|
||||||
*/
|
*/
|
||||||
private $votes;
|
private $votes;
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
|
||||||
|
* @Serializer\Type("App\Entity\Choice")
|
||||||
|
*/
|
||||||
|
private $choices;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->votes = new ArrayCollection();
|
$this->votes = new ArrayCollection();
|
||||||
|
$this->choices = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int {
|
public function getId(): ?int {
|
||||||
|
@ -287,4 +298,32 @@ class Poll {
|
||||||
|
|
||||||
return $this;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,50 +39,55 @@ class Vote {
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=false)
|
||||||
*/
|
*/
|
||||||
private $poll;
|
private $poll;
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $choice;
|
||||||
|
|
||||||
public function getId(): ?int {
|
public function getId(): ?int {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAnswerTxt(): ?string {
|
public function getAnswerTxt(): ?string {
|
||||||
return $this->answerTxt;
|
return $this->answerTxt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnswerTxt( ?string $answerTxt ): self {
|
public function setAnswerTxt( ?string $answerTxt ): self {
|
||||||
$this->answerTxt = $answerTxt;
|
$this->answerTxt = $answerTxt;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAnswerDate(): ?\DateTimeInterface {
|
public function getAnswerDate(): ?\DateTimeInterface {
|
||||||
return $this->answerDate;
|
return $this->answerDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnswerDate( ?\DateTimeInterface $answerDate ): self {
|
public function setAnswerDate( ?\DateTimeInterface $answerDate ): self {
|
||||||
$this->answerDate = $answerDate;
|
$this->answerDate = $answerDate;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreationDate(): ?\DateTimeInterface {
|
public function getCreationDate(): ?\DateTimeInterface {
|
||||||
return $this->creationDate;
|
return $this->creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreationDate( \DateTimeInterface $creationDate ): self {
|
public function setCreationDate( \DateTimeInterface $creationDate ): self {
|
||||||
$this->creationDate = $creationDate;
|
$this->creationDate = $creationDate;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPoll(): ?Poll {
|
public function getPoll(): ?Poll {
|
||||||
return $this->poll;
|
return $this->poll;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPoll( ?Poll $poll ): self {
|
public function setPoll( ?Poll $poll ): self {
|
||||||
$this->poll = $poll;
|
$this->poll = $poll;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPseudo(): ?string
|
public function getPseudo(): ?string
|
||||||
{
|
{
|
||||||
|
@ -95,4 +100,16 @@ class Vote {
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getChoice(): ?Choice
|
||||||
|
{
|
||||||
|
return $this->choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setChoice(?Choice $choice): self
|
||||||
|
{
|
||||||
|
$this->choice = $choice;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Choice;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Choice|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method Choice|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method Choice[] findAll()
|
||||||
|
* @method Choice[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class ChoiceRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Choice::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Choice[] Returns an array of Choice objects
|
||||||
|
// */
|
||||||
|
/*
|
||||||
|
public function findByExampleField($value)
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('c')
|
||||||
|
->andWhere('c.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->orderBy('c.id', 'ASC')
|
||||||
|
->setMaxResults(10)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function findOneBySomeField($value): ?Choice
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('c')
|
||||||
|
->andWhere('c.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
Loading…
Reference in New Issue