Moved poll functions to Poll class (#739)

This commit is contained in:
Roman Kelesidis 2023-05-29 22:57:10 +07:00 committed by GitHub
commit d2588855fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 43 deletions

View file

@ -1574,45 +1574,6 @@ function build_topic_pagination($url, $replies, $per_page)
return $pg;
}
//
// Poll
//
function get_poll_data_items_js($topic_id)
{
if (!$topic_id_csv = get_id_csv($topic_id)) {
return is_array($topic_id) ? array() : false;
}
$items = array();
if (!$poll_data = CACHE('bb_poll_data')->get("poll_$topic_id")) {
$poll_data = DB()->fetch_rowset("
SELECT topic_id, vote_id, vote_text, vote_result
FROM " . BB_POLL_VOTES . "
WHERE topic_id IN($topic_id_csv)
ORDER BY topic_id, vote_id
");
CACHE('bb_poll_data')->set("poll_$topic_id", $poll_data);
}
foreach ($poll_data as $row) {
$opt_text_for_js = htmlCHR($row['vote_text']);
$opt_result_for_js = (int)$row['vote_result'];
$items[$row['topic_id']][$row['vote_id']] = array($opt_text_for_js, $opt_result_for_js);
}
foreach ($items as $k => $v) {
$items[$k] = json_encode($v, JSON_THROW_ON_ERROR);
}
return is_array($topic_id) ? $items : $items[$topic_id];
}
function poll_is_active($t_data)
{
global $bb_cfg;
return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);
}
function print_confirmation($tpl_vars)
{
global $template, $lang;