mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ fill more data in response of a get poll config
This commit is contained in:
parent
585bdc9f19
commit
a98f830800
@ -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_count' => count( $poll->getStacksOfVotes() ),
|
||||
'stacks' => $stacks,
|
||||
'choices_count' => count( $choices ),
|
||||
'choices_count' => count( $poll->getChoices() ),
|
||||
'choices' => $choices,
|
||||
'comments' => $comments,
|
||||
'comments_count' => count( $comments ),
|
||||
];
|
||||
/**
|
||||
* password protected content
|
||||
|
@ -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();
|
||||
|
@ -49,9 +49,9 @@ class Comment {
|
||||
function display() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'poll' => $this->getPoll(),
|
||||
'text' => $this->getText(),
|
||||
'token' => $this->getOwner()->getModifierToken(),
|
||||
'pseudo' => $this->getOwner()->getPseudo(),
|
||||
'date' => $this->getCreatedAt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user