diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 9dd06dc..d81bd40 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -173,18 +173,36 @@ class DefaultController extends AbstractController { $pass = $poll->getPassword(); $data = $request->getContent(); $data = json_decode( $data, true ); + + $comments = []; + $stacks = []; + $choices = []; + foreach ( $poll->getComments() as $c ) { + $comments[] = $c; + } + foreach ( $poll->getStacksOfVotes() as $c ) { + $stacks[] = $c; + } + foreach ( $poll->getChoices() as $c ) { + $choices[] = $c; + } + $returnedPoll = [ + 'message' => 'your poll config', + 'data' => $poll, + 'stacks_count' => count( $stacks ), + 'stacks' => $stacks, + 'choices_count' => count( $choices ), + 'choices' => $choices, + 'comments' => $comments, + ]; /** * password protected content */ if ( $pass ) { if ( $pass == md5( $data[ 'password_input' ] ) ) { - return $this->json( [ - 'message' => 'your poll config', - 'data' => $poll, - 'stacks' => $poll->getStacksOfVotes(), - 'comments' => $poll->getComments(), - ], + return $this->json( + $returnedPoll, 200 ); } else { return $this->json( [ @@ -194,12 +212,9 @@ class DefaultController extends AbstractController { 403 ); } } else { - return $this->json( [ - 'message' => 'your poll config', - 'data' => $poll, - 'stacks' => $poll->getStacksOfVotes(), - 'comments' => $poll->getComments(), - ], + return $this->json( + $returnedPoll + , 200 ); } diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index 8db1eba..fa29519 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -19,7 +19,7 @@ class Choice { * @ORM\Column(type="integer") * @Serializer\Expose() */ - private $id; + public $id; /** * @ORM\Column(type="string", length=255, nullable=true) diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 01521c8..b85501b 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -112,25 +112,21 @@ 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; /** * @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\StackOfVotes") * @Serializer\Expose() */ public $stacksOfVotes; /** * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\Choice") * @Serializer\Expose() */ public $choices; /** * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\Comment") * @Serializer\Expose() */ public $comments;