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 ) {
|
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
||||||
if ( ! isset( $computedArray[ $vote->getChoice()->getId() ] ) ) {
|
if ( ! isset( $computedArray[ $vote->getChoice()->getId() ] ) ) {
|
||||||
$computedArray[ $vote->getChoice()->getId() ] = [
|
$computedArray[ $vote->getChoice()->getId() ] = [
|
||||||
'yes' => 0,
|
'yes' => [
|
||||||
'maybe' => 0,
|
'count' => 0,
|
||||||
'no' => 0,
|
'people' => [],
|
||||||
|
],
|
||||||
|
'maybe' => [
|
||||||
|
'count' => 0,
|
||||||
|
'people' => [],
|
||||||
|
],
|
||||||
|
'no' => [
|
||||||
|
'count' => 0,
|
||||||
|
'people' => [],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ] ++;
|
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'count' ] ++;
|
||||||
$people[ $stack_of_vote->getOwner()->getPseudo() ] = $vote->getValue();
|
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'counts' => $computedArray,
|
'counts' => $computedArray,
|
||||||
'people' => $people,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,15 @@ class StackOfVotes {
|
||||||
'creation_date' => '',
|
'creation_date' => '',
|
||||||
'votes' => [],
|
'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 ) {
|
foreach ( $this->getVotes() as $vote ) {
|
||||||
$tab[ 'votes' ][] = [
|
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'vote_id' => $vote->getId(),
|
'vote_id' => $vote->getId(),
|
||||||
'value' => $vote->getValue(),
|
'value' => $vote->getValue(),
|
||||||
|
|
Loading…
Reference in New Issue