4.6.x poll.module poll_view_results(&$node, $teaser, $page, $block)
4.7.x poll.module poll_view_results(&$node, $teaser, $page, $block)
5.x poll.module poll_view_results(&$node, $teaser, $page, $block)
6.x poll.module poll_view_results(&$node, $teaser, $page, $block)
7.x poll.module poll_view_results($node, $view_mode, $block = FALSE)

Generates a graphical representation of the results of a poll.

2 calls to poll_view_results()
poll_block_latest_poll_view in modules/poll/poll.module
Return content for 'latest poll' block.
poll_view in modules/poll/poll.module
Implements hook_view().
5 string references to 'poll_view_results'
FieldUpdatePathTestCase::testFilledUpgrade in modules/simpletest/tests/upgrade/update.field.test
Tests that the update is successful.
hook_field_extra_fields in modules/field/field.api.php
Exposes "pseudo-field" components on fieldable entities.
poll_block_latest_poll_view in modules/poll/poll.module
Return content for 'latest poll' block.
poll_field_extra_fields in modules/poll/poll.module
Implements hook_field_extra_fields().
poll_view in modules/poll/poll.module
Implements hook_view().

File

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

Code

function poll_view_results($node, $view_mode, $block = FALSE) {
  // Make sure that choices are ordered by their weight.
  uasort($node->choice, 'drupal_sort_weight');

  // Count the votes and find the maximum.
  $total_votes = 0;
  $max_votes = 0;
  foreach ($node->choice as $choice) {
    if (isset($choice['chvotes'])) {
      $total_votes += $choice['chvotes'];
      $max_votes = max($max_votes, $choice['chvotes']);
    }
  }

  $poll_results = '';
  foreach ($node->choice as $i => $choice) {
    if (!empty($choice['chtext'])) {
      $chvotes = isset($choice['chvotes']) ? $choice['chvotes'] : NULL;
      $poll_results .= theme('poll_bar', array('title' => $choice['chtext'], 'votes' => $chvotes, 'total_votes' => $total_votes, 'vote' => isset($node->vote) && $node->vote == $i, 'block' => $block));
    }
  }

  return theme('poll_results', array('raw_title' => $node->title, 'results' => $poll_results, 'votes' => $total_votes, 'raw_links' => isset($node->links) ? $node->links : array(), 'block' => $block, 'nid' => $node->nid, 'vote' => isset($node->vote) ? $node->vote : NULL));
}