diff --git a/lib/Model/Poll.php b/lib/Model/Poll.php index 9f0679e88d2..917a27f7262 100644 --- a/lib/Model/Poll.php +++ b/lib/Model/Poll.php @@ -157,7 +157,11 @@ public function setOptions(array $options): void { throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); } - $this->options = $jsonOptions; + $this->setter('options', [$jsonOptions]); + } + + public function getOptions(): string { + return $this->options; } /** @@ -166,11 +170,16 @@ public function setOptions(array $options): void { * @throws PollPropertyException */ public function setQuestion(string $question): void { + nvlog($question); $question = trim($question); if ($question === '' || strlen($question) > 32_000) { throw new PollPropertyException(PollPropertyException::REASON_QUESTION); } - $this->question = $question; + $this->setter('question', [$question]); + } + + public function getQuestion(): string { + return $this->question; } } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 3a122fc09a7..90bc5ea1dc5 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -85,48 +85,6 @@ public function updatePoll(Participant $participant, Poll $poll): void { $this->pollMapper->update($poll); } - /** - * @param array $options - * @return string - * - * @since 21.0.0 - */ - public function validatePollOptions(array $options): string { - try { - json_encode($options, JSON_THROW_ON_ERROR, 1); - } catch (\Exception) { - throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); - } - - $validOptions = []; - foreach ($options as $option) { - if (!is_string($option)) { - throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); - } - - $option = trim($option); - if ($option !== '') { - $validOptions[] = $option; - } - } - - if (count($validOptions) < 2) { - throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); - } - - try { - $jsonOptions = json_encode($validOptions, JSON_THROW_ON_ERROR, 1); - } catch (\Exception) { - throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); - } - - if (strlen($jsonOptions) > 60_000) { - throw new PollPropertyException(PollPropertyException::REASON_OPTIONS); - } - - return $jsonOptions; - } - /** * @param Participant $participant * @param Poll $poll @@ -366,16 +324,4 @@ public function neutralizeDeletedUser(string $actorType, string $actorId): void ->andWhere($update->expr()->eq('actor_id', $update->createNamedParameter($actorId))); $update->executeStatement(); } - - /** - * @param string $question - * @return string - */ - public function validatePollQuestion(string $question): string { - $question = trim($question); - if ($question === '' || strlen($question) > 32_000) { - throw new PollPropertyException(PollPropertyException::REASON_QUESTION); - } - return $question; - } }