mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
reorganize displays
This commit is contained in:
parent
dd1de88635
commit
7c1fbf7347
@ -101,18 +101,27 @@ class PollController extends EmailsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$comments = $poll->getComments();
|
$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();
|
$pass = $poll->getPassword();
|
||||||
|
|
||||||
$returnedPoll = [
|
$returnedPoll = [
|
||||||
'message' => 'your poll config for ' . $poll->getTitle(),
|
'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->display(),
|
||||||
'poll' => $poll,
|
// TODO do not render sub objects of owner, it returns too many thing
|
||||||
'stacks_count' => count( $poll->getStacksOfVotes() ),
|
'stacks_count' => count( $poll->getStacksOfVotes() ),
|
||||||
'stacks' => $poll->getStacksOfVotes(),
|
'stacks' => $displayedStackOfVotes,
|
||||||
'choices_count' => $poll->computeAnswers(),
|
'choices_count' => $poll->computeAnswers(),
|
||||||
'choices' => $poll->getChoices(),
|
'comments' => $displayedComments,
|
||||||
'comments' => $comments,
|
|
||||||
'comments_count' => count( $comments ),
|
'comments_count' => count( $comments ),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -129,8 +138,8 @@ class PollController extends EmailsController {
|
|||||||
} else {
|
} else {
|
||||||
// free access to poll
|
// free access to poll
|
||||||
// return $this->returnPollData( $poll, $serializer );
|
// return $this->returnPollData( $poll, $serializer );
|
||||||
// return $this->json($returnedPoll);
|
return $this->json($returnedPoll);
|
||||||
return $this->json($poll);
|
// return $this->json($poll);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'date' => $this->getDateTime(),
|
'date' => $this->getDateTime(),
|
||||||
'text' => $this->getName(),
|
'name' => $this->getName(),
|
||||||
'url' => $this->getUrl(),
|
'url' => $this->getUrl(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,8 @@ class Poll {
|
|||||||
|
|
||||||
public function display() {
|
public function display() {
|
||||||
return [
|
return [
|
||||||
'poll' => $this,
|
'config' => $this,
|
||||||
|
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||||
'answers' => $this->computeAnswers(),
|
'answers' => $this->computeAnswers(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class StackOfVotes {
|
|||||||
public function display() {
|
public function display() {
|
||||||
$tab = [
|
$tab = [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'modifier_token' => $this->getOwner()->getModifierToken(),
|
// 'modifier_token' => $this->getOwner()->getModifierToken(),
|
||||||
'pseudo' => '',
|
'pseudo' => '',
|
||||||
'creation_date' => '',
|
'creation_date' => '',
|
||||||
'votes' => [],
|
'votes' => [],
|
||||||
@ -55,13 +55,14 @@ class StackOfVotes {
|
|||||||
foreach ( $this->getPoll()->getChoices() as $choice ) {
|
foreach ( $this->getPoll()->getChoices() as $choice ) {
|
||||||
$tab[ 'votes' ][ $choice->getId() ] = [
|
$tab[ 'votes' ][ $choice->getId() ] = [
|
||||||
'choice_id' => $choice->getId(),
|
'choice_id' => $choice->getId(),
|
||||||
|
'name' => $choice->getName(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $this->getVotes() as $vote ) {
|
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[ 'votes' ][ $vote->getChoice()->getId() ][ 'stack_id' ] = $this->getId();
|
||||||
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
|
$tab[ 'pseudo' ] = $this->getPseudo();
|
||||||
$tab[ 'creation_date' ] = $vote->getCreationDate();
|
$tab[ 'creation_date' ] = $vote->getCreationDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user