diff --git a/src/DataFixtures/AppPollFixtures.php b/src/DataFixtures/AppPollFixtures.php index bdb2ca0..ef6c64f 100644 --- a/src/DataFixtures/AppPollFixtures.php +++ b/src/DataFixtures/AppPollFixtures.php @@ -62,6 +62,9 @@ class AppPollFixtures extends Fixture { $poll->setModificationPolicy( 'self' ); $poll->setMailOnComment( true ); $poll->setExpiracyDate( new DateTime() ); + + + $poll->addTextChoiceArray( [ 'un truc', 'deux trucs' ] ); $poll->setOwner( $owner ); $owner->addPoll( $poll ); @@ -70,11 +73,15 @@ class AppPollFixtures extends Fixture { // voting test with 2 people $stack1 = new StackOfVotes(); + $vote0 = new Vote(); + $vote0->setChoice( $poll->getChoices()[ 0 ] ); $stack1->setOwner( $voter ) - ->addVote( $poll->getChoices()[ 0 ] ); + ->addVote( $vote0 ); $stack2 = new StackOfVotes(); - $stack1->setOwner( $owner )->addVote( $poll->getChoices()[ 1 ] ); + $vote1 = new Vote(); + $vote1->setChoice( $poll->getChoices()[ 1 ] ); + $stack1->setOwner( $owner )->addVote( $vote1 ); $voter->addStackOfVote( $stack1 ); $owner->addStackOfVote( $stack2 ); diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index 1a0d013..44df862 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -47,12 +47,12 @@ class Choice { * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice") * @Serializer\Type("App\Entity\Vote") */ - private $vote; + private $votes; public function __construct() { $this->poll = new ArrayCollection(); $this->stackOfVotes = new ArrayCollection(); - $this->vote = new ArrayCollection(); + $this->votes = new ArrayCollection(); $this->setDateTime( new \DateTime() ); } @@ -88,6 +88,12 @@ class Choice { return $this->poll; } + public function setPoll( Poll $poll ): self { + $this->poll = [ $poll ]; + + return $this; + } + public function addPoll( Poll $poll ): self { if ( ! $this->poll->contains( $poll ) ) { $this->poll[] = $poll; @@ -161,7 +167,7 @@ class Choice { /** * @return Collection|Vote[] */ - public function getVote(): Collection { - return $this->vote; + public function getVotes(): Collection { + return $this->votes; } } diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 7d6d7db..f34f53d 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -17,7 +17,7 @@ class Comment { private $id; /** - * @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="text") + * @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="comments") */ private $owner; diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 775f492..a956337 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -133,10 +133,6 @@ class Poll { * @Serializer\Type("string") */ private $adminKey; - /** - * @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes") - */ - private $stacksOfVotes; public function __construct() { $this->votes = new ArrayCollection(); @@ -394,11 +390,10 @@ class Poll { return $this->choices; } - public function addTextChoiceArray( Array $choiceTextArray, $pseudo = "some body" ): self { + public function addTextChoiceArray( Array $choiceTextArray ): self { foreach ( $choiceTextArray as $text ) { $newChoice = new Choice(); - $newChoice->setName( $text ) - ->setPseudo( $pseudo ); + $newChoice->setName( $text ); $this->addChoice( $newChoice ); } diff --git a/src/Entity/StackOfVotes.php b/src/Entity/StackOfVotes.php index 914339d..1fa7daa 100644 --- a/src/Entity/StackOfVotes.php +++ b/src/Entity/StackOfVotes.php @@ -19,9 +19,13 @@ class StackOfVotes { private $id; /** - * @ORM\OneToMany(targetEntity="App\Entity\poll", mappedBy="stacksOfVotes", cascade={"persist","remove"}) + * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"}) */ private $votes; + /** + * @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"}) + */ + private $poll; /** * @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes") @@ -43,21 +47,21 @@ class StackOfVotes { return $this->votes; } - public function addVote( poll $vote ): self { + public function addVote( Vote $vote ): self { if ( ! $this->votes->contains( $vote ) ) { $this->votes[] = $vote; - $vote->setStacksOfVotes( $this ); + $vote->setStackOfVotes( $this ); } return $this; } - public function removeVote( poll $vote ): self { + public function removeVote( Vote $vote ): self { if ( $this->votes->contains( $vote ) ) { $this->votes->removeElement( $vote ); // set the owning side to null (unless already changed) - if ( $vote->getStacksOfVotes() === $this ) { - $vote->setStacksOfVotes( null ); + if ( $vote->getStackOfVotes() === $this ) { + $vote->setStackOfVotes( null ); } } @@ -83,4 +87,14 @@ class StackOfVotes { return $this; } + + public function getPoll(): ?Poll { + return $this->poll; + } + + public function setPoll( ?Poll $poll ): self { + $this->poll = $poll; + + return $this; + } } diff --git a/src/Entity/Vote.php b/src/Entity/Vote.php index 2f41c17..023e094 100644 --- a/src/Entity/Vote.php +++ b/src/Entity/Vote.php @@ -46,6 +46,12 @@ class Vote { * @Serializer\Type("App\Entity\Poll") */ private $poll; + /** + * @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes") + * @ORM\JoinColumn(nullable=false) + * @Serializer\Type("App\Entity\StackOfVotes") + */ + private $stackOfVotes; public function __construct() { $this->setCreationDate( new \DateTime() ); @@ -104,4 +110,14 @@ class Vote { return $this; } + + public function getStackOfVotes(): ?StackOfVotes { + return $this->stackOfVotes; + } + + public function setStackOfVotes( ?StackOfVotes $stackOfVotes ): self { + $this->stackOfVotes = $stackOfVotes; + + return $this; + } }