fixture with date

This commit is contained in:
Baptiste Lemoine 2019-11-27 16:14:49 +01:00
parent 945e677d49
commit c02edb5a76
5 changed files with 132 additions and 40 deletions

View File

@ -3,9 +3,9 @@
namespace App\DataFixtures;
use App\Entity\Choice;
use App\Entity\Comment;
use App\Entity\Owner;
use App\Entity\Poll;
use App\Entity\StackOfVotes;
use App\Entity\Vote;
use DateTime;
use Doctrine\Bundle\FixturesBundle\Fixture;
@ -16,8 +16,11 @@ class AppPollFixtures extends Fixture {
$owner = new Owner();
$owner->setEmail( 'tktest@tktest.com' )
->setPseudo( 'tk_TEST' )
->setModifierToken( uniqid() );
->setPseudo( 'tk_TEST' );
$commenterMan = new Owner();
$commenterMan->setEmail( 'tktest_commentateur@tktest.com' )
->setPseudo( 'tk_TEST_commentateur' );
$voter = new Owner();
$voter->setEmail( 'testing_vote_people@tktest.com' )
->setPseudo( 'voting_people_TEST' )
@ -55,9 +58,23 @@ class AppPollFixtures extends Fixture {
$poll = new Poll();
$poll->setTitle( 'démo sondage de texte 2' );
$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' );
$poll->setDescription( 'description du sondage 2' );
$poll->setKind( 'date' );
$poll->setKind( 'text' );
$poll->setAdminKey( uniqid() );
$poll->setModificationPolicy( 'self' );
$poll->setMailOnComment( true );
@ -69,47 +86,80 @@ class AppPollFixtures extends Fixture {
$owner->addPoll( $poll );
$manager->persist( $poll );
$manager->persist( $someoneComment );
$manager->persist( $ownerComment );
// voting test with 2 people
$stack1 = new StackOfVotes();
$vote0 = new Vote();
$vote0->setChoice( $poll->getChoices()[ 0 ] );
$stack1->setOwner( $voter )
->addVote( $vote0 );
// $stack1 = new StackOfVotes();
// $vote0 = new Vote();
// $vote0->setChoice( $poll->getChoices()[ 0 ] );
// $stack1->setOwner( $voter )
// ->addVote( $vote0 );
//
// $stack2 = new StackOfVotes();
// $vote1 = new Vote();
// $vote1
// ->setChoice( $poll->getChoices()[ 1 ] );
// $stack1
// ->setOwner( $owner )
// ->addVote( $vote1 );
//
//
// $voter->addStackOfVote( $stack1 );
// $owner->addStackOfVote( $stack2 );
//
// $poll = new Poll();
// $poll->setTitle( 'accès restreint sondage de texte' );
// $poll->setKind( 'text' );
// $poll->setPassword( md5( 'mot_de_passe_super' ) );
// $poll->setModificationPolicy( 'everybody' );
// $poll->setDescription( 'description du sondage a accès restreint. le mot de passe est mot_de_passe_super' );
// $poll->setAdminKey( uniqid() );
// $poll->setCustomUrl( 'boudoum_podom_podom' );
//
// $poll->setExpiracyDate( new DateTime() );
// $poll->setMailOnComment( true );
// $poll->setMailOnVote( true );
// $poll->setOwner( $owner );
// $owner->addPoll( $poll );
//
// $manager->persist( $vote1 );
// $manager->persist( $vote0 );
// $manager->persist( $stack1 );
// $manager->persist( $stack2 );
// $manager->persist( $poll );
// $manager->persist( $owner );
// $manager->persist( $voter );
$stack2 = new StackOfVotes();
$vote1 = new Vote();
$vote1->setChoice( $poll->getChoices()[ 1 ] );
$stack1->setOwner( $owner )->addVote( $vote1 );
$voter->addStackOfVote( $stack1 );
$owner->addStackOfVote( $stack2 );
$poll = new Poll();
$poll->setTitle( 'accès restreint sondage de texte' );
$poll->setKind( 'text' );
$poll->setPassword( md5( 'mot_de_passe_super' ) );
$poll->setModificationPolicy( 'everybody' );
$poll->setDescription( 'description du sondage a accès restreint. le mot de passe est mot_de_passe_super' );
$poll->setAdminKey( uniqid() );
$poll->setCustomUrl( 'boudoum_podom_podom' );
$poll->setExpiracyDate( new DateTime() );
$poll->setMailOnComment( true );
$poll->setMailOnVote( true );
$poll->setOwner( $owner );
$owner->addPoll( $poll );
$manager->persist( $poll );
$manager->persist( $owner );
$manager->persist( $voter );
// poll with date type
$poll = new Poll();
$choice = new Choice();
$firstDate = new DateTime();
$choice->setName( $firstDate );
$choice2 = new Choice();
$choice3 = new Choice();
$choice2->setName( $poll->addDaysToDate( $firstDate, 1 ) );
$choice3->setName( $poll->addDaysToDate( $firstDate, 2 ) );
$poll->setTitle( "c'est pour aujourdhui ou pour demain" )
->setDescription( 'Vous avez le choix dans la date' )
->setExpiracyDate( new DateTime() )
->setKind( 'date' )
->setOwner( $owner )
->addChoice( $choice )
->addChoice( $choice2 )
->setModificationPolicy( 'self' );
// poll with cartoon choices
$poll = new Poll();
$poll->setTitle( 'dessin animé préféré' )
->setDescription( 'choisissez votre animé préféré' )
->setExpiracyDate( new DateTime() )
->setKind( 'text' )
->setOwner( $owner )
->setModificationPolicy( 'self' )
->addTextChoiceArray( [
"Vic le viking",
"Boumbo petite automobile",
@ -118,11 +168,12 @@ class AppPollFixtures extends Fixture {
"Foot 2 rue",
"Le chat, la vache, et l'océan",
"Digimon",
],
'fixture land' );
] );
$manager->persist( $poll );
$manager->persist( $commenterMan );
$manager->flush();
}
}

View File

@ -65,7 +65,11 @@ class Choice {
return $this->name;
}
public function setName( string $name ): self {
public function setName( $name ): self {
if ( is_a( $name, 'DateTime' ) ) {
$this->setDateTime( $name );
$name = $name->format( 'D Y-m-d' );
}
$this->name = $name;
return $this;

View File

@ -36,6 +36,10 @@ class Comment {
*/
private $poll;
function __construct() {
$this->setCreatedAt( new \DateTime() );
}
public function getId(): ?int {
return $this->id;
}

View File

@ -49,12 +49,17 @@ class Owner {
* @ORM\Column(type="string", length=255)
*/
private $modifierToken;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
public function __construct() {
$this->polls = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
$this->setCreatedAt( new \DateTime() );
$this->setModifierToken( uniqid() );
}
public function getId(): ?int {
@ -195,4 +200,14 @@ class Owner {
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt( \DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
}

View File

@ -77,7 +77,7 @@ class Poll {
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
*/
public $modificationPolicy;
public $modificationPolicy = 'nobody';
/**
* send a mail on a new comment
* @ORM\Column(type="boolean", nullable=true)
@ -134,15 +134,33 @@ class Poll {
*/
private $adminKey;
/**
* number of days from now for default expiracy date
* @var int
*/
private $defaultExpiracyDaysFromNow = 60;
public function __construct() {
$this->adminKey = uniqid();
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
$this->setCreationDate( new \DateTime() );
$this->setExpiracyDate( $this->addDaysToDate(
new \DateTime(),
$this->defaultExpiracyDaysFromNow
) );
$this->setAllowedAnswers( [ 'yes' ] );
}
public function addDaysToDate( \DateTime $date, int $days ) {
$st = strtotime( $date->getTimestamp() . ' + ' . $days . ' days' );
return new \DateTime( "@$st" );
}
public function getId(): ?int {
return $this->id;
}