mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
model of stack of votes
This commit is contained in:
parent
d6fe2a6285
commit
b7d1a51e2a
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\Vote;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
@ -16,9 +18,9 @@ class AppPollFixtures extends Fixture {
|
||||
|
||||
// $product = new Product();
|
||||
$poll = new Poll();
|
||||
$poll->setTitle( 'démo sondage de texte' );
|
||||
$poll->setTitle( 'citron ou orange' );
|
||||
$poll->setKind( 'text' );
|
||||
$poll->setDescription( 'description du sondage' );
|
||||
$poll->setDescription( 'votre sorbert préféré' );
|
||||
$poll->setAdminKey( 'dskjfsfdljkdsjlkdsfkjdsjdlkfs' );
|
||||
$poll->setModificationPolicy( 'nobody' );
|
||||
$poll->setCreationDate( new \DateTime() );
|
||||
@ -27,6 +29,24 @@ class AppPollFixtures extends Fixture {
|
||||
$poll->setOwner( $owner );
|
||||
$owner->addPoll( $poll );
|
||||
|
||||
$choiceA = new Choice();
|
||||
$choiceA->setName( 'citron' );
|
||||
$choiceB = new Choice();
|
||||
$choiceA->setName( 'orange' );
|
||||
|
||||
$poll
|
||||
->addChoice( $choiceA )
|
||||
->addChoice( $choiceB );
|
||||
|
||||
$voteA = new Vote();
|
||||
$voteA->setPseudo( 'chuck norris' )
|
||||
->setCreationDate( new DateTime() )
|
||||
->setChoice( $choiceA );
|
||||
$voteA = new Vote();
|
||||
$voteA->setPseudo( 'Néo' )
|
||||
->setCreationDate( new DateTime() )
|
||||
->setChoice( $choiceB );
|
||||
|
||||
$manager->persist( $poll );
|
||||
|
||||
|
||||
|
@ -43,9 +43,15 @@ class Owner {
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="owner")
|
||||
*/
|
||||
private $stackOfVotes;
|
||||
|
||||
public function __construct() {
|
||||
$this->polls = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->stackOfVotes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
@ -125,6 +131,37 @@ class Owner {
|
||||
}
|
||||
}
|
||||
|
||||
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->setOwner($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->getOwner() === $this) {
|
||||
$stackOfVote->setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,11 @@ class Poll {
|
||||
*/
|
||||
public $comments;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes")
|
||||
*/
|
||||
private $stacksOfVotes;
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
@ -359,6 +364,18 @@ class Poll {
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStacksOfVotes(): ?StackOfVotes
|
||||
{
|
||||
return $this->stacksOfVotes;
|
||||
}
|
||||
|
||||
public function setStacksOfVotes(?StackOfVotes $stacksOfVotes): self
|
||||
{
|
||||
$this->stacksOfVotes = $stacksOfVotes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
117
src/Entity/StackOfVotes.php
Normal file
117
src/Entity/StackOfVotes.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?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\StackOfVotesRepository")
|
||||
*/
|
||||
class StackOfVotes
|
||||
{
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\poll", mappedBy="stacksOfVotes")
|
||||
*/
|
||||
private $votes;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $pseudo;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $modifierToken;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes")
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public function addVote(poll $vote): self
|
||||
{
|
||||
if (!$this->votes->contains($vote)) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setStacksOfVotes($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote(poll $vote): self
|
||||
{
|
||||
if ($this->votes->contains($vote)) {
|
||||
$this->votes->removeElement($vote);
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($vote->getStacksOfVotes() === $this) {
|
||||
$vote->setStacksOfVotes(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string
|
||||
{
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo(?string $pseudo): self
|
||||
{
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModifierToken(): ?string
|
||||
{
|
||||
return $this->modifierToken;
|
||||
}
|
||||
|
||||
public function setModifierToken(string $modifierToken): self
|
||||
{
|
||||
$this->modifierToken = $modifierToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner(?Owner $owner): self
|
||||
{
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
50
src/Repository/StackOfVotesRepository.php
Normal file
50
src/Repository/StackOfVotesRepository.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\StackOfVotes;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method StackOfVotes|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method StackOfVotes|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method StackOfVotes[] findAll()
|
||||
* @method StackOfVotes[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class StackOfVotesRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, StackOfVotes::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return StackOfVotes[] Returns an array of StackOfVotes objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('s.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?StackOfVotes
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user