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);
}
/**
* @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 \stdClass $poll
* @return array
*/
public function computeBestChoices($votes, $poll) {
if (0 === count($votes)) {
return $this->computeEmptyBestChoices($poll);
}
@ -305,6 +271,39 @@ class PollService {
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) {
return Token::getToken($length);
}