mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
batch of answers in fixtures
This commit is contained in:
parent
c0e7173326
commit
eba4a14ce8
@ -7,6 +7,7 @@ use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
@ -22,15 +23,14 @@ class AppPollFixtures extends Fixture {
|
||||
->setPseudo( 'voting_people_TEST' )
|
||||
->setModifierToken( uniqid() );
|
||||
|
||||
// $product = new Product();
|
||||
$poll = new Poll();
|
||||
$poll->setTitle( 'citron ou orange' );
|
||||
$poll->setKind( 'text' );
|
||||
$poll->setDescription( 'votre sorbert préféré' );
|
||||
$poll->setAdminKey( uniqid() );
|
||||
$poll->setModificationPolicy( 'nobody' );
|
||||
$poll->setCreationDate( new \DateTime() );
|
||||
$poll->setExpiracyDate( new \DateTime() );
|
||||
|
||||
$poll->setExpiracyDate( new DateTime() );
|
||||
$poll->setMailOnVote( true );
|
||||
$poll->setOwner( $owner );
|
||||
$owner->addPoll( $poll );
|
||||
@ -46,11 +46,9 @@ class AppPollFixtures extends Fixture {
|
||||
|
||||
$voteA = new Vote();
|
||||
$voteA->setPseudo( 'chuck norris' )
|
||||
->setCreationDate( new DateTime() )
|
||||
->setChoice( $choiceA );
|
||||
$voteA = new Vote();
|
||||
$voteA->setPseudo( 'Néo' )
|
||||
->setCreationDate( new DateTime() )
|
||||
->setChoice( $choiceB );
|
||||
|
||||
$manager->persist( $poll );
|
||||
@ -63,13 +61,13 @@ class AppPollFixtures extends Fixture {
|
||||
$poll->setAdminKey( uniqid() );
|
||||
$poll->setModificationPolicy( 'self' );
|
||||
$poll->setMailOnComment( true );
|
||||
$poll->setCreationDate( new \DateTime() );
|
||||
$poll->setExpiracyDate( new \DateTime() );
|
||||
$poll->setExpiracyDate( new DateTime() );
|
||||
$poll->setOwner( $owner );
|
||||
$owner->addPoll( $poll );
|
||||
|
||||
$manager->persist( $poll );
|
||||
|
||||
|
||||
// voting test with 2 people
|
||||
$stack1 = new StackOfVotes();
|
||||
$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->setAdminKey( uniqid() );
|
||||
$poll->setCustomUrl( 'boudoum_podom_podom' );
|
||||
$poll->setCreationDate( new \DateTime() );
|
||||
$poll->setExpiracyDate( new \DateTime() );
|
||||
|
||||
$poll->setExpiracyDate( new DateTime() );
|
||||
$poll->setMailOnComment( true );
|
||||
$poll->setMailOnVote( true );
|
||||
$poll->setOwner( $owner );
|
||||
@ -100,6 +98,24 @@ class AppPollFixtures extends Fixture {
|
||||
$manager->persist( $owner );
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ class Choice {
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->stackOfVotes = new ArrayCollection();
|
||||
$this->vote = new ArrayCollection();
|
||||
$this->setDateTime( new \DateTime() );
|
||||
}
|
||||
|
||||
|
||||
@ -136,23 +137,21 @@ class Choice {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addStackOfVote(StackOfVotes $stackOfVote): self
|
||||
{
|
||||
if (!$this->stackOfVotes->contains($stackOfVote)) {
|
||||
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
|
||||
$this->stackOfVotes[] = $stackOfVote;
|
||||
$stackOfVote->setChoice($this);
|
||||
$stackOfVote->setChoice( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeStackOfVote(StackOfVotes $stackOfVote): self
|
||||
{
|
||||
if ($this->stackOfVotes->contains($stackOfVote)) {
|
||||
$this->stackOfVotes->removeElement($stackOfVote);
|
||||
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);
|
||||
if ( $stackOfVote->getChoice() === $this ) {
|
||||
$stackOfVote->setChoice( null );
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +161,7 @@ class Choice {
|
||||
/**
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getVote(): Collection
|
||||
{
|
||||
public function getVote(): Collection {
|
||||
return $this->vote;
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,14 @@ class Poll {
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
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
|
||||
* everybody - can modify votes
|
||||
@ -135,6 +143,8 @@ class Poll {
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->stackOfVotes = new ArrayCollection();
|
||||
$this->setCreationDate( new \DateTime() );
|
||||
$this->setAllowedAnswers( [ 'yes' ] );
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
@ -380,31 +390,49 @@ class Poll {
|
||||
/**
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function getChoices(): Collection
|
||||
{
|
||||
public function getChoices(): Collection {
|
||||
return $this->choices;
|
||||
}
|
||||
|
||||
public function addChoice(Choice $choice): self
|
||||
{
|
||||
if (!$this->choices->contains($choice)) {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll($this);
|
||||
public function addTextChoiceArray( Array $choiceTextArray, $pseudo = "some body" ): self {
|
||||
foreach ( $choiceTextArray as $text ) {
|
||||
$newChoice = new Choice();
|
||||
$newChoice->setName( $text )
|
||||
->setPseudo( $pseudo );
|
||||
$this->addChoice( $newChoice );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeChoice(Choice $choice): self
|
||||
{
|
||||
if ($this->choices->contains($choice)) {
|
||||
$this->choices->removeElement($choice);
|
||||
public function addChoice( Choice $choice ): self {
|
||||
if ( ! $this->choices->contains( $choice ) ) {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll( $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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,10 @@ class Vote {
|
||||
*/
|
||||
private $poll;
|
||||
|
||||
public function __construct() {
|
||||
$this->setCreationDate( new \DateTime() );
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user