public function vote($pollId, $choise)
{
if ($choise < 0 || $choise > 19 && $choise != 255) {
throw new Exception(L::get("POLLS_ILLEGAL_CHOISE"), 412);
}
$sth = $this->db->prepare("SELECT COUNT(*) FROM `pollanswers` WHERE `userid` = ? AND `pollid` = ?");
$sth->bindValue(1, $this->user->getId(), PDO::PARAM_INT);
$sth->bindParam(2, $pollId, PDO::PARAM_INT);
$sth->execute();
$res = $sth->fetch();
if ($res[0] == 1) {
throw new Exception(L::get("POLLS_ALREADY_VOTED"), 409);
}
$sth = $this->db->prepare("INSERT INTO pollanswers(pollid, userid, selection, class, alder) VALUES(?, ?, ?, ?, ?)");
$sth->bindParam(1, $pollId, PDO::PARAM_INT);
$sth->bindValue(2, $this->user->getId(), PDO::PARAM_INT);
$sth->bindParam(3, $choise, PDO::PARAM_INT);
$sth->bindValue(4, $this->user->getClass(), PDO::PARAM_INT);
$sth->bindValue(5, $this->user->getAge(), PDO::PARAM_INT);
$sth->execute();
}
break; case validateRoute('DELETE', 'faq/\\d+'): $faq = new Faq($db, $user); httpResponse($faq->delete($params[1])); break; case validateRoute('GET', 'polls'): $polls = new Polls($db, $user); httpResponse($polls->query()); break; case validateRoute('GET', 'polls/latest'): $polls = new Polls($db, $user); httpResponse($polls->getLatest()); break; case validateRoute('POST', 'polls/votes/\\d+'): $polls = new Polls($db, $user); httpResponse($polls->vote($params[2], (int) $postdata["choise"])); break; case validateRoute('POST', 'polls'): $forum = new Forum($db, $user); $polls = new Polls($db, $user, $forum); $polls->create($postdata); httpResponse(); break; case validateRoute('PATCH', 'polls/\\d+'): $polls = new Polls($db, $user); $polls->update($params[1], $postdata); httpResponse(); break; case validateRoute('DELETE', 'polls/\\d+'): $polls = new Polls($db, $user); $polls->delete($params[1], $postdata);