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 = [];
|
$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
|
||||||
|
@ -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();
|
||||||
|
@ -49,9 +49,9 @@ class Comment {
|
|||||||
function display() {
|
function display() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'poll' => $this->getPoll(),
|
|
||||||
'text' => $this->getText(),
|
'text' => $this->getText(),
|
||||||
'token' => $this->getOwner()->getModifierToken(),
|
'pseudo' => $this->getOwner()->getPseudo(),
|
||||||
|
'date' => $this->getCreatedAt(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user