Code coverage for /20081101/modules/poll/poll.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: poll.pages.inc,v 1.9 2008/10/13 00:33:03 webchick Exp $
3
4
/**
5
 * @file
6
 * User page callbacks for the poll module.
7
 */
8
9
/**
10
 * Menu callback to provide a simple list of all polls available.
11
 */
121
function poll_page() {
13
  // List all polls.
140
  $sql = db_rewrite_sql("SELECT n.nid, n.title, p.active, n.created,
SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid
INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE n.status = 1 GROUP BY
n.nid, n.title, p.active, n.created ORDER BY n.created DESC");
15
  // Count all polls for the pager.
160
  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n INNER JOIN
{poll} p ON n.nid = p.nid WHERE n.status = 1');
170
  $result = pager_query($sql, 15, 0, $count_sql);
180
  $output = '<ul>';
190
  while ($node = db_fetch_object($result)) {
200
    $output .= '<li>' . l($node->title, "node/$node->nid") . ' - ' .
format_plural($node->votes, '1 vote', '@count votes') . ' - ' .
($node->active ? t('open') : t('closed')) . '</li>';
210
  }
220
  $output .= '</ul>';
230
  $output .= theme("pager", NULL, 15);
240
  return $output;
250
}
26
27
/**
28
 * Callback for the 'votes' tab for polls you can see other votes on
29
 */
301
function poll_votes($node) {
311
  drupal_set_title($node->title);
321
  $output = t('This table lists all the recorded votes for this poll. If
anonymous users are allowed to vote, they will be identified by the IP
address of the computer they used when they voted.');
33
341
  $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
351
  $header[] = array('data' => t('Vote'), 'field' => 'pv.chorder');
361
  $header[] = array('data' => t('Vote'), 'field' => 'pc.weight');
37
381
  $result = pager_query("SELECT pv.chid, pv.uid, pv.hostname, u.name FROM
{poll_votes} pv INNER JOIN {poll_choices} pc ON pv.chid = pc.chid LEFT JOIN
{users} u ON pv.uid = u.uid WHERE pv.nid = %d". tablesort_sql($header), 20,
0, NULL, $node->nid);
391
  $rows = array();
401
  while ($vote = db_fetch_object($result)) {
411
    $rows[] = array(
421
      $vote->name ? theme('username', $vote) :
check_plain($vote->hostname),
431
      check_plain($node->choice[$vote->chid]['chtext']));
441
  }
451
  $output .= theme('table', $header, $rows);
461
  $output .= theme('pager', NULL, 20, 0);
471
  return $output;
480
}
49
50
/**
51
 * Callback for the 'results' tab for polls you can vote on
52
 */
531
function poll_results($node) {
540
  drupal_set_title($node->title);
550
  $node->show_results = TRUE;
560
  return node_show($node, 0);
570
}
581