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

View File

@ -65,7 +65,11 @@ class Choice {
return $this->name; 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; $this->name = $name;
return $this; return $this;

View File

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

View File

@ -49,12 +49,17 @@ class Owner {
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
private $modifierToken; private $modifierToken;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
public function __construct() { public function __construct() {
$this->polls = new ArrayCollection(); $this->polls = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection(); $this->stackOfVotes = new ArrayCollection();
$this->setCreatedAt( new \DateTime() );
$this->setModifierToken( uniqid() );
} }
public function getId(): ?int { public function getId(): ?int {
@ -195,4 +200,14 @@ class Owner {
return $this; 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) * @ORM\Column(type="string", length=255)
* @Serializer\Type("string") * @Serializer\Type("string")
*/ */
public $modificationPolicy; public $modificationPolicy = 'nobody';
/** /**
* send a mail on a new comment * send a mail on a new comment
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
@ -134,15 +134,33 @@ class Poll {
*/ */
private $adminKey; private $adminKey;
/**
* number of days from now for default expiracy date
* @var int
*/
private $defaultExpiracyDaysFromNow = 60;
public function __construct() { public function __construct() {
$this->adminKey = uniqid();
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$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->setCreationDate( new \DateTime() );
$this->setExpiracyDate( $this->addDaysToDate(
new \DateTime(),
$this->defaultExpiracyDaysFromNow
) );
$this->setAllowedAnswers( [ 'yes' ] ); $this->setAllowedAnswers( [ 'yes' ] );
} }
public function addDaysToDate( \DateTime $date, int $days ) {
$st = strtotime( $date->getTimestamp() . ' + ' . $days . ' days' );
return new \DateTime( "@$st" );
}
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }