bug/undefined-offset-on-best-choices
This commit is contained in:
parent
5b4b8a8606
commit
c79b32984d
@ -435,7 +435,7 @@ $smarty->assign('deletion_date', strtotime($poll->end_date) + PURGE_DELAY * 8640
|
||||
$smarty->assign('slots', $poll->format === 'D' ? $pollService->splitSlots($slots) : $slots);
|
||||
$smarty->assign('slots_hash', $pollService->hashSlots($slots));
|
||||
$smarty->assign('votes', $pollService->splitVotes($votes));
|
||||
$smarty->assign('best_choices', $pollService->computeBestChoices($votes));
|
||||
$smarty->assign('best_choices', $pollService->computeBestChoices($votes, $poll));
|
||||
$smarty->assign('comments', $comments);
|
||||
$smarty->assign('editingVoteId', $editingVoteId);
|
||||
$smarty->assign('message', $message);
|
||||
|
@ -178,8 +178,36 @@ class PollService {
|
||||
return $this->pollRepository->findAllByAdminMail($mail);
|
||||
}
|
||||
|
||||
function computeBestChoices($votes) {
|
||||
$result = ['y' => [0], 'inb' => [0]];
|
||||
function computeBestChoices($votes, $poll) {
|
||||
$result = ['y' => [], 'inb' => []];
|
||||
|
||||
if (0 === count($votes)) {
|
||||
// if there is no votes, calculates the number of slot
|
||||
|
||||
$slots = $this->allSlotsByPoll($poll);
|
||||
|
||||
if ($poll->format === 'A') {
|
||||
// poll format classic
|
||||
|
||||
foreach ($slots as $slot) {
|
||||
$result['y'][] = 0;
|
||||
$result['inb'][] = 0;
|
||||
}
|
||||
} else {
|
||||
// poll format date
|
||||
|
||||
$slots = $this->splitSlots($slots);
|
||||
|
||||
foreach ($slots as $slot) {
|
||||
foreach ($slot->moments as $_) {
|
||||
$result['y'][] = 0;
|
||||
$result['inb'][] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if there is votes
|
||||
|
||||
foreach ($votes as $vote) {
|
||||
$choices = str_split($vote->choices);
|
||||
foreach ($choices as $i => $choice) {
|
||||
@ -195,6 +223,7 @@ class PollService {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -293,7 +322,7 @@ class PollService {
|
||||
if (count($votes) <= 0) {
|
||||
return;
|
||||
}
|
||||
$best_choices = $this->computeBestChoices($votes);
|
||||
$best_choices = $this->computeBestChoices($votes, $poll);
|
||||
foreach ($best_choices['y'] as $i => $nb_choice) {
|
||||
// if for this option we have reached maximum value and user wants to add itself too
|
||||
if ($poll->ValueMax !== null && $nb_choice >= $poll->ValueMax && $user_choice[$i] === "2") {
|
||||
|
@ -227,7 +227,7 @@ $smarty->assign('deletion_date', strtotime($poll->end_date) + PURGE_DELAY * 8640
|
||||
$smarty->assign('slots', $poll->format === 'D' ? $pollService->splitSlots($slots) : $slots);
|
||||
$smarty->assign('slots_hash', $pollService->hashSlots($slots));
|
||||
$smarty->assign('votes', $pollService->splitVotes($votes));
|
||||
$smarty->assign('best_choices', $pollService->computeBestChoices($votes));
|
||||
$smarty->assign('best_choices', $pollService->computeBestChoices($votes, $poll));
|
||||
$smarty->assign('comments', $comments);
|
||||
$smarty->assign('editingVoteId', $editingVoteId);
|
||||
$smarty->assign('message', $message);
|
||||
|
Loading…
Reference in New Issue
Block a user