/** * @param array $formData * @param int $pollId * @param string $ipAddress * @param string $time * @return bool|int * @throws Core\Validation\Exceptions\ValidationRuleNotFoundException */ public function vote(array $formData, $pollId, $ipAddress, $time) { $answers = $formData['answer']; $bool = false; $userId = $this->userModel->isAuthenticated() ? $this->userModel->getUserId() : null; // Multiple Answers if (is_array($answers) === false) { $answers = [$answers]; } foreach ($answers as $answer) { if ($this->validator->is(IntegerValidationRule::class, $answer) === true) { $insertValues = ['poll_id' => $pollId, 'answer_id' => $answer, 'user_id' => $userId, 'ip' => $ipAddress, 'time' => $time]; $bool = $this->voteRepository->insert($insertValues); } } return $bool; }
/** * @inheritdoc */ public function validate(Validator $validator, $data, $field = '', array $extra = []) { if (!$this->isValid($data, $field, $extra)) { $validator->addError($this->getMessage(), $field); } }