Basic polls display + UI work
This commit is contained in:
@ -9,17 +9,14 @@ use APnutI\Exceptions\NotAuthorizedException;
|
||||
use APnutI\Exceptions\PollAccessRestrictedException;
|
||||
use APnutI\Entities\Poll;
|
||||
|
||||
echo get_page_header('Poll', true, ['poll']);
|
||||
|
||||
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
|
||||
die('Invalid poll ID');
|
||||
}
|
||||
$poll_id = (int)$_GET['id'];
|
||||
$poll = null;
|
||||
|
||||
if ($api->isAuthenticated()) {
|
||||
$user = $api->getAuthorizedUser();
|
||||
echo 'Welcome ' . ($user->name ?? $user->username) . '<br>';
|
||||
}
|
||||
|
||||
try {
|
||||
$poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null;
|
||||
$poll = $api->getPoll($poll_id, $poll_token);
|
||||
@ -39,30 +36,45 @@ try {
|
||||
);
|
||||
}
|
||||
|
||||
#echo json_encode($poll);
|
||||
#$user_avatar_url = $api->getAvatarUrl($poll->user->id, 50);
|
||||
$user_avatar_url = $poll->user->getAvatarUrl(50);
|
||||
#$prompt = '@' . $poll->user->username . ' asks: ' . $poll->prompt;
|
||||
$username = '@' . $poll->user->username;
|
||||
#echo '<img src="'.$user_avatar_url.'"/>';
|
||||
#echo $prompt;
|
||||
$disabled = $poll->canVote() ? '' : 'disabled';
|
||||
$user_name = $poll->user->name ?? '';
|
||||
$created_at = $poll->created_at;
|
||||
$closed_at = $poll->closed_at;
|
||||
jslog('teyt');
|
||||
?>
|
||||
<div class="poll">
|
||||
<div class="header">
|
||||
<img src="<?= $user_avatar_url ?>" />
|
||||
<span class="username"><?= $username ?></span> asks:
|
||||
<span class="prompt"><?= $poll->prompt ?></span>
|
||||
<div class="options">
|
||||
<?php
|
||||
foreach ($poll->options as $option) {
|
||||
$checked = $option->is_your_response ? 'checked' : ''; ?>
|
||||
<div class="options">
|
||||
<input type="checkbox" <?= $checked.' '.$disabled ?>/>
|
||||
<span class="option-text"><?= $option->text ?></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="user">
|
||||
<img src="<?= $user_avatar_url ?>" class="avatar"/>
|
||||
<div class="usernames">
|
||||
<b><?= $user_name.'<br>' ?></b>
|
||||
<span class="username"><a href="http://pnut.io/<?= $username ?>"><?= $username ?></a></span>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="datewrapper">
|
||||
<span class="created_at">Created</span>
|
||||
<span class="closed_at"><?= $poll->isClosed() ? 'Closed' : 'Closing' ?></span>
|
||||
<time class="created_at" datetime="<?= $created_at->format(\DateTime::ISO8601) ?>">
|
||||
<?= $created_at->format('Y-m-d, H:i:s e') ?>
|
||||
</time>
|
||||
<time class="closed_at" datetime="<?= $closed_at->format(\DateTime::ISO8601) ?>">
|
||||
<?= $closed_at->format('Y-m-d, H:i:s e') ?>
|
||||
</time>
|
||||
</div>
|
||||
</div>
|
||||
<span class="prompt"><em><?= $poll->prompt ?></em></span>
|
||||
</div>
|
||||
<div class="options">
|
||||
<?php
|
||||
foreach ($poll->options as $option) {
|
||||
$checked = $option->is_your_response ? 'checked' : ''; ?>
|
||||
<div class="options">
|
||||
<input type="checkbox" <?= $checked.' '.$disabled ?>/>
|
||||
<span class="option-text"><?= $option->text ?></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?= json_encode($poll);?>
|
||||
|
||||
|
Reference in New Issue
Block a user