Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-04-06 09:43:32 +02:00
parent 61ac8fcf76
commit 08f7ca141d
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -177,46 +177,12 @@ class PollService {
return $this->pollRepository->findAllByAdminMail($mail); return $this->pollRepository->findAllByAdminMail($mail);
} }
/**
* @param \stdClass $poll
* @return array
*/
private function computeEmptyBestChoices($poll)
{
$result = ['y' => [], 'inb' => []];
// if there is no votes, calculates the number of slot
$slots = $this->allSlotsByPoll($poll);
if ($poll->format === 'A') {
// poll format classic
for ($i = 0; $i < count($slots); $i++) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
} else {
// poll format date
$slots = $this->splitSlots($slots);
foreach ($slots as $slot) {
for ($i = 0; $i < count($slot->moments); $i++) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
}
}
return $result;
}
/** /**
* @param array $votes * @param array $votes
* @param \stdClass $poll * @param \stdClass $poll
* @return array * @return array
*/ */
public function computeBestChoices($votes, $poll) { public function computeBestChoices($votes, $poll) {
if (0 === count($votes)) { if (0 === count($votes)) {
return $this->computeEmptyBestChoices($poll); return $this->computeEmptyBestChoices($poll);
} }
@ -305,6 +271,39 @@ class PollService {
return $slots; return $slots;
} }
/**
* @param \stdClass $poll
* @return array
*/
private function computeEmptyBestChoices($poll)
{
$result = ['y' => [], 'inb' => []];
// if there is no votes, calculates the number of slot
$slots = $this->allSlotsByPoll($poll);
if ($poll->format === 'A') {
// poll format classic
for ($i = 0; $i < count($slots); $i++) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
} else {
// poll format date
$slots = $this->splitSlots($slots);
foreach ($slots as $slot) {
for ($i = 0; $i < count($slot->moments); $i++) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
}
}
return $result;
}
private function random($length) { private function random($length) {
return Token::getToken($length); return Token::getToken($length);
} }