You are here

function advpoll_display_results in Advanced Poll 7.2

Same name and namespace in other branches
  1. 7.3 advpoll.module \advpoll_display_results()
  2. 7 advpoll.module \advpoll_display_results()
4 calls to advpoll_display_results()
advpoll_form_submit in ./advpoll.module
Submit handler for voting
advpoll_node_view in ./advpoll.module
Implements hook_node_view().
advpoll_ranking_results_page in advpoll_ranking/advpoll_ranking.module
advpoll_results_page in includes/advpoll.pages.inc

File

./advpoll.module, line 401

Code

function advpoll_display_results($nid, $data) {
  $output = '';
  $form = NULL;
  if (user_access('cancel own vote') && advpoll_get_user_votes($nid)) {
    $form = drupal_get_form('advpoll_cancel_vote_form', $nid);
  }
  $rendered_form = drupal_render($form);

  // 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('administer polls') && ($data->show_results == 'never' || $data->show_results == 'afterclose' && $data->end_date > time())) {
    $output .= theme('advpoll_noresults', array(
      'data' => $data,
      'votes' => $votes,
      'nid' => $nid,
      'cancel_form' => $rendered_form,
    ));
  }
  else {
    $results = advpoll_get_votes($nid, $data->behavior);
    $bars = '';
    $final = advpoll_update_choices($data->choices, $results['choices']);
    foreach ($final as $item) {
      $voted = FALSE;
      if (in_array($item['tag'], $votes)) {
        $voted = TRUE;
      }
      $bars .= theme('advpoll_bar', array(
        'title' => $item['title'],
        'percentage' => $item['percentage'],
        'votes' => $item['votes'],
        'voted' => $voted,
      ));
    }
    $output .= theme('advpoll_results', array(
      'bars' => $bars,
      'total' => $results['total'],
      'voted' => $votes,
      'nid' => $nid,
      'cancel_form' => $rendered_form,
    ));
  }
  return $output;
}