annotate modules/poll/poll.pages.inc @ 8:85cbd6048071

Added tag 6.3 for changeset fff6d4c8c043
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:30:28 +0100
parents c1f4ac30525a
children
rev   line source
webmaster@1 1 <?php
webmaster@1 2 // $Id: poll.pages.inc,v 1.4 2007/12/14 09:50:41 goba Exp $
webmaster@1 3
webmaster@1 4 /**
webmaster@1 5 * @file
webmaster@1 6 * User page callbacks for the poll module.
webmaster@1 7 */
webmaster@1 8
webmaster@1 9 /**
webmaster@1 10 * Menu callback to provide a simple list of all polls available.
webmaster@1 11 */
webmaster@1 12 function poll_page() {
webmaster@1 13 // List all polls.
webmaster@1 14 $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");
webmaster@1 15 // Count all polls for the pager.
webmaster@1 16 $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid WHERE n.status = 1');
webmaster@1 17 $result = pager_query($sql, 15, 0, $count_sql);
webmaster@1 18 $output = '<ul>';
webmaster@1 19 while ($node = db_fetch_object($result)) {
webmaster@1 20 $output .= '<li>'. l($node->title, "node/$node->nid") .' - '. format_plural($node->votes, '1 vote', '@count votes') .' - '. ($node->active ? t('open') : t('closed')) .'</li>';
webmaster@1 21 }
webmaster@1 22 $output .= '</ul>';
webmaster@1 23 $output .= theme("pager", NULL, 15);
webmaster@1 24 return $output;
webmaster@1 25 }
webmaster@1 26
webmaster@1 27 /**
webmaster@1 28 * Callback for the 'votes' tab for polls you can see other votes on
webmaster@1 29 */
webmaster@1 30 function poll_votes($node) {
webmaster@1 31 drupal_set_title(check_plain($node->title));
webmaster@1 32 $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.');
webmaster@1 33
webmaster@1 34 $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
webmaster@1 35 $header[] = array('data' => t('Vote'), 'field' => 'pv.chorder');
webmaster@1 36
webmaster@1 37 $result = pager_query("SELECT pv.chorder, pv.uid, pv.hostname, u.name FROM {poll_votes} pv LEFT JOIN {users} u ON pv.uid = u.uid WHERE pv.nid = %d". tablesort_sql($header), 20, 0, NULL, $node->nid);
webmaster@1 38 $rows = array();
webmaster@1 39 while ($vote = db_fetch_object($result)) {
webmaster@1 40 $rows[] = array(
webmaster@1 41 $vote->name ? theme('username', $vote) : check_plain($vote->hostname),
webmaster@1 42 check_plain($node->choice[$vote->chorder]['chtext']));
webmaster@1 43 }
webmaster@1 44 $output .= theme('table', $header, $rows);
webmaster@1 45 $output .= theme('pager', NULL, 20, 0);
webmaster@1 46 return $output;
webmaster@1 47 }
webmaster@1 48
webmaster@1 49 /**
webmaster@1 50 * Callback for the 'results' tab for polls you can vote on
webmaster@1 51 */
webmaster@1 52 function poll_results($node) {
webmaster@1 53 drupal_set_title(check_plain($node->title));
webmaster@1 54 $node->show_results = TRUE;
webmaster@1 55 return node_show($node, 0);
webmaster@1 56 }