diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index c4f10d6..93d9414 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -226,31 +226,23 @@ class DefaultController extends AbstractController { $stacks = []; $choices = []; foreach ( $poll->getComments() as $c ) { - $comments[] = [ - 'pseudo' => $c->getOwner()->getPseudo(), - 'date' => $c->getCreatedAt(), - 'text' => $c->getText(), - ]; + $comments[ $c->getId() ] = $c->display(); } foreach ( $poll->getStacksOfVotes() as $c ) { - $stacks[] = - [ - "id" => $c->getId(), - "pseudo" => $c->getOwner()->getPseudo(), - "votes" => $c->getVotes(), - ]; + $stacks[ $c->getId() ] = $c->display(); } foreach ( $poll->getChoices() as $c ) { - $choices[] = $c; + $choices[ $c->getId() ] = $c->display(); } $returnedPoll = [ - 'message' => 'your poll config', - 'data' => $poll, - 'stacks_count' => count( $stacks ), - 'stacks' => $stacks, - 'choices_count' => count( $choices ), - 'choices' => $choices, - 'comments' => $comments, + 'message' => 'your poll config', + 'data' => $poll, + 'stacks_count' => count( $poll->getStacksOfVotes() ), + 'stacks' => $stacks, + 'choices_count' => count( $poll->getChoices() ), + 'choices' => $choices, + 'comments' => $comments, + 'comments_count' => count( $comments ), ]; /** * password protected content diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index fa29519..81da4ed 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -46,6 +46,14 @@ class Choice { */ public $votes; + public function display() { + return [ + 'id' => $this->getId(), + 'date' => $this->getDateTime(), + 'text' => $this->getName(), + ]; + } + public function __construct( $optionalName = null ) { $this->poll = new ArrayCollection(); $this->votes = new ArrayCollection(); diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 02e5cd0..ee0a3e5 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -48,10 +48,10 @@ class Comment { function display() { return [ - 'id' => $this->getId(), - 'poll' => $this->getPoll(), - 'text' => $this->getText(), - 'token' => $this->getOwner()->getModifierToken(), + 'id' => $this->getId(), + 'text' => $this->getText(), + 'pseudo' => $this->getOwner()->getPseudo(), + 'date' => $this->getCreatedAt(), ]; } diff --git a/src/Entity/StackOfVotes.php b/src/Entity/StackOfVotes.php index 98c752f..67d56d3 100644 --- a/src/Entity/StackOfVotes.php +++ b/src/Entity/StackOfVotes.php @@ -43,14 +43,22 @@ class StackOfVotes { public function display() { - $tab = []; + $tab = [ + 'id' => $this->getId(), + 'pseudo' => '', + 'creation_date' => '', + 'votes' => [], + ]; foreach ( $this->getVotes() as $vote ) { - $tab[ $vote->getId() ] = [ - 'id' => $vote->getId(), + $tab[ 'votes' ][ $vote->getId() ] = [ + 'id' => $this->getId(), + 'vote_id' => $vote->getId(), 'value' => $vote->getValue(), 'choice_id' => $vote->getChoice()->getId(), 'text' => $vote->getChoice()->getName(), ]; + $tab[ 'pseudo' ] = $this->getOwner()->getPseudo(); + $tab[ 'creation_date' ] = $vote->getCreationDate(); } return $tab;