You are here

function advpoll_display_results in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 advpoll.module \advpoll_display_results()
  2. 7.2 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 366

Code

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

  // 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 ($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' => $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' => $form,
    ));
  }
  return $output;
}