function advpoll_display_borda_results in Advanced Poll 7.3
Same name and namespace in other branches
- 7 advpoll_ranking/advpoll_ranking.module \advpoll_display_borda_results()
- 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_display_borda_results()
Determines how to theme poll results based on settings in $data.
Borda display differs in that items that have the same values are grouped into one 'bar' display.
Parameters
$nid: Node id of the poll.
$data: Data from the node formatted by one of the helper functions in the advpoll_helper.inc document.
$page: A boolean value that indicates whether the request is to be displayed normally (0) or on the results page (1).
Return value
The appropriate borda poll markup.
4 calls to advpoll_display_borda_results()
- advpoll_draggable_submit in advpoll_ranking/
advpoll_ranking.module - Submit handler for ranking polls.
- advpoll_ranking_node_view in advpoll_ranking/
advpoll_ranking.module - Implements hook_node_view().
- advpoll_ranking_results_page in advpoll_ranking/
advpoll_ranking.module - Determines how to display the votes based on its type.
- advpoll_ranking_submit in advpoll_ranking/
advpoll_ranking.module - Submit handler for ranking polls.
File
- advpoll_ranking/
advpoll_ranking.module, line 736
Code
function advpoll_display_borda_results($nid, $data, $page = 0) {
$output = '';
$form = NULL;
$expired = FALSE;
if ($data->start_date && $data->start_date > time() || $data->end_date && $data->end_date < time() || $data->state == 'close') {
$expired = TRUE;
}
// Get user's votes if they're logged in and if voting is normal.
$votes = array();
if ($data->mode == 'normal') {
$votes = advpoll_get_user_votes($nid);
}
if (user_access('cancel own vote') && $votes && !$expired) {
$form = drupal_get_form('advpoll_ranking_cancel_form', $nid);
}
$rendered_form = drupal_render($form);
if (!$page && !$votes && $data->electoral && ($data->show_results == 'afterclose' || $data->show_results == 'never') && !$expired) {
$output .= theme('advpoll_ineligible', array(
'data' => $data,
));
}
elseif (!$page && ($data->show_results == 'never' || $data->show_results == 'afterclose' && !$expired)) {
$output .= theme('advpoll_noresults', array(
'data' => $data,
'votes' => $votes,
'nid' => $nid,
'cancel_form' => $rendered_form,
));
}
else {
$results = advpoll_get_votes($nid, $data);
$bars = '';
$final = advpoll_update_choices($data->choices, $results['choices']);
$reordered = array();
foreach ($final as $item) {
$title = $item['title'];
$show_bar = TRUE;
if ($item['write_in']) {
$title .= ' ' . t('(Write in)');
$show_bar = _advpoll_show_writeins_access();
}
if ($show_bar) {
$voted = FALSE;
if (in_array($item['tag'], $votes)) {
$voted = TRUE;
}
if (!isset($reordered[$item['percentage']])) {
$reordered[$item['percentage']] = array();
}
$reordered[$item['percentage']][] = array(
'title' => $title,
'votes' => $item['votes'],
'voted' => $voted,
);
}
}
foreach ($reordered as $key => $candidates) {
$titles = array();
foreach ($candidates as $candidate) {
$class = $candidate['voted'] ? 'voted' : 'not-voted';
$titles[] = '<span class="' . $class . '">' . $candidate['title'] . '</span>';
}
$bars .= theme('advpoll_borda_bar', array(
'title' => implode(', ', $titles),
'percentage' => $key,
'votes' => isset($candidate['votes']) ? $candidate['votes'] : 0,
));
}
$output .= theme('advpoll_results', array(
'bars' => $bars,
'total' => $results['total'],
'voted' => $votes,
'nid' => $nid,
'cancel_form' => $rendered_form,
));
}
return $output;
}