valid schema

This commit is contained in:
Baptiste Lemoine 2019-11-28 11:51:25 +01:00
parent a0842f3b7c
commit 010f07230d
6 changed files with 345 additions and 345 deletions

View File

@ -265,6 +265,8 @@ class DefaultController extends AbstractController {
if ( ! $poll ) {
return $this->json( [ 'message' => 'poll not found' ], 404 );
}
$em = $this->getDoctrine()->getManager();
$data = $request->getContent();
$data = json_decode( $data, true );
@ -273,13 +275,21 @@ class DefaultController extends AbstractController {
->setEmail( $data[ 'email' ] )
->setPseudo( $data[ 'pseudo' ] );
$stack = new StackOfVotes();
$stack
->setPseudo( $data[ 'pseudo' ] )
->setPoll( $poll );
foreach ( $data[ 'votes' ] as $voteInfo ) {
$vote = new Vote();
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
$vote->setPoll( $poll )
->setChoice( $foundChoice )
->setValue( $voteInfo[ 'value' ] );
$vote->setPoll( $poll );
$stack->addVote( $vote );
$poll->addVote( $vote );
$em->persist( $vote );
$em->persist( $foundChoice );
}
// find poll from choices
@ -299,13 +309,14 @@ class DefaultController extends AbstractController {
// ->setPoll( $poll );
// $foundOwner->addComment( $comment );
//
$em = $this->getDoctrine()->getManager();
$em->persist( $stack );
$em->persist( $poll );
// $em->persist( $comment );
$em->flush();
return $this->json( [
'message' => 'you created a comment',
'message' => 'you created a vote',
'vote_stack' => $stack,
'json_you_sent' => $data,
],
201 );

View File

@ -15,7 +15,10 @@ use Doctrine\Common\Persistence\ObjectManager;
class AppPollFixtures extends Fixture {
public function load( ObjectManager $manager ) {
$owner = new Owner();
/**
* create a few demo people
*/
$owner = new Owner(); // someone who creates the polls
$owner->setEmail( 'tktest@tktest.com' )
->setPseudo( 'tk_TEST' );
$commenterMan = new Owner();
@ -26,6 +29,11 @@ class AppPollFixtures extends Fixture {
$voter->setEmail( 'testing_vote_people@tktest.com' )
->setPseudo( 'voting_people_TEST' )
->setModifierToken( uniqid() );
$manager->persist( $owner );
$manager->persist( $commenterMan );
$manager->persist( $voter );
$manager->flush();
$poll = new Poll();
$poll->setTitle( 'citron ou orange' )
@ -45,9 +53,7 @@ class AppPollFixtures extends Fixture {
->addChoice( $choiceA )
->addChoice( $choiceB );
$manager->persist( $poll );
$manager->persist( $owner );
$manager->persist( $voter );
$manager->flush();
$stack1 = new StackOfVotes();
$stack1
@ -57,13 +63,13 @@ class AppPollFixtures extends Fixture {
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStackOfVotes( $stack1 )
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
->setChoice( $choiceA );
$voteB = new Vote();
$voteB
->setPoll( $poll )
->setStackOfVotes( $stack1 )
->setStacksOfVotes( $stack1 )
->setValue( "yes" )
->setChoice( $choiceB );
@ -83,7 +89,7 @@ class AppPollFixtures extends Fixture {
$voteA = new Vote();
$voteA
->setPoll( $poll )
->setStackOfVotes( $stack2 )
->setStacksOfVotes( $stack2 )
->setValue( "maybe" )
->setChoice( $choiceA );
@ -210,13 +216,13 @@ class AppPollFixtures extends Fixture {
$vote = new Vote();
$vote
->setPoll( $poll )
->setStackOfVotes( $stack )
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 2 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
->setStackOfVotes( $stack )
->setStacksOfVotes( $stack )
->setValue( "maybe" )
->setChoice( $poll->getChoices()[ 1 ] );
@ -230,19 +236,19 @@ class AppPollFixtures extends Fixture {
$vote = new Vote();
$vote
->setPoll( $poll )
->setStackOfVotes( $stack )
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 1 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
->setStackOfVotes( $stack )
->setStacksOfVotes( $stack )
->setValue( "yes" )
->setChoice( $poll->getChoices()[ 2 ] );
$vote = new Vote();
$vote
->setPoll( $poll )
->setStackOfVotes( $stack )
->setStacksOfVotes( $stack )
->setValue( "no" )
->setChoice( $poll->getChoices()[ 2 ] );

View File

@ -33,145 +33,90 @@ class Choice {
public $dateTime;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="choices", cascade={"persist"})
* @Serializer\Type("App\Entity\Poll")
*/
private $poll;
/**
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="choice")
* @Serializer\Type("App\Entity\StackOfVotes")
*/
public $stackOfVotes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice")
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
* @Serializer\Type("App\Entity\Vote")
*/
public $votes;
public function __construct() {
$this->poll = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
$this->votes = new ArrayCollection();
$this->setDateTime( new \DateTime() );
}
$this->poll = new ArrayCollection();
$this->votes = new ArrayCollection();
$this->setDateTime( new \DateTime() );
}
public function getId(): ?int {
return $this->id;
}
return $this->id;
}
public function getName(): ?string {
return $this->name;
}
return $this->name;
}
public function setName( $name ): self {
if ( is_a( $name, 'DateTime' ) ) {
$this->setDateTime( $name );
$name = $name->format( 'D Y-m-d' );
}
$this->name = $name;
return $this;
}
if ( is_a( $name, 'DateTime' ) ) {
$this->setDateTime( $name );
$name = $name->format( 'D Y-m-d' );
}
$this->name = $name;
return $this;
}
public function getDateTime(): ?DateTimeInterface {
return $this->dateTime;
}
return $this->dateTime;
}
public function setDateTime( ?DateTimeInterface $dateTime ): self {
$this->dateTime = $dateTime;
$this->dateTime = $dateTime;
return $this;
}
return $this;
}
/**
* @return Collection|Poll[]
*/
public function getPoll(): Collection {
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;
$poll->setChoices( $this );
}
return $this;
}
public function removePoll( Poll $poll ): self {
if ( $this->poll->contains( $poll ) ) {
$this->poll->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getChoices() === $this ) {
$poll->setChoices( null );
}
}
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getStackOfVotes(): Collection {
return $this->stackOfVotes;
}
public function addVote( Choice $vote ): self {
if ( ! $this->stackOfVotes->contains( $vote ) ) {
$this->stackOfVotes[] = $vote;
$vote->setChoice( $this );
}
return $this;
}
public function removeVote( Choice $vote ): self {
if ( $this->stackOfVotes->contains( $vote ) ) {
$this->stackOfVotes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getChoice() === $this ) {
$vote->setChoice( null );
}
}
return $this;
}
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setChoice( $this );
}
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 getVotes(): Collection {
return $this->votes;
}
return $this->votes;
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setChoice( $this );
}
return $this;
}
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->getChoice() === $this ) {
$vote->setChoice( null );
}
}
return $this;
}
public function getPoll(): ?Poll
{
return $this->poll;
}
public function setPoll(?Poll $poll): self
{
$this->poll = $poll;
return $this;
}
}

View File

@ -111,7 +111,7 @@ class Poll {
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\StackOfVotes")
*/
public $stackOfVotes;
public $stacksOfVotes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\Choice")
@ -142,314 +142,349 @@ class Poll {
public function __construct() {
$this->adminKey = uniqid();
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
$this->setCreationDate( new \DateTime() );
$this->setExpiracyDate( $this->addDaysToDate(
new \DateTime(),
$this->defaultExpiracyDaysFromNow
) );
$this->setAllowedAnswers( [ 'yes' ] );
}
$this->adminKey = uniqid();
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stacksOfVotes = new ArrayCollection();
$this->setCreationDate( new \DateTime() );
$this->setExpiracyDate( $this->addDaysToDate(
new \DateTime(),
$this->defaultExpiracyDaysFromNow
) );
$this->setAllowedAnswers( [ 'yes' ] );
}
public function findChoiceById( $id ) {
return new Choice(); // TODO
}
public function findChoiceById( int $id ) {
error_reporting( E_ALL ^ E_NOTICE );
$choices = $this->getChoices();
var_dump( count( $choices ) );
foreach ( $choices as $choice ) {
if ( $choice && $choice->getId() == $id ) {
return $choice;
}
return null;
}
// if ( $choices && $choices->containsKey( $id ) ) {
// $foundChoice = $choices->get( $id );
// } else {
// $foundChoice = new Choice();
// $foundChoice->setPoll( $this );
// }
//
// return $foundChoice;
}
public function addDaysToDate( \DateTime $date, int $days ) {
$st = strtotime( $date->getTimestamp() . ' + ' . $days . ' days' );
return new \DateTime( $st );
}
$st = strtotime( $date->getTimestamp() . ' + ' . $days . ' days' );
return new \DateTime( $st );
}
public function getId(): ?int {
return $this->id;
}
return $this->id;
}
public function getTitle(): ?string {
return $this->title;
}
return $this->title;
}
public function setTitle( string $title ): self {
$this->title = $title;
return $this;
}
$this->title = $title;
return $this;
}
public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate;
}
return $this->creationDate;
}
public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
return $this;
}
$this->creationDate = $creationDate;
return $this;
}
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate;
return $this;
}
$this->expiracyDate = $expiracyDate;
return $this;
}
public function getOwner(): ?Owner {
return $this->owner;
}
return $this->owner;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
$this->owner = $owner;
return $this;
}
/**
* @return Collection|Vote[]
*/
public function getVotes(): Collection {
return $this->votes;
}
return $this->votes;
}
public function getAdminKey(): ?string {
return $this->adminKey;
}
return $this->adminKey;
}
public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey;
return $this;
}
$this->adminKey = $adminKey;
return $this;
}
public function getDescription(): ?string {
return $this->description;
}
return $this->description;
}
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
$this->description = $description;
return $this;
}
public function getKind(): ?string {
return $this->kind;
}
return $this->kind;
}
public function setKind( string $kind ): self {
$this->kind = $kind;
return $this;
}
$this->kind = $kind;
return $this;
}
public function getCustomUrl(): ?string {
return $this->customUrl;
}
return $this->customUrl;
}
public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl;
return $this;
}
$this->customUrl = $customUrl;
return $this;
}
public function getPassword(): ?string {
return $this->password;
}
return $this->password;
}
public function setPassword( string $password ): self {
$this->password = $password;
return $this;
}
$this->password = $password;
return $this;
}
public function getModificationPolicy(): ?string {
return $this->modificationPolicy;
}
return $this->modificationPolicy;
}
public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy;
return $this;
}
$this->modificationPolicy = $modificationPolicy;
return $this;
}
public function getMailOnComment(): ?bool {
return $this->mailOnComment;
}
return $this->mailOnComment;
}
public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment;
return $this;
}
$this->mailOnComment = $mailOnComment;
return $this;
}
public function getMailOnVote(): ?bool {
return $this->mailOnVote;
}
return $this->mailOnVote;
}
public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote;
return $this;
}
$this->mailOnVote = $mailOnVote;
return $this;
}
public function getHideResults(): ?bool {
return $this->hideResults;
}
return $this->hideResults;
}
public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults;
return $this;
}
$this->hideResults = $hideResults;
return $this;
}
public function getShowResultEvenIfPasswords(): ?bool {
return $this->showResultEvenIfPasswords;
}
return $this->showResultEvenIfPasswords;
}
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
return $this->comments;
}
return $this->comments;
}
public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
$comment->setPoll( $this );
}
return $this;
}
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
$comment->setPoll( $this );
}
return $this;
}
public function removeComment( Comment $comment ): self {
if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment );
// set the owning side to null (unless already changed)
if ( $comment->getPoll() === $this ) {
$comment->setPoll( null );
}
}
if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment );
// set the owning side to null (unless already changed)
if ( $comment->getPoll() === $this ) {
$comment->setPoll( null );
}
}
return $this;
}
return $this;
}
public function getStacksOfVotes(): ?StackOfVotes {
return $this->stacksOfVotes;
}
public function getStacksOfVotes() {
return $this->stacksOfVotes;
}
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes;
$this->stacksOfVotes = $stacksOfVotes;
return $this;
}
return $this;
}
/**
* @return Collection|StackOfVotes[]
*/
public function getStackOfVotes(): Collection {
return $this->stackOfVotes;
}
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setPoll( $this );
}
return $this;
}
if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) {
$this->stacksOfVotes[] = $stackOfVote;
$stackOfVote->setPoll( $this );
}
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->getPoll() === $this ) {
$stackOfVote->setPoll( null );
}
}
return $this;
}
if ( $this->stacksOfVotes->contains( $stackOfVote ) ) {
$this->stacksOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed)
if ( $stackOfVote->getPoll() === $this ) {
$stackOfVote->setPoll( null );
}
}
return $this;
}
public function getExpiracyDate(): ?\DateTimeInterface {
return $this->expiracyDate;
}
return $this->expiracyDate;
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
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->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection {
return $this->choices;
}
return $this->choices;
}
public function addTextChoiceArray( Array $choiceTextArray ): self {
foreach ( $choiceTextArray as $text ) {
$newChoice = new Choice();
$newChoice->setName( $text );
$this->addChoice( $newChoice );
}
return $this;
}
foreach ( $choiceTextArray as $text ) {
$newChoice = new Choice();
$newChoice->setName( $text );
$this->addChoice( $newChoice );
}
return $this;
}
public function addChoice( Choice $choice ): self {
if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice;
$choice->setPoll( $this );
}
return $this;
}
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 );
}
}
return $this;
}
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;
}
return $this->allowedAnswers;
}
public function setAllowedAnswers( array $allowedAnswers ): self {
$this->allowedAnswers = $allowedAnswers;
$this->allowedAnswers = $allowedAnswers;
return $this;
}
return $this;
}
public function addStacksOfVote(StackOfVotes $stacksOfVote): self
{
if (!$this->stacksOfVotes->contains($stacksOfVote)) {
$this->stacksOfVotes[] = $stacksOfVote;
$stacksOfVote->setPoll($this);
}
return $this;
}
public function removeStacksOfVote(StackOfVotes $stacksOfVote): self
{
if ($this->stacksOfVotes->contains($stacksOfVote)) {
$this->stacksOfVotes->removeElement($stacksOfVote);
// set the owning side to null (unless already changed)
if ($stacksOfVote->getPoll() === $this) {
$stacksOfVote->setPoll(null);
}
}
return $this;
}
}

View File

@ -26,15 +26,18 @@ class StackOfVotes {
public $pseudo;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
* @Serializer\Expose()
*/
private $votes;
public $votes;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
private $poll;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
* @Serializer\Expose()
*/
private $owner;
@ -58,7 +61,7 @@ class StackOfVotes {
$vote->setPoll( $this->getPoll() );
$this->votes[] = $vote;
$vote->setStackOfVotes( $this );
$vote->setStacksOfVotes( $this );
}
return $this;
@ -68,8 +71,8 @@ class StackOfVotes {
if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getStackOfVotes() === $this ) {
$vote->setStackOfVotes( null );
if ( $vote->getStacksOfVotes() === $this ) {
$vote->setStacksOfVotes( null );
}
}

View File

@ -23,7 +23,7 @@ class Vote {
*/
public $creationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\choice")
*/
@ -36,7 +36,7 @@ class Vote {
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes")
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\Poll")
*/
@ -46,7 +46,7 @@ class Vote {
* @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\StackOfVotes")
*/
private $stackOfVotes;
private $stacksOfVotes;
public function __construct() {
$this->setCreationDate( new \DateTime() );
@ -99,12 +99,12 @@ class Vote {
return $this;
}
public function getStackOfVotes(): ?StackOfVotes {
return $this->stackOfVotes;
public function getStacksOfVotes(): ?StackOfVotes {
return $this->stacksOfVotes;
}
public function setStackOfVotes( ?StackOfVotes $stackOfVotes ): self {
$this->stackOfVotes = $stackOfVotes;
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes;
return $this;
}