mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ update modeling of entities with stack
This commit is contained in:
parent
eba4a14ce8
commit
945e677d49
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user