fill missing ids in stacks
This commit is contained in:
parent
86fe1d5720
commit
58c28474f8
|
@ -161,19 +161,28 @@
|
|||
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
||||
if ( ! isset( $computedArray[ $vote->getChoice()->getId() ] ) ) {
|
||||
$computedArray[ $vote->getChoice()->getId() ] = [
|
||||
'yes' => 0,
|
||||
'maybe' => 0,
|
||||
'no' => 0,
|
||||
'yes' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
'maybe' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
'no' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ] ++;
|
||||
$people[ $stack_of_vote->getOwner()->getPseudo() ] = $vote->getValue();
|
||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'count' ] ++;
|
||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'counts' => $computedArray,
|
||||
'people' => $people,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,15 @@ class StackOfVotes {
|
|||
'creation_date' => '',
|
||||
'votes' => [],
|
||||
];
|
||||
// prefill votes with all choices ids
|
||||
foreach ( $this->getPoll()->getChoices() as $choice ) {
|
||||
$tab[ 'votes' ][ $choice->getId() ] = [
|
||||
'choice_id' => $choice->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ( $this->getVotes() as $vote ) {
|
||||
$tab[ 'votes' ][] = [
|
||||
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = [
|
||||
'id' => $this->getId(),
|
||||
'vote_id' => $vote->getId(),
|
||||
'value' => $vote->getValue(),
|
||||
|
|
Loading…
Reference in New Issue