Browse Source
Allow to vote nothing
Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/7621/head
Joas Schilling
4 years ago
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205
2 changed files with
8 additions and
6 deletions
-
lib/Controller/PollController.php
-
lib/Service/PollService.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) { |
|
|
|
|
|
|
|
@ -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 = []; |
|
|
|
|