fill more data in response of a get poll config

This commit is contained in:
Baptiste Lemoine 2020-01-21 11:10:18 +01:00
parent 585bdc9f19
commit a98f830800
4 changed files with 34 additions and 26 deletions

View File

@ -226,31 +226,23 @@ class DefaultController extends AbstractController {
$stacks = []; $stacks = [];
$choices = []; $choices = [];
foreach ( $poll->getComments() as $c ) { foreach ( $poll->getComments() as $c ) {
$comments[] = [ $comments[ $c->getId() ] = $c->display();
'pseudo' => $c->getOwner()->getPseudo(),
'date' => $c->getCreatedAt(),
'text' => $c->getText(),
];
} }
foreach ( $poll->getStacksOfVotes() as $c ) { foreach ( $poll->getStacksOfVotes() as $c ) {
$stacks[] = $stacks[ $c->getId() ] = $c->display();
[
"id" => $c->getId(),
"pseudo" => $c->getOwner()->getPseudo(),
"votes" => $c->getVotes(),
];
} }
foreach ( $poll->getChoices() as $c ) { foreach ( $poll->getChoices() as $c ) {
$choices[] = $c; $choices[ $c->getId() ] = $c->display();
} }
$returnedPoll = [ $returnedPoll = [
'message' => 'your poll config', 'message' => 'your poll config',
'data' => $poll, 'data' => $poll,
'stacks_count' => count( $stacks ), 'stacks_count' => count( $poll->getStacksOfVotes() ),
'stacks' => $stacks, 'stacks' => $stacks,
'choices_count' => count( $choices ), 'choices_count' => count( $poll->getChoices() ),
'choices' => $choices, 'choices' => $choices,
'comments' => $comments, 'comments' => $comments,
'comments_count' => count( $comments ),
]; ];
/** /**
* password protected content * password protected content

View File

@ -46,6 +46,14 @@ class Choice {
*/ */
public $votes; public $votes;
public function display() {
return [
'id' => $this->getId(),
'date' => $this->getDateTime(),
'text' => $this->getName(),
];
}
public function __construct( $optionalName = null ) { public function __construct( $optionalName = null ) {
$this->poll = new ArrayCollection(); $this->poll = new ArrayCollection();
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();

View File

@ -48,10 +48,10 @@ class Comment {
function display() { function display() {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),
'poll' => $this->getPoll(), 'text' => $this->getText(),
'text' => $this->getText(), 'pseudo' => $this->getOwner()->getPseudo(),
'token' => $this->getOwner()->getModifierToken(), 'date' => $this->getCreatedAt(),
]; ];
} }

View File

@ -43,14 +43,22 @@ class StackOfVotes {
public function display() { public function display() {
$tab = []; $tab = [
'id' => $this->getId(),
'pseudo' => '',
'creation_date' => '',
'votes' => [],
];
foreach ( $this->getVotes() as $vote ) { foreach ( $this->getVotes() as $vote ) {
$tab[ $vote->getId() ] = [ $tab[ 'votes' ][ $vote->getId() ] = [
'id' => $vote->getId(), 'id' => $this->getId(),
'vote_id' => $vote->getId(),
'value' => $vote->getValue(), 'value' => $vote->getValue(),
'choice_id' => $vote->getChoice()->getId(), 'choice_id' => $vote->getChoice()->getId(),
'text' => $vote->getChoice()->getName(), 'text' => $vote->getChoice()->getName(),
]; ];
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
$tab[ 'creation_date' ] = $vote->getCreationDate();
} }
return $tab; return $tab;