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 = [];
$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

View File

@ -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();

View File

@ -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(),
];
}

View File

@ -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;