From 4de3dd7ca3306e2a0ca37240cfbab31cb1c08aa8 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Thu, 23 Jan 2020 14:47:26 +0100 Subject: [PATCH 1/2] :zap: handle vote stack --- funky-framadate-front | 1 - src/Controller/DefaultController.php | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) delete mode 160000 funky-framadate-front diff --git a/funky-framadate-front b/funky-framadate-front deleted file mode 160000 index 47adf12..0000000 --- a/funky-framadate-front +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 47adf12bc89e48914c8b801e34b261c23b827fd2 diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 7b8ffab..aee5a26 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -423,6 +423,7 @@ class DefaultController extends AbstractController { $emOwner = $this->getDoctrine()->getRepository( Owner::class ); + $emChoice = $this->getDoctrine()->getRepository( Choice::class ); $existingOwner = false; $foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) ); // manage existing or new Owner @@ -443,8 +444,21 @@ class DefaultController extends AbstractController { ->setPseudo( $data[ 'pseudo' ] ) ->setPoll( $poll ); foreach ( $data[ 'votes' ] as $voteInfo ) { + + if ( ! isset( $voteInfo[ 'value' ] ) ) { + continue; + } + $allowedValuesToAnswer = [ 'yes', 'maybe', 'no' ]; + + if ( ! in_array( $voteInfo[ 'value' ], $allowedValuesToAnswer ) ) { + return $this->json( [ + 'message' => 'answer ' . $voteInfo[ 'value' ] . ' is not allowed. should be yes, maybe, or no.', + 'vote_stack' => $stack, + ], + 404 ); + } $vote = new Vote(); - $foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] ); + $foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] ); if ( ! $foundChoice ) { return $this->json( [ 'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found', @@ -474,6 +488,7 @@ class DefaultController extends AbstractController { return $this->json( [ 'message' => 'you created a vote stack' . $precision, + 'poll' => $poll, 'vote_stack' => $stack->display(), 'vote_count' => count( $poll->getStacksOfVotes() ), 'owner_modifier_token' => $foundOwner->getModifierToken(), From 4ff254d54adcaca3b65a1c577389b11b094596ef Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Thu, 23 Jan 2020 15:13:51 +0100 Subject: [PATCH 2/2] cration of poll up answers possible --- src/Controller/DefaultController.php | 14 ++++++++++++++ src/Entity/Poll.php | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index aee5a26..0cbbf24 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -162,6 +162,20 @@ class DefaultController extends AbstractController { $em->persist( $newpoll ); $em->persist( $foundOwner ); + // emails + $newpoll->setMailOnComment( true ); + $newpoll->setMailOnVote( true ); + $newpoll->setHideResults( false ); + // possible answers + $newpoll->setAllowedAnswers( [ 'yes' ] ); + if ( $data[ 'voteChoices' ] ) { + switch ( $data[ 'voteChoices' ] ) { + case "only_yes": + default: + + break; + } + } // setup the password, converting the raw with md5 hash if ( $data[ 'password' ] ) { $newpoll->setPassword( $data[ 'password' ] ); diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index b85501b..c1d1f8c 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -112,6 +112,7 @@ class Poll { public $showResultEvenIfPasswords; /** * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) + * @Serializer\Type("App\Entity\Vote") * @Serializer\Expose() */ public $votes; @@ -128,6 +129,7 @@ class Poll { /** * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) * @Serializer\Expose() + * @Serializer\Type("App\Entity\Comment") */ public $comments; /**