batch of answers in fixtures
This commit is contained in:
parent
c0e7173326
commit
eba4a14ce8
|
@ -7,6 +7,7 @@ use App\Entity\Owner;
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
use App\Entity\StackOfVotes;
|
use App\Entity\StackOfVotes;
|
||||||
use App\Entity\Vote;
|
use App\Entity\Vote;
|
||||||
|
use DateTime;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
@ -22,15 +23,14 @@ class AppPollFixtures extends Fixture {
|
||||||
->setPseudo( 'voting_people_TEST' )
|
->setPseudo( 'voting_people_TEST' )
|
||||||
->setModifierToken( uniqid() );
|
->setModifierToken( uniqid() );
|
||||||
|
|
||||||
// $product = new Product();
|
|
||||||
$poll = new Poll();
|
$poll = new Poll();
|
||||||
$poll->setTitle( 'citron ou orange' );
|
$poll->setTitle( 'citron ou orange' );
|
||||||
$poll->setKind( 'text' );
|
$poll->setKind( 'text' );
|
||||||
$poll->setDescription( 'votre sorbert préféré' );
|
$poll->setDescription( 'votre sorbert préféré' );
|
||||||
$poll->setAdminKey( uniqid() );
|
$poll->setAdminKey( uniqid() );
|
||||||
$poll->setModificationPolicy( 'nobody' );
|
$poll->setModificationPolicy( 'nobody' );
|
||||||
$poll->setCreationDate( new \DateTime() );
|
|
||||||
$poll->setExpiracyDate( new \DateTime() );
|
$poll->setExpiracyDate( new DateTime() );
|
||||||
$poll->setMailOnVote( true );
|
$poll->setMailOnVote( true );
|
||||||
$poll->setOwner( $owner );
|
$poll->setOwner( $owner );
|
||||||
$owner->addPoll( $poll );
|
$owner->addPoll( $poll );
|
||||||
|
@ -46,11 +46,9 @@ class AppPollFixtures extends Fixture {
|
||||||
|
|
||||||
$voteA = new Vote();
|
$voteA = new Vote();
|
||||||
$voteA->setPseudo( 'chuck norris' )
|
$voteA->setPseudo( 'chuck norris' )
|
||||||
->setCreationDate( new DateTime() )
|
|
||||||
->setChoice( $choiceA );
|
->setChoice( $choiceA );
|
||||||
$voteA = new Vote();
|
$voteA = new Vote();
|
||||||
$voteA->setPseudo( 'Néo' )
|
$voteA->setPseudo( 'Néo' )
|
||||||
->setCreationDate( new DateTime() )
|
|
||||||
->setChoice( $choiceB );
|
->setChoice( $choiceB );
|
||||||
|
|
||||||
$manager->persist( $poll );
|
$manager->persist( $poll );
|
||||||
|
@ -63,13 +61,13 @@ class AppPollFixtures extends Fixture {
|
||||||
$poll->setAdminKey( uniqid() );
|
$poll->setAdminKey( uniqid() );
|
||||||
$poll->setModificationPolicy( 'self' );
|
$poll->setModificationPolicy( 'self' );
|
||||||
$poll->setMailOnComment( true );
|
$poll->setMailOnComment( true );
|
||||||
$poll->setCreationDate( new \DateTime() );
|
$poll->setExpiracyDate( new DateTime() );
|
||||||
$poll->setExpiracyDate( new \DateTime() );
|
|
||||||
$poll->setOwner( $owner );
|
$poll->setOwner( $owner );
|
||||||
$owner->addPoll( $poll );
|
$owner->addPoll( $poll );
|
||||||
|
|
||||||
$manager->persist( $poll );
|
$manager->persist( $poll );
|
||||||
|
|
||||||
|
|
||||||
// voting test with 2 people
|
// voting test with 2 people
|
||||||
$stack1 = new StackOfVotes();
|
$stack1 = new StackOfVotes();
|
||||||
$stack1->setOwner( $voter )
|
$stack1->setOwner( $voter )
|
||||||
|
@ -89,8 +87,8 @@ class AppPollFixtures extends Fixture {
|
||||||
$poll->setDescription( 'description du sondage a accès restreint. le mot de passe est mot_de_passe_super' );
|
$poll->setDescription( 'description du sondage a accès restreint. le mot de passe est mot_de_passe_super' );
|
||||||
$poll->setAdminKey( uniqid() );
|
$poll->setAdminKey( uniqid() );
|
||||||
$poll->setCustomUrl( 'boudoum_podom_podom' );
|
$poll->setCustomUrl( 'boudoum_podom_podom' );
|
||||||
$poll->setCreationDate( new \DateTime() );
|
|
||||||
$poll->setExpiracyDate( new \DateTime() );
|
$poll->setExpiracyDate( new DateTime() );
|
||||||
$poll->setMailOnComment( true );
|
$poll->setMailOnComment( true );
|
||||||
$poll->setMailOnVote( true );
|
$poll->setMailOnVote( true );
|
||||||
$poll->setOwner( $owner );
|
$poll->setOwner( $owner );
|
||||||
|
@ -100,6 +98,24 @@ class AppPollFixtures extends Fixture {
|
||||||
$manager->persist( $owner );
|
$manager->persist( $owner );
|
||||||
$manager->persist( $voter );
|
$manager->persist( $voter );
|
||||||
|
|
||||||
|
|
||||||
|
// poll with cartoon choices
|
||||||
|
$poll = new Poll();
|
||||||
|
$poll->setTitle( 'dessin animé préféré' )
|
||||||
|
->setDescription( 'choisissez votre animé préféré' )
|
||||||
|
->addTextChoiceArray( [
|
||||||
|
"Vic le viking",
|
||||||
|
"Boumbo petite automobile",
|
||||||
|
"Les mystérieuses cités d'or",
|
||||||
|
"Les mondes engloutis",
|
||||||
|
"Foot 2 rue",
|
||||||
|
"Le chat, la vache, et l'océan",
|
||||||
|
"Digimon",
|
||||||
|
],
|
||||||
|
'fixture land' );
|
||||||
|
|
||||||
|
$manager->persist( $poll );
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ class Choice {
|
||||||
$this->poll = new ArrayCollection();
|
$this->poll = new ArrayCollection();
|
||||||
$this->stackOfVotes = new ArrayCollection();
|
$this->stackOfVotes = new ArrayCollection();
|
||||||
$this->vote = new ArrayCollection();
|
$this->vote = new ArrayCollection();
|
||||||
|
$this->setDateTime( new \DateTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,8 +137,7 @@ class Choice {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addStackOfVote(StackOfVotes $stackOfVote): self
|
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||||
{
|
|
||||||
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
|
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
|
||||||
$this->stackOfVotes[] = $stackOfVote;
|
$this->stackOfVotes[] = $stackOfVote;
|
||||||
$stackOfVote->setChoice( $this );
|
$stackOfVote->setChoice( $this );
|
||||||
|
@ -146,8 +146,7 @@ class Choice {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeStackOfVote(StackOfVotes $stackOfVote): self
|
public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||||
{
|
|
||||||
if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
|
if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
|
||||||
$this->stackOfVotes->removeElement( $stackOfVote );
|
$this->stackOfVotes->removeElement( $stackOfVote );
|
||||||
// set the owning side to null (unless already changed)
|
// set the owning side to null (unless already changed)
|
||||||
|
@ -162,8 +161,7 @@ class Choice {
|
||||||
/**
|
/**
|
||||||
* @return Collection|Vote[]
|
* @return Collection|Vote[]
|
||||||
*/
|
*/
|
||||||
public function getVote(): Collection
|
public function getVote(): Collection {
|
||||||
{
|
|
||||||
return $this->vote;
|
return $this->vote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,14 @@ class Poll {
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $kind;
|
public $kind;
|
||||||
|
/**
|
||||||
|
* array of possible answer to each choice, by default: "yes" or nothing only.
|
||||||
|
* could be also "yes", "maybe", "no". extensible to anything
|
||||||
|
* @ORM\Column(type="array")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
|
*/
|
||||||
|
public $allowedAnswers;
|
||||||
/**
|
/**
|
||||||
* kind of way the people can modify the poll
|
* kind of way the people can modify the poll
|
||||||
* everybody - can modify votes
|
* everybody - can modify votes
|
||||||
|
@ -135,6 +143,8 @@ class Poll {
|
||||||
$this->choices = new ArrayCollection();
|
$this->choices = new ArrayCollection();
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
$this->stackOfVotes = new ArrayCollection();
|
$this->stackOfVotes = new ArrayCollection();
|
||||||
|
$this->setCreationDate( new \DateTime() );
|
||||||
|
$this->setAllowedAnswers( [ 'yes' ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int {
|
public function getId(): ?int {
|
||||||
|
@ -380,13 +390,22 @@ class Poll {
|
||||||
/**
|
/**
|
||||||
* @return Collection|Choice[]
|
* @return Collection|Choice[]
|
||||||
*/
|
*/
|
||||||
public function getChoices(): Collection
|
public function getChoices(): Collection {
|
||||||
{
|
|
||||||
return $this->choices;
|
return $this->choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addChoice(Choice $choice): self
|
public function addTextChoiceArray( Array $choiceTextArray, $pseudo = "some body" ): self {
|
||||||
{
|
foreach ( $choiceTextArray as $text ) {
|
||||||
|
$newChoice = new Choice();
|
||||||
|
$newChoice->setName( $text )
|
||||||
|
->setPseudo( $pseudo );
|
||||||
|
$this->addChoice( $newChoice );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addChoice( Choice $choice ): self {
|
||||||
if ( ! $this->choices->contains( $choice ) ) {
|
if ( ! $this->choices->contains( $choice ) ) {
|
||||||
$this->choices[] = $choice;
|
$this->choices[] = $choice;
|
||||||
$choice->setPoll( $this );
|
$choice->setPoll( $this );
|
||||||
|
@ -395,8 +414,7 @@ class Poll {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeChoice(Choice $choice): self
|
public function removeChoice( Choice $choice ): self {
|
||||||
{
|
|
||||||
if ( $this->choices->contains( $choice ) ) {
|
if ( $this->choices->contains( $choice ) ) {
|
||||||
$this->choices->removeElement( $choice );
|
$this->choices->removeElement( $choice );
|
||||||
// set the owning side to null (unless already changed)
|
// set the owning side to null (unless already changed)
|
||||||
|
@ -407,4 +425,14 @@ class Poll {
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAllowedAnswers(): ?array {
|
||||||
|
return $this->allowedAnswers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedAnswers( array $allowedAnswers ): self {
|
||||||
|
$this->allowedAnswers = $allowedAnswers;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,10 @@ class Vote {
|
||||||
*/
|
*/
|
||||||
private $poll;
|
private $poll;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->setCreationDate( new \DateTime() );
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int {
|
public function getId(): ?int {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue