本文整理汇总了PHP中Poll::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::valid方法的具体用法?PHP Poll::valid怎么用?PHP Poll::valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Poll
<?php
require_once "init.php";
use Firebase\JWT\JWT;
$pollID = 0;
$outputMessage = ['error' => false, 'message' => ""];
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$pollID = $_GET['id'];
$poll = new Poll($database, $pollID);
if (!$poll->valid()) {
$outputMessage['error'] = true;
$outputMessage['message'] = "Poll does not exist";
$headersHandler->sendHeaderCode(404);
$headersHandler->sendJSONData($outputMessage);
die;
}
$poll->fetchOptions();
$options = $poll->getOptions();
$data = ['question' => $poll->getQuestion(), 'options' => array(), 'hasVoted' => false];
foreach ($options as $option) {
array_push($data['options'], ['name' => $option->getName(), 'amount' => $option->getAmount(), 'id' => $option->getID()]);
}
if ($headersHandler->isAuthenticated()) {
// if authenticated - send info if user has already voted ($poll->hasUserVoted)
$jwt = $headersHandler->getBearer();
$decodedJWT = JWT::decode($jwt, $secretKey, array('HS256'));
if ($decodedJWT) {
$decodedArray = (array) $decodedJWT;
$hasVoted = $poll->hasUserVoted($decodedArray['id']);
if ($hasVoted) {
$data['hasVoted'] = $hasVoted->getID();