poll_view_results

Versions
4.6 – 6
poll_view_results(&$node, $teaser, $page, $block)
7
poll_view_results($node, $build_mode, $block = FALSE)

Generates a graphical representation of the results of a poll.

Code

modules/poll.module, line 327

<?php
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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.