From 7c1fbf7347e8741a2862a10b2a588ed39fe98fe1 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 26 Apr 2021 15:14:25 +0200 Subject: [PATCH] reorganize displays --- src/Controller/api/PollController.php | 25 +++++++++++++++++-------- src/Entity/Choice.php | 2 +- src/Entity/Poll.php | 3 ++- src/Entity/StackOfVotes.php | 7 ++++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Controller/api/PollController.php b/src/Controller/api/PollController.php index d56e61e..f9cf1b6 100644 --- a/src/Controller/api/PollController.php +++ b/src/Controller/api/PollController.php @@ -101,18 +101,27 @@ class PollController extends EmailsController { } $comments = $poll->getComments(); + $stacks = $poll->getStacksOfVotes(); + + $displayedComments = []; + foreach ( $comments as $comment ) { + $displayedComments[] = $comment->display(); + } + $displayedStackOfVotes = []; + foreach ( $stacks as $stack ) { + $displayedStackOfVotes[] = $stack->display(); + } $pass = $poll->getPassword(); $returnedPoll = [ 'message' => 'your poll config for ' . $poll->getTitle(), - 'password_protected' => $pass ? 'yes' : 'no', - // TODO do not render sub objects of owner, it returns too many things - 'poll' => $poll, + + 'poll' => $poll->display(), + // TODO do not render sub objects of owner, it returns too many thing 'stacks_count' => count( $poll->getStacksOfVotes() ), - 'stacks' => $poll->getStacksOfVotes(), + 'stacks' => $displayedStackOfVotes, 'choices_count' => $poll->computeAnswers(), - 'choices' => $poll->getChoices(), - 'comments' => $comments, + 'comments' => $displayedComments, 'comments_count' => count( $comments ), ]; @@ -129,8 +138,8 @@ class PollController extends EmailsController { } else { // free access to poll // return $this->returnPollData( $poll, $serializer ); -// return $this->json($returnedPoll); - return $this->json($poll); + return $this->json($returnedPoll); +// return $this->json($poll); } } diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index ce2a0fc..cdff507 100755 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -66,7 +66,7 @@ return [ 'id' => $this->getId(), 'date' => $this->getDateTime(), - 'text' => $this->getName(), + 'name' => $this->getName(), 'url' => $this->getUrl(), ]; } diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 355ad96..86f5e99 100755 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -241,7 +241,8 @@ class Poll { public function display() { return [ - 'poll' => $this, + 'config' => $this, + 'password_protected' => $this->getPassword() ? 'yes' : 'no', 'answers' => $this->computeAnswers(), ]; } diff --git a/src/Entity/StackOfVotes.php b/src/Entity/StackOfVotes.php index 2916446..1bba295 100755 --- a/src/Entity/StackOfVotes.php +++ b/src/Entity/StackOfVotes.php @@ -46,7 +46,7 @@ class StackOfVotes { public function display() { $tab = [ 'id' => $this->getId(), - 'modifier_token' => $this->getOwner()->getModifierToken(), +// 'modifier_token' => $this->getOwner()->getModifierToken(), 'pseudo' => '', 'creation_date' => '', 'votes' => [], @@ -55,13 +55,14 @@ class StackOfVotes { foreach ( $this->getPoll()->getChoices() as $choice ) { $tab[ 'votes' ][ $choice->getId() ] = [ 'choice_id' => $choice->getId(), + 'name' => $choice->getName(), ]; } foreach ( $this->getVotes() as $vote ) { - $tab[ 'votes' ][ $vote->getChoice()->getId() ] = $vote->display(); +// $tab[ 'votes' ][ $vote->getChoice()->getId() ] = $vote->display(); $tab[ 'votes' ][ $vote->getChoice()->getId() ][ 'stack_id' ] = $this->getId(); - $tab[ 'pseudo' ] = $this->getOwner()->getPseudo(); + $tab[ 'pseudo' ] = $this->getPseudo(); $tab[ 'creation_date' ] = $vote->getCreationDate(); }