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

245 lines
6.7 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;
2021-04-21 11:22:01 +02:00
use Doctrine\Persistence\ObjectManager;
2019-11-05 16:31:27 +01:00
class AppPollFixtures extends Fixture {
2021-04-21 11:30:22 +02:00
public const POLL_FIXTURE_ONE = 'citron-poll-fixture';
2019-11-05 16:31:27 +01:00
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
2021-04-21 11:30:22 +02:00
$pollCitronOrange = new Poll();
$pollCitronOrange->setTitle( 'citron ou orange' )
->setCustomUrl('citron')
->setDescription( 'votre sorbert préféré' )
->setAdminKey( uniqid() )
->setModificationPolicy( 'nobody' )
->setPassword('le pass woute woute');
2021-04-21 11:30:22 +02:00
$this->addReference(self::POLL_FIXTURE_ONE, $pollCitronOrange);
$pollCitronOrange->setMailOnVote( true );
$pollCitronOrange->setOwner( $owner );
$owner->addPoll( $pollCitronOrange );
2019-11-05 17:22:30 +01:00
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
2021-04-21 11:30:22 +02:00
$pollCitronOrange
2019-11-11 10:44:19 +01:00
->addChoice( $choiceA )
->addChoice( $choiceB );
2021-04-21 11:30:22 +02:00
$manager->persist( $pollCitronOrange );
2019-11-28 11:51:25 +01:00
2019-11-27 17:07:11 +01:00
$stack1 = new StackOfVotes();
$stack1
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-27 17:07:11 +01:00
->setOwner( $voter );
2019-11-11 10:44:19 +01:00
$voteA = new Vote();
2019-11-27 17:07:11 +01:00
$voteA
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
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
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
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
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-27 17:07:11 +01:00
->setOwner( $voter );
2019-11-11 10:44:19 +01:00
$voteA = new Vote();
2019-11-27 17:07:11 +01:00
$voteA
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
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
2021-04-21 11:30:22 +02:00
$pollCitronOrange = new Poll();
2019-11-27 16:14:49 +01:00
$ownerComment = new Comment();
$ownerComment
->setText( "trop bien ce sondage wohooo! signé l'auteur." )
2021-04-21 11:22:01 +02:00
->setPseudo('un gens qui commente')
2019-11-27 16:14:49 +01:00
->setOwner( $owner );
2021-04-21 11:30:22 +02:00
$pollCitronOrange->addComment( $ownerComment );
2019-11-27 16:14:49 +01:00
$someoneComment = new Comment();
$someoneComment
->setText( "comme l'auteur se la raconte. PFFFF!" )
2021-04-21 11:22:01 +02:00
->setPseudo('un gens qui commente')
2019-11-27 16:14:49 +01:00
->setOwner( $commenterMan );
2021-04-21 11:30:22 +02:00
$pollCitronOrange->addComment( $someoneComment );
2019-11-27 16:14:49 +01:00
2021-04-21 11:30:22 +02:00
$pollCitronOrange->setTitle( 'démo sondage de texte avec deux commentaires' )
->setCustomUrl('demo')
->setDescription( 'description du sondage 2' );
2019-11-27 16:39:52 +01:00
2021-04-21 11:30:22 +02:00
$pollCitronOrange->setAdminKey( uniqid() );
$pollCitronOrange->setModificationPolicy( 'self' );
$pollCitronOrange->setMailOnComment( true );
2021-04-21 11:30:22 +02:00
$pollCitronOrange->addTextChoiceArray( [ 'un truc', 'deux trucs' ] );
$pollCitronOrange->setOwner( $owner );
$owner->addPoll( $pollCitronOrange );
2019-11-05 17:22:30 +01:00
2021-04-21 11:30:22 +02:00
$manager->persist( $pollCitronOrange );
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
2021-04-21 11:30:22 +02:00
$pollCitronOrange = new Poll();
2019-11-27 16:14:49 +01:00
$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();
2021-04-21 11:30:22 +02:00
$choice2->setName( $pollCitronOrange->addDaysToDate( $firstDate, 1 )->format( 'Y-m-d H:i:s' ) );
$choice3->setName( $pollCitronOrange->addDaysToDate( $firstDate, 2 )->format( 'Y-m-d H:i:s' ) );
2019-11-27 16:14:49 +01:00
2021-04-21 11:30:22 +02:00
$pollCitronOrange->setTitle( "c'est pour aujourdhui ou pour demain" )
->setCustomUrl('aujourdhui-ou-demain')
2019-11-27 16:14:49 +01:00
->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' );
2021-04-21 11:30:22 +02:00
$manager->persist( $pollCitronOrange );
2019-11-27 10:57:06 +01:00
// poll with cartoon choices
2021-04-21 11:30:22 +02:00
$pollCitronOrange = new Poll();
$pollCitronOrange->setTitle( 'dessin animé préféré' )
->setCustomUrl('dessin-anime')
2019-11-27 10:57:06 +01:00
->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
2021-04-21 11:22:01 +02:00
->setPseudo('un gens qui commente')
2020-01-30 11:49:36 +01:00
->setText( "allez boumbo!" )
->setOwner( $commenterMan );
2021-04-21 11:30:22 +02:00
$pollCitronOrange->addComment( $someoneComment );
2020-01-30 11:49:36 +01:00
$someoneComment2 = new Comment();
$someoneComment2
2021-04-21 11:22:01 +02:00
->setPseudo('un gens qui commente')
2020-01-30 11:49:36 +01:00
->setText( "je suis pour la team rocket de digimon" )
->setOwner( $owner );
2021-04-21 11:30:22 +02:00
$pollCitronOrange->addComment( $someoneComment2 );
2020-01-30 11:49:36 +01:00
2021-04-21 11:30:22 +02:00
$manager->persist( $pollCitronOrange );
2019-11-27 10:57:06 +01:00
$stack = new StackOfVotes();
$stack->setPseudo( 'Wulfila' );
$stack
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
->setOwner( $voter );
$vote = new Vote();
$vote
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
2021-04-21 11:30:22 +02:00
->setChoice( $pollCitronOrange->getChoices()[ 2 ] );
$vote = new Vote();
$vote
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "maybe" )
2021-04-21 11:30:22 +02:00
->setChoice( $pollCitronOrange->getChoices()[ 1 ] );
$manager->persist( $stack );
$stack = new StackOfVotes();
$stack->setPseudo( 'Tykayn' );
$stack
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
->setOwner( $voter );
$vote = new Vote();
$vote
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
2021-04-21 11:30:22 +02:00
->setChoice( $pollCitronOrange->getChoices()[ 1 ] );
$vote = new Vote();
$vote
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "yes" )
2021-04-21 11:30:22 +02:00
->setChoice( $pollCitronOrange->getChoices()[ 2 ] );
$vote = new Vote();
$vote
2021-04-21 11:30:22 +02:00
->setPoll( $pollCitronOrange )
2019-11-28 11:51:25 +01:00
->setStacksOfVotes( $stack )
->setValue( "no" )
2021-04-21 11:30:22 +02:00
->setChoice( $pollCitronOrange->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();
}
}