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

display also empty votes in stacks

This commit is contained in:
Tykayn 2021-06-10 12:46:20 +02:00 committed by tykayn
parent fd28433dd8
commit 31c75f69b2
2 changed files with 20 additions and 3 deletions

View File

@ -179,7 +179,9 @@ class PollController extends EmailsController {
// wrong pass // wrong pass
return $this->json( [ return $this->json( [
'message' => 'this is protected by a password, your password hash "' . $md5 . '" is wrong, and you should feel bad', 'message' => 'this is protected by a password, your password hash "' . $md5 . '" is wrong, and you should feel bad',
// 'md5' => md5( $md5 ), 'pass' => $md5 ,
'md5' => md5( $md5 ),
'md5( $poll->getPassword() )' => md5( $poll->getPassword() ),
'data' => null, 'data' => null,
], ],
403 ); 403 );

View File

@ -59,15 +59,30 @@ class StackOfVotes {
public function display() { public function display() {
// fill all votes by choices
$choices = $this->getPoll()->getChoices();
$defaultVotes = [];
foreach ( $choices as $choice ) {
$defaultVotes[ $choice->getId() ] = [ "choice_id" => $choice->getId(), "value" => "" ];
}
$tab = [ $tab = [
'id' => $this->getId(), 'id' => $this->getId(),
'pseudo' => $this->getPseudo(), 'pseudo' => $this->getPseudo(),
'created_at' => $this->getCreatedAtAsString(), 'created_at' => $this->getCreatedAtAsString(),
'votes' => [], 'votes' => $defaultVotes,
]; ];
foreach ( $this->getVotes() as $vote ) { foreach ( $this->getVotes() as $vote ) {
$tab[ 'votes' ][] = $vote->display(); $tab[ 'votes' ][ $vote->getChoice()->getId() ] = $vote->display();
} }
// flatten the votes array
$flatVotes = [];
foreach ( $tab[ 'votes' ] as $vote ) {
$flatVotes[] = $vote;
}
$tab[ 'votes' ] = $flatVotes;
$tab[ 'owner' ] = $this->getOwner()->display(); $tab[ 'owner' ] = $this->getOwner()->display();
return $tab; return $tab;