1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
1d72bfe684 enrich display config of a poll 2021-04-26 15:21:19 +02:00
7c1fbf7347 reorganize displays 2021-04-26 15:14:25 +02:00
4 changed files with 32 additions and 19 deletions

View File

@ -101,19 +101,31 @@ class PollController extends EmailsController {
}
$comments = $poll->getComments();
$pass = $poll->getPassword();
$stacks = $poll->getStacksOfVotes();
$displayedComments = [];
foreach ( $comments as $comment ) {
$displayedComments[] = $comment->display();
}
$displayedStackOfVotes = [];
foreach ( $stacks as $stack ) {
$displayedStackOfVotes[] = $stack->display();
}
$displayedChoices = [];
foreach ( $poll->getChoices() as $choice
) {
$displayedChoices[] = $choice->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,
'stacks_count' => count( $poll->getStacksOfVotes() ),
'stacks' => $poll->getStacksOfVotes(),
'choices_count' => $poll->computeAnswers(),
'choices' => $poll->getChoices(),
'comments' => $comments,
'comments_count' => count( $comments ),
'message' => 'your poll config for ' . $poll->getTitle(),
'poll' => $poll->display(),
// TODO do not render sub objects of owner, it returns too many thing
'stacks' => $displayedStackOfVotes,
'choices' => $displayedChoices,
'comments' => $displayedComments,
];
/**
@ -129,8 +141,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);
}
}

View File

@ -66,7 +66,7 @@
return [
'id' => $this->getId(),
'date' => $this->getDateTime(),
'text' => $this->getName(),
'name' => $this->getName(),
'url' => $this->getUrl(),
];
}

View File

@ -232,7 +232,6 @@ class Poll {
}
}
}
return [
'counts' => $computedArray,
'maxScore' => $maxScore,
@ -241,7 +240,8 @@ class Poll {
public function display() {
return [
'poll' => $this,
'config' => $this,
'password_protected' => $this->getPassword() ? 'yes' : 'no',
'answers' => $this->computeAnswers(),
];
}

View File

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