Same name and namespace in other branches
  1. 4.7.x modules/poll.module \poll_view_results()
  2. 5.x modules/poll/poll.module \poll_view_results()
  3. 6.x modules/poll/poll.module \poll_view_results()
  4. 7.x modules/poll/poll.module \poll_view_results()

Generates a graphical representation of the results of a poll.

File

modules/poll.module, line 327
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_view_results(&$node, $teaser, $page, $block) {

  // Display the results
  // Count the votes and find the maximum
  foreach ($node->choice as $choice) {
    $votestotal += $choice['chvotes'];
    $votesmax = max($votesmax, $choice['chvotes']);
  }

  // Output the divs for the text, bars and percentages
  $output .= '<div class="poll">';
  if ($block) {
    $output .= '<div class="title">' . check_plain($node->title) . '</div>';
  }
  foreach ($node->choice as $i => $choice) {
    if ($choice['chtext'] != '') {
      $percentage = round($choice['chvotes'] * 100 / max($votestotal, 1));
      $output .= '<div class="text">' . check_plain($choice['chtext']) . '</div>';
      $output .= '<div class="bar">';
      $output .= '<div style="width: ' . $percentage . '%;" class="foreground"></div>';
      $output .= '</div>';
      $output .= '<div class="percent">' . $percentage . '%' . (!$block ? ' (' . format_plural($choice['chvotes'], '1 vote', '%count votes') . ')' : '') . '</div>';
    }
  }
  $output .= '<div class="total">' . t('Total votes') . ": {$votestotal}</div>";
  $output .= '</div>';
  return $output;
}