batch of answers in fixtures

This commit is contained in:
Baptiste Lemoine 2019-11-27 10:57:06 +01:00
parent c0e7173326
commit eba4a14ce8
4 changed files with 296 additions and 250 deletions

View File

@ -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();
} }
} }

View File

@ -50,120 +50,118 @@ class Choice {
private $vote; private $vote;
public function __construct() { public function __construct() {
$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() );
}
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function getName(): ?string { public function getName(): ?string {
return $this->name; return $this->name;
} }
public function setName( string $name ): self { public function setName( string $name ): self {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }
public function getDateTime(): ?DateTimeInterface { public function getDateTime(): ?DateTimeInterface {
return $this->dateTime; return $this->dateTime;
} }
public function setDateTime( ?DateTimeInterface $dateTime ): self { public function setDateTime( ?DateTimeInterface $dateTime ): self {
$this->dateTime = $dateTime; $this->dateTime = $dateTime;
return $this; return $this;
} }
/** /**
* @return Collection|Poll[] * @return Collection|Poll[]
*/ */
public function getPoll(): Collection { public function getPoll(): Collection {
return $this->poll; return $this->poll;
} }
public function addPoll( Poll $poll ): self { public function addPoll( Poll $poll ): self {
if ( ! $this->poll->contains( $poll ) ) { if ( ! $this->poll->contains( $poll ) ) {
$this->poll[] = $poll; $this->poll[] = $poll;
$poll->setChoices( $this ); $poll->setChoices( $this );
} }
return $this; return $this;
} }
public function removePoll( Poll $poll ): self { public function removePoll( Poll $poll ): self {
if ( $this->poll->contains( $poll ) ) { if ( $this->poll->contains( $poll ) ) {
$this->poll->removeElement( $poll ); $this->poll->removeElement( $poll );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $poll->getChoices() === $this ) { if ( $poll->getChoices() === $this ) {
$poll->setChoices( null ); $poll->setChoices( null );
} }
} }
return $this; return $this;
} }
/** /**
* @return Collection|Choice[] * @return Collection|Choice[]
*/ */
public function getStackOfVotes(): Collection { public function getStackOfVotes(): Collection {
return $this->stackOfVotes; return $this->stackOfVotes;
} }
public function addVote( Choice $vote ): self { public function addVote( Choice $vote ): self {
if ( ! $this->stackOfVotes->contains( $vote ) ) { if ( ! $this->stackOfVotes->contains( $vote ) ) {
$this->stackOfVotes[] = $vote; $this->stackOfVotes[] = $vote;
$vote->setChoice( $this ); $vote->setChoice( $this );
} }
return $this; return $this;
} }
public function removeVote( Choice $vote ): self { public function removeVote( Choice $vote ): self {
if ( $this->stackOfVotes->contains( $vote ) ) { if ( $this->stackOfVotes->contains( $vote ) ) {
$this->stackOfVotes->removeElement( $vote ); $this->stackOfVotes->removeElement( $vote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $vote->getChoice() === $this ) { if ( $vote->getChoice() === $this ) {
$vote->setChoice( null ); $vote->setChoice( null );
} }
} }
return $this;
}
public function addStackOfVote(StackOfVotes $stackOfVote): self return $this;
{ }
if (!$this->stackOfVotes->contains($stackOfVote)) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setChoice($this);
}
return $this; public function addStackOfVote( StackOfVotes $stackOfVote ): self {
} if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setChoice( $this );
}
public function removeStackOfVote(StackOfVotes $stackOfVote): self return $this;
{ }
if ($this->stackOfVotes->contains($stackOfVote)) {
$this->stackOfVotes->removeElement($stackOfVote);
// set the owning side to null (unless already changed)
if ($stackOfVote->getChoice() === $this) {
$stackOfVote->setChoice(null);
}
}
return $this; public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
} if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed)
if ( $stackOfVote->getChoice() === $this ) {
$stackOfVote->setChoice( null );
}
}
/** return $this;
* @return Collection|Vote[] }
*/
public function getVote(): Collection /**
{ * @return Collection|Vote[]
return $this->vote; */
} public function getVote(): Collection {
return $this->vote;
}
} }

View File

@ -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
@ -131,280 +139,300 @@ class Poll {
private $stacksOfVotes; private $stacksOfVotes;
public function __construct() { public function __construct() {
$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->setAllowedAnswers( [ 'yes' ] );
}
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function getTitle(): ?string { public function getTitle(): ?string {
return $this->title; return $this->title;
} }
public function setTitle( string $title ): self { public function setTitle( string $title ): self {
$this->title = $title; $this->title = $title;
return $this; return $this;
} }
public function getCreationDate(): ?DateTimeInterface { public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate; return $this->creationDate;
} }
public function setCreationDate( DateTimeInterface $creationDate ): self { public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate; $this->creationDate = $creationDate;
return $this; return $this;
} }
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self { public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate; $this->expiracyDate = $expiracyDate;
return $this; return $this;
} }
public function getOwner(): ?Owner { public function getOwner(): ?Owner {
return $this->owner; return $this->owner;
} }
public function setOwner( ?Owner $owner ): self { public function setOwner( ?Owner $owner ): self {
$this->owner = $owner; $this->owner = $owner;
return $this; return $this;
} }
/** /**
* @return Collection|Vote[] * @return Collection|Vote[]
*/ */
public function getVotes(): Collection { public function getVotes(): Collection {
return $this->votes; return $this->votes;
} }
public function getAdminKey(): ?string { public function getAdminKey(): ?string {
return $this->adminKey; return $this->adminKey;
} }
public function setAdminKey( string $adminKey ): self { public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey; $this->adminKey = $adminKey;
return $this; return $this;
} }
public function getDescription(): ?string { public function getDescription(): ?string {
return $this->description; return $this->description;
} }
public function setDescription( string $description ): self { public function setDescription( string $description ): self {
$this->description = $description; $this->description = $description;
return $this; return $this;
} }
public function getKind(): ?string { public function getKind(): ?string {
return $this->kind; return $this->kind;
} }
public function setKind( string $kind ): self { public function setKind( string $kind ): self {
$this->kind = $kind; $this->kind = $kind;
return $this; return $this;
} }
public function getCustomUrl(): ?string { public function getCustomUrl(): ?string {
return $this->customUrl; return $this->customUrl;
} }
public function setCustomUrl( string $customUrl ): self { public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl; $this->customUrl = $customUrl;
return $this; return $this;
} }
public function getPassword(): ?string { public function getPassword(): ?string {
return $this->password; return $this->password;
} }
public function setPassword( string $password ): self { public function setPassword( string $password ): self {
$this->password = $password; $this->password = $password;
return $this; return $this;
} }
public function getModificationPolicy(): ?string { public function getModificationPolicy(): ?string {
return $this->modificationPolicy; return $this->modificationPolicy;
} }
public function setModificationPolicy( string $modificationPolicy ): self { public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy; $this->modificationPolicy = $modificationPolicy;
return $this; return $this;
} }
public function getMailOnComment(): ?bool { public function getMailOnComment(): ?bool {
return $this->mailOnComment; return $this->mailOnComment;
} }
public function setMailOnComment( bool $mailOnComment ): self { public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment; $this->mailOnComment = $mailOnComment;
return $this; return $this;
} }
public function getMailOnVote(): ?bool { public function getMailOnVote(): ?bool {
return $this->mailOnVote; return $this->mailOnVote;
} }
public function setMailOnVote( bool $mailOnVote ): self { public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote; $this->mailOnVote = $mailOnVote;
return $this; return $this;
} }
public function getHideResults(): ?bool { public function getHideResults(): ?bool {
return $this->hideResults; return $this->hideResults;
} }
public function setHideResults( bool $hideResults ): self { public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults; $this->hideResults = $hideResults;
return $this; return $this;
} }
public function getShowResultEvenIfPasswords(): ?bool { public function getShowResultEvenIfPasswords(): ?bool {
return $this->showResultEvenIfPasswords; return $this->showResultEvenIfPasswords;
} }
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self { public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords; $this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this; return $this;
} }
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
public function getComments(): Collection { public function getComments(): Collection {
return $this->comments; return $this->comments;
} }
public function addComment( Comment $comment ): self { public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) { if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment; $this->comments[] = $comment;
$comment->setPoll( $this ); $comment->setPoll( $this );
} }
return $this; return $this;
} }
public function removeComment( Comment $comment ): self { public function removeComment( Comment $comment ): self {
if ( $this->comments->contains( $comment ) ) { if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment ); $this->comments->removeElement( $comment );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $comment->getPoll() === $this ) { if ( $comment->getPoll() === $this ) {
$comment->setPoll( null ); $comment->setPoll( null );
} }
} }
return $this; return $this;
} }
public function getStacksOfVotes(): ?StackOfVotes { public function getStacksOfVotes(): ?StackOfVotes {
return $this->stacksOfVotes; return $this->stacksOfVotes;
} }
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self { public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes; $this->stacksOfVotes = $stacksOfVotes;
return $this; return $this;
} }
/** /**
* @return Collection|StackOfVotes[] * @return Collection|StackOfVotes[]
*/ */
public function getStackOfVotes(): Collection { public function getStackOfVotes(): Collection {
return $this->stackOfVotes; return $this->stackOfVotes;
} }
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->setPoll( $this ); $stackOfVote->setPoll( $this );
} }
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)
if ( $stackOfVote->getPoll() === $this ) { if ( $stackOfVote->getPoll() === $this ) {
$stackOfVote->setPoll( null ); $stackOfVote->setPoll( null );
} }
} }
return $this; return $this;
} }
public function getExpiracyDate(): ?\DateTimeInterface { public function getExpiracyDate(): ?\DateTimeInterface {
return $this->expiracyDate; return $this->expiracyDate;
} }
public function addVote( Vote $vote ): self { public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) { if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote; $this->votes[] = $vote;
$vote->setPoll( $this ); $vote->setPoll( $this );
} }
return $this; return $this;
} }
public function removeVote( Vote $vote ): self { public function removeVote( Vote $vote ): self {
if ( $this->votes->contains( $vote ) ) { if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote ); $this->votes->removeElement( $vote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) { if ( $vote->getPoll() === $this ) {
$vote->setPoll( null ); $vote->setPoll( null );
} }
} }
return $this; return $this;
} }
/** /**
* @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 ) {
if (!$this->choices->contains($choice)) { $newChoice = new Choice();
$this->choices[] = $choice; $newChoice->setName( $text )
$choice->setPoll($this); ->setPseudo( $pseudo );
} $this->addChoice( $newChoice );
}
return $this; return $this;
} }
public function removeChoice(Choice $choice): self public function addChoice( Choice $choice ): self {
{ if ( ! $this->choices->contains( $choice ) ) {
if ($this->choices->contains($choice)) { $this->choices[] = $choice;
$this->choices->removeElement($choice); $choice->setPoll( $this );
// set the owning side to null (unless already changed) }
if ($choice->getPoll() === $this) {
$choice->setPoll(null);
}
}
return $this; return $this;
} }
public function removeChoice( Choice $choice ): self {
if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice );
// set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) {
$choice->setPoll( null );
}
}
return $this;
}
public function getAllowedAnswers(): ?array {
return $this->allowedAnswers;
}
public function setAllowedAnswers( array $allowedAnswers ): self {
$this->allowedAnswers = $allowedAnswers;
return $this;
}
} }

View File

@ -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;
} }