Added user avatars next to their chosen option

This commit is contained in:
aymm 2021-03-27 21:15:07 +01:00
parent 67c02f458c
commit 0448f995f7
Signed by: phlaym
GPG Key ID: A06651BAB6777237
3 changed files with 23 additions and 8 deletions

View File

@ -34,7 +34,7 @@ function get_page_header(
} }
$script_str = ''; $script_str = '';
foreach ($scripts as $script) { foreach ($scripts as $script) {
$script_str .= '<script src="scripts/' . $script . '.js">'; $script_str .= '<script src="scripts/' . $script . '.js"></script>';
} }
return '<html><head><meta charset="utf-8"><title>'.$title.'</title><link rel="stylesheet" href="styles/style.css">' return '<html><head><meta charset="utf-8"><title>'.$title.'</title><link rel="stylesheet" href="styles/style.css">'
. $script_str . $script_str

View File

@ -60,8 +60,6 @@ header {
} }
.poll .header { .poll .header {
/*display: flex;
align-items: center;*/
margin-bottom: 8px; margin-bottom: 8px;
} }
@ -89,3 +87,9 @@ header {
datewrapper time { datewrapper time {
grid-column: 2; grid-column: 2;
} }
.options {
display: grid;
grid-template-columns: auto 1fr;
grid-column-gap: 8px;
}

View File

@ -35,14 +35,14 @@ try {
. '<input type="hidden" name="id" value="'.$poll_id.'"><button type="submit">Access poll</button></form>' . '<input type="hidden" name="id" value="'.$poll_id.'"><button type="submit">Access poll</button></form>'
); );
} }
jslog($poll);
$user_avatar_url = $poll->user->getAvatarUrl(50); $user_avatar_url = $poll->user->getAvatarUrl(50);
$username = '@' . $poll->user->username; $username = '@' . $poll->user->username;
$disabled = $poll->canVote() ? '' : 'disabled'; $disabled = $poll->canVote() ? '' : 'disabled';
$user_name = $poll->user->name ?? ''; $user_name = $poll->user->name ?? '';
$created_at = $poll->created_at; $created_at = $poll->created_at;
$closed_at = $poll->closed_at; $closed_at = $poll->closed_at;
jslog('teyt');
?> ?>
<div class="poll"> <div class="poll">
<div class="header"> <div class="header">
@ -68,11 +68,22 @@ jslog('teyt');
</div> </div>
<div class="options"> <div class="options">
<?php <?php
$row = 1;
$user_args = [
'include_html' => false,
'include_counts' => false,
];
foreach ($poll->options as $option) { foreach ($poll->options as $option) {
$checked = $option->is_your_response ? 'checked' : ''; ?> $checked = $option->is_your_response ? 'checked' : ''; ?>
<div class="options"> <div class="option" style="grid-row: <?= $row ?>;">
<input type="checkbox" <?= $checked.' '.$disabled ?>/> <input type="checkbox" <?= $checked.' '.$disabled ?>/>
<span class="option-text"><?= $option->text ?></span> <span class="option-text"><?= $option->text . ' (' . $option->respondents . ')'?></span>
</div>
<div class="option-responses" style="grid-row: <?= $row++ ?>;grid-column: 2;">
<?php foreach ($option->respondent_ids as $res_id) {
$u = $api->getUser($res_id, $user_args); ?>
<img src="<?= $u->getAvatarUrl(20) ?>" class="avatar" title="@<?= $u->username ?>">
<?php } ?>
</div> </div>
<?php } ?> <?php } ?>
</div> </div>