/** * Vote for an item * * @return void */ public function voteTask() { $no_html = Request::getInt('no_html', 0); $id = Request::getInt('id', 0); $vote = Request::getInt('vote', 0); // Login required if (User::isGuest()) { if (!$no_html) { $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN_TO_VOTE')); $this->loginTask(); } return; } // Load the question $row = new Question($id); // Record the vote if (!$row->vote($vote)) { if ($no_html) { $response = new \stdClass(); $response->success = false; $response->message = $row->getError(); echo json_encode($response); return; } else { App::redirect(Route::url($row->link()), $row->getError(), 'warning'); return; } } // Update display if ($no_html) { $this->qid = $id; $this->view->question = $row; $this->view->voted = $vote; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); } else { App::redirect(Route::url($row->link())); } }