Exemplo n.º 1
0
 public function bdApi_actionPostVotes(array $poll, bdApi_ControllerApi_Abstract $controller)
 {
     if (!$this->canVoteOnPoll($poll, $errorPhraseKey)) {
         throw $controller->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     $responseIds = $controller->getInput()->filterSingle('response_ids', XenForo_Input::UINT, array('array' => true));
     $responseId = $controller->getInput()->filterSingle('response_id', XenForo_Input::UINT);
     if ($responseId > 0) {
         $responseIds[] = $responseId;
         $responseIds = array_unique($responseIds);
     }
     if (empty($responseIds)) {
         if (!$responseIds) {
             return $controller->responseError(new XenForo_Phrase('bdapi_slash_poll_vote_requires_response_id'));
         }
     }
     if ($poll['max_votes'] > 0 && count($responseIds) > $poll['max_votes']) {
         return $controller->responseError(new XenForo_Phrase('you_may_select_up_to_x_choices', array('max' => $poll['max_votes'])));
     }
     if ($this->voteOnPoll($poll['poll_id'], $responseIds)) {
         return $controller->responseMessage(new XenForo_Phrase('changes_saved'));
     } else {
         return $controller->responseError(new XenForo_Phrase('unexpected_error_occurred'));
     }
 }