1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00
date-poll-api/src/DataFixtures/AppPollFixtures.php

235 lines
5.8 KiB
PHP
Raw Normal View History

2019-11-05 16:31:27 +01:00
<?php
namespace App\DataFixtures;
2019-11-11 10:44:19 +01:00
use App\Entity\Choice;
2019-11-27 16:14:49 +01:00
use App\Entity\Comment;
2019-11-05 17:22:30 +01:00
use App\Entity\Owner;
2019-11-05 16:31:27 +01:00
use App\Entity\Poll;
2019-11-27 17:07:11 +01:00
use App\Entity\StackOfVotes;
2019-11-11 10:44:19 +01:00
use App\Entity\Vote;
2019-11-27 10:57:06 +01:00
use DateTime;
2019-11-05 16:31:27 +01:00
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class AppPollFixtures extends Fixture {
public function load( ObjectManager $manager ) {
2019-11-05 17:22:30 +01:00
2019-11-28 11:51:25 +01:00
/**
* create a few demo people
*/
$owner = new Owner(); // someone who creates the polls
2019-11-05 17:22:30 +01:00
$owner->setEmail( 'tktest@tktest.com' )
2019-11-27 16:14:49 +01:00
->setPseudo( 'tk_TEST' );
$commenterMan = new Owner();
$commenterMan->setEmail( 'tktest_commentateur@tktest.com' )
->setPseudo( 'tk_TEST_commentateur' );
2019-11-12 11:55:11 +01:00
$voter = new Owner();
$voter->setEmail( 'testing_vote_people@tktest.com' )
->setPseudo( 'voting_people_TEST' )
->setModifierToken( uniqid() );
2019-11-28 11:51:25 +01:00
$manager->persist( $owner );
$manager->persist( $commenterMan );
$manager->persist( $voter );
$manager->flush();
2019-11-05 17:22:30 +01:00
2019-11-05 16:31:27 +01:00
$poll = new Poll();
$poll->setTitle( 'citron ou orange' )
->setDescription( 'votre sorbert préféré' )
->setAdminKey( uniqid() )
->setModificationPolicy( 'nobody' );
2019-11-05 17:22:30 +01:00
$poll->setMailOnVote( true );
$poll->setOwner( $owner );
$owner->addPoll( $poll );
2019-11-11 10:44:19 +01:00
$choiceA = new Choice();
$choiceA->setName( 'citron' );
$choiceB = new Choice();
2020-01-30 11:49:36 +01:00
$choiceB->setName( 'orange' );
2019-11-11 10:44:19 +01:00
$poll
->addChoice( $choiceA )
->addChoice( $choiceB );
2019-11-27 17:07:11 +01:00
$manager->persist( $poll );
2019-11-28 11:51:25 +01:00
2019-11-27 17:07:11 +01:00
$stack1 = new StackOfVotes();
$stack1
->setPoll( $poll )
->setOwner( $voter );
2019-11-11 10:44:19 +01:00
$voteA = new Vote();
2019-11-27 17:07:11 +01:00
$voteA
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
2019-11-27 17:07:11 +01:00
->setChoice( $choiceA );
$voteB = new Vote();
$voteB
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
2019-11-27 17:07:11 +01:00
->setChoice( $choiceB );
$stack1->setPseudo( 'chuck norris' );
$manager->persist( $stack1 );
// voter guy votes again with an other pseudo
$stack2 = new StackOfVotes();
$stack2->setPseudo( 'Jean indécis' );
$stack2
->setPoll( $poll )
->setOwner( $voter );
2019-11-11 10:44:19 +01:00
$voteA = new Vote();
2019-11-27 17:07:11 +01:00
$voteA
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack2 )
->setValue( "maybe" )
2019-11-27 17:07:11 +01:00
->setChoice( $choiceA );
2019-11-11 10:44:19 +01:00
2019-11-27 17:07:11 +01:00
$manager->persist( $stack2 );
2019-11-05 17:22:30 +01:00
$poll = new Poll();
2019-11-27 16:14:49 +01:00
$ownerComment = new Comment();
$ownerComment
->setText( "trop bien ce sondage wohooo! signé l'auteur." )
->setOwner( $owner );
$poll->addComment( $ownerComment );
$someoneComment = new Comment();
$someoneComment
->setText( "comme l'auteur se la raconte. PFFFF!" )
->setOwner( $commenterMan );
$poll->addComment( $someoneComment );
$poll->setTitle( 'démo sondage de texte avec deux commentaires' );
2019-11-05 17:22:30 +01:00
$poll->setDescription( 'description du sondage 2' );
2019-11-27 16:39:52 +01:00
2019-11-12 11:55:11 +01:00
$poll->setAdminKey( uniqid() );
2019-11-05 17:22:30 +01:00
$poll->setModificationPolicy( 'self' );
$poll->setMailOnComment( true );
$poll->addTextChoiceArray( [ 'un truc', 'deux trucs' ] );
2019-11-05 17:22:30 +01:00
$poll->setOwner( $owner );
$owner->addPoll( $poll );
$manager->persist( $poll );
2019-11-27 16:14:49 +01:00
$manager->persist( $someoneComment );
$manager->persist( $ownerComment );
2019-11-05 17:22:30 +01:00
2019-11-27 10:57:06 +01:00
2019-11-12 12:00:06 +01:00
// voting test with 2 people
2019-11-27 16:14:49 +01:00
// poll with date type
$poll = new Poll();
$choice = new Choice();
$firstDate = new DateTime();
2019-11-29 10:19:12 +01:00
$choice->setName( $firstDate->format( 'Y-m-d H:i:s' ) );
2019-11-27 16:14:49 +01:00
$choice2 = new Choice();
$choice3 = new Choice();
2019-11-29 10:19:12 +01:00
$choice2->setName( $poll->addDaysToDate( $firstDate, 1 )->format( 'Y-m-d H:i:s' ) );
$choice3->setName( $poll->addDaysToDate( $firstDate, 2 )->format( 'Y-m-d H:i:s' ) );
2019-11-27 16:14:49 +01:00
$poll->setTitle( "c'est pour aujourdhui ou pour demain" )
->setDescription( 'Vous avez le choix dans la date' )
->setKind( 'date' )
->setOwner( $owner )
->addChoice( $choice )
->addChoice( $choice2 )
2020-01-30 11:49:36 +01:00
->addChoice( $choice3 )
2019-11-27 16:14:49 +01:00
->setModificationPolicy( 'self' );
2020-01-30 11:49:36 +01:00
$manager->persist( $poll );
2019-11-27 10:57:06 +01:00
// poll with cartoon choices
$poll = new Poll();
$poll->setTitle( 'dessin animé préféré' )
->setDescription( 'choisissez votre animé préféré' )
2019-11-27 16:14:49 +01:00
->setOwner( $owner )
->setModificationPolicy( 'self' )
2019-11-27 10:57:06 +01:00
->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",
2019-11-27 16:14:49 +01:00
] );
2019-11-27 10:57:06 +01:00
2020-01-30 11:49:36 +01:00
$someoneComment = new Comment();
$someoneComment
->setText( "allez boumbo!" )
->setOwner( $commenterMan );
$poll->addComment( $someoneComment );
$someoneComment2 = new Comment();
$someoneComment2
->setText( "je suis pour la team rocket de digimon" )
->setOwner( $owner );
$poll->addComment( $someoneComment2 );
2019-11-27 10:57:06 +01:00
$manager->persist( $poll );
$stack = new StackOfVotes();
$stack->setPseudo( 'Wulfila' );
$stack
->setPoll( $poll )
->setOwner( $voter );
$vote = new Vote();
$vote
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 2 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 1 ] );
$manager->persist( $stack );
$stack = new StackOfVotes();
$stack->setPseudo( 'Tykayn' );
$stack
->setPoll( $poll )
->setOwner( $voter );
$vote = new Vote();
$vote
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 1 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 2 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "no" )
->setChoice( $poll->getChoices()[ 2 ] );
$manager->persist( $stack );
2019-11-27 16:14:49 +01:00
$manager->persist( $commenterMan );
2019-11-05 16:31:27 +01:00
$manager->flush();
}
}