Browse Source

Allow to vote nothing

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/7621/head
Joas Schilling 4 years ago
parent
commit
1dd2553ff7
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 2
      lib/Controller/PollController.php
  2. 12
      lib/Service/PollService.php

2
lib/Controller/PollController.php

@ -148,7 +148,7 @@ class PollController extends AEnvironmentAwareController {
* @param int[] $optionIds
* @return DataResponse
*/
public function votePoll(int $pollId, array $optionIds): DataResponse {
public function votePoll(int $pollId, array $optionIds = []): DataResponse {
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (\Exception $e) {

12
lib/Service/PollService.php

@ -138,11 +138,13 @@ class PollService {
throw new \OverflowException();
}
$maxOptionId = max(array_keys(json_decode($poll->getOptions(), true, 512, JSON_THROW_ON_ERROR)));
$maxVotedId = max($optionIds);
$minVotedId = min($optionIds);
if ($minVotedId < 0 || $maxVotedId > $maxOptionId) {
throw new \RangeException();
if (!empty($optionIds)) {
$maxOptionId = max(array_keys(json_decode($poll->getOptions(), true, 512, JSON_THROW_ON_ERROR)));
$maxVotedId = max($optionIds);
$minVotedId = min($optionIds);
if ($minVotedId < 0 || $maxVotedId > $maxOptionId) {
throw new \RangeException();
}
}
$votes = [];

Loading…
Cancel
Save