more stack fixtures

develop
Baptiste Lemoine 3 years ago
parent b3bdeb0d4a
commit 158a795446
  1. 4
      src/DataFixtures/AppPollFixtures.php
  2. 76
      src/DataFixtures/CommentFixtures.php
  3. 148
      src/DataFixtures/VotesStacksFixtures.php
  4. 234
      src/Entity/StackOfVotes.php

@ -54,7 +54,6 @@ class AppPollFixtures extends Fixture {
->addChoice( $choiceB );
$manager->persist( $poll );
$stack1 = new StackOfVotes();
$stack1
->setPoll( $poll )
@ -72,10 +71,7 @@ class AppPollFixtures extends Fixture {
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
->setChoice( $choiceB );
$stack1->setPseudo( 'chuck norris' );
$manager->persist( $stack1 );
// voter guy votes again with an other pseudo

@ -0,0 +1,76 @@
<?php
namespace App\DataFixtures;
use App\Entity\Comment;
use App\Entity\Owner;
use App\Entity\Poll;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class CommentFixtures extends Fixture {
public function load( ObjectManager $manager ) {
$emPoll = $manager->getRepository( Poll::class );
$commenterMan = new Owner();
$commenterMan->setEmail( 'tktest_commentateur_other@tktest.com' )
->setPseudo( 'Bill Murray' );
$commenterMan2 = new Owner();
$commenterMan2->setEmail( 'wulfila@tktest.com' )
->setPseudo( 'Wulfila' );
// comment on "citron ou orange"
$pollCitronOrange = $emPoll->find( 1 );
$comment = new Comment();
$comment->setOwner( $commenterMan )
->setText( 'quelle indécision wololo! finalement citron. heu non orange. AAAAh!' );
$pollCitronOrange->addComment( $comment );
$manager->persist( $comment );
$manager->persist( $pollCitronOrange );
$manager->persist( $commenterMan );
$manager->flush();
// comment on "démo sondage de texte avec deux commentaires"
$poll = $emPoll->find( 2 );
$comment = new Comment();
$comment->setOwner( $commenterMan2 )
->setText( 'il est écrit Squalala.' );
$pollCitronOrange->addComment( $comment );
$manager->persist( $comment );
$manager->persist( $poll );
$manager->persist( $commenterMan2 );
$manager->flush();
$comment = new Comment();
$comment->setOwner( $commenterMan )
->setText( "Zelda. Orange." );
$pollCitronOrange->addComment( $comment );
$manager->persist( $comment );
$manager->persist( $poll );
$manager->persist( $commenterMan );
$manager->flush();
// comment on "c'est pour aujourdhui ou pour demain"
$poll = $emPoll->find( 3 );
$comment = new Comment();
$comment->setOwner( $commenterMan )
->setText( "va pour demain" );
$pollCitronOrange->addComment( $comment );
$manager->persist( $comment );
$manager->persist( $poll );
$manager->persist( $commenterMan );
$manager->flush();
// comment on "dessin animé préféré"
$poll = $emPoll->find( 4 );
$comment = new Comment();
$comment->setOwner( $commenterMan2 )
->setText( "Ceci est un commentaire de fixture créé avec le CipherBliss poweur." );
$pollCitronOrange->addComment( $comment );
$manager->persist( $comment );
$manager->persist( $poll );
$manager->persist( $commenterMan2 );
$manager->flush();
}
}

@ -0,0 +1,148 @@
<?php
namespace App\DataFixtures;
use App\Entity\Owner;
use App\Entity\Poll;
use App\Entity\StackOfVotes;
use App\Entity\Vote;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class VotesStacksFixtures extends Fixture {
public function load( ObjectManager $manager ) {
$emPoll = $manager->getRepository( Poll::class );
$people1 = new Owner();
$people1->setEmail( 'tktest_nikolas_edison@tktest.com' )
->setPseudo( 'Nikolas Edison' );
$people2 = new Owner();
$people2->setEmail( 'wulfila@tktest.com' )
->setPseudo( 'Wulfila' );
$people3 = new Owner();
$people3->setEmail( 'billie_jean@tktest.com' )
->setPseudo( 'Billie Jean' );
// "citron ou orange"
$poll = $emPoll->find( 1 );
$stack1 = new StackOfVotes();
$stack1
->setPoll( $poll )
->setOwner( $people1 );
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 0 ] );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStacksOfVotes( $stack1 )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 1 ] );
$poll->addStackOfVote( $stack1 );
$manager->persist( $poll );
$manager->persist( $people1 );
$manager->persist( $stack1 );
$stack2 = new StackOfVotes();
$stack2
->setPoll( $poll )
->setOwner( $people2 );
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStacksOfVotes( $stack2 )
->setValue( "no" )
->setChoice( $poll->getChoices()[ 0 ] );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStacksOfVotes( $stack2 )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 1 ] );
$poll->addStackOfVote( $stack2 );
$manager->persist( $poll );
$manager->persist( $stack2 );
$manager->persist( $people2 );
// comment on "démo sondage de texte avec deux commentaires"
$poll = $emPoll->find( 2 );
// comment on "c'est pour aujourdhui ou pour demain"
$poll = $emPoll->find( 3 );
// comment on "dessin animé préféré"
$poll = $emPoll->find( 4 );
$stack1 = new StackOfVotes();
$stack1
->setPoll( $poll )
->setOwner( $people1 );
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStacksOfVotes( $stack1 )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 2 ] );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStacksOfVotes( $stack1 )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 4 ] );
$poll->addStackOfVote( $stack1 );
$manager->persist( $poll );
$manager->persist( $people1 );
$manager->persist( $stack1 );
$stack2 = new StackOfVotes();
$stack2
->setPoll( $poll )
->setOwner( $people2 );
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStacksOfVotes( $stack2 )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 3 ] );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStacksOfVotes( $stack2 )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 5 ] );
$poll->addStackOfVote( $stack2 );
$manager->persist( $poll );
$manager->persist( $people2 );
$manager->persist( $stack2 );
$stack3 = new StackOfVotes();
$stack3
->setPoll( $poll )
->setOwner( $people3 );
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStacksOfVotes( $stack3 )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 1 ] );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStacksOfVotes( $stack3 )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 3 ] );
$poll->addStackOfVote( $stack3 );
$manager->persist( $poll );
$manager->persist( $people3 );
$manager->persist( $stack3 );
$manager->flush();
}
}

@ -1,141 +1,149 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* contains the votes for one answer to a poll
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
* @ORM\HasLifecycleCallbacks()
*/
class StackOfVotes {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
* @Serializer\Expose()
*/
public $pseudo;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
* @Serializer\Expose()
*/
public $votes;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
private $poll;
/**
* contains the votes for one answer to a poll
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
class StackOfVotes {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
* @Serializer\Expose()
*/
public $pseudo;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
* @Serializer\Expose()
*/
public $votes;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
private $poll;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
private $owner;
public function display() {
$tab = [
'id' => $this->getId(),
'pseudo' => '',
'creation_date' => '',
'votes' => [],
private $owner;
public function display() {
$tab = [
'id' => $this->getId(),
'pseudo' => '',
'creation_date' => '',
'votes' => [],
];
// prefill votes with all choices ids
foreach ( $this->getPoll()->getChoices() as $choice ) {
$tab[ 'votes' ][ $choice->getId() ] = [
'choice_id' => $choice->getId(),
];
// prefill votes with all choices ids
foreach ( $this->getPoll()->getChoices() as $choice ) {
$tab[ 'votes' ][ $choice->getId() ] = [
'choice_id' => $choice->getId(),
];
}
foreach ( $this->getVotes() as $vote ) {
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = [
'id' => $this->getId(),
'vote_id' => $vote->getId(),
'value' => $vote->getValue(),
'choice_id' => $vote->getChoice()->getId(),
'text' => $vote->getChoice()->getName(),
];
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
$tab[ 'creation_date' ] = $vote->getCreationDate();
}
return $tab;
}
public function __construct() {
$this->votes = new ArrayCollection();
foreach ( $this->getVotes() as $vote ) {
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = [
'id' => $this->getId(),
'vote_id' => $vote->getId(),
'value' => $vote->getValue(),
'choice_id' => $vote->getChoice()->getId(),
'text' => $vote->getChoice()->getName(),
];
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
$tab[ 'creation_date' ] = $vote->getCreationDate();
}
public function getId(): ?int {
return $this->id;
}
return $tab;
}
/**
* @return Collection|poll[]
*/
public function getVotes(): Collection {
return $this->votes;
}
/**
* @ORM\PrePersist
*/
public function prePersist() {
$this->setPseudo( $this->getOwner()->getPseudo() );
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$vote->setPoll( $this->getPoll() );
public function __construct() {
$this->votes = new ArrayCollection();
}
$this->votes[] = $vote;
$vote->setStacksOfVotes( $this );
}
public function getId(): ?int {
return $this->id;
}
return $this;
}
/**
* @return Collection|poll[]
*/
public function getVotes(): Collection {
return $this->votes;
}
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->getStacksOfVotes() === $this ) {
$vote->setStacksOfVotes( null );
}
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$vote->setPoll( $this->getPoll() );
return $this;
$this->votes[] = $vote;
$vote->setStacksOfVotes( $this );
}
public function getPseudo(): ?string {
return $this->pseudo;
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->getStacksOfVotes() === $this ) {
$vote->setStacksOfVotes( null );
}
}
public function setPseudo( ?string $pseudo ): self {
$this->pseudo = $pseudo;
return $this;
}
return $this;
}
public function getPseudo(): ?string {
return $this->pseudo;
}
public function getOwner(): ?Owner {
return $this->owner;
}
public function setPseudo( ?string $pseudo ): self {
$this->pseudo = $pseudo;
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
return $this;
}
public function getOwner(): ?Owner {
return $this->owner;
}
public function getPoll(): ?Poll {
return $this->poll;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
return $this;
}
return $this;
}
public function getPoll(): ?Poll {
return $this->poll;
}
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
return $this;
}
}

Loading…
Cancel
Save