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
return $this->json( [
'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,
],
403 );

View File

@ -59,15 +59,30 @@ class StackOfVotes {
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 = [
'id' => $this->getId(),
'pseudo' => $this->getPseudo(),
'created_at' => $this->getCreatedAtAsString(),
'votes' => [],
'votes' => $defaultVotes,
];
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();
return $tab;