/[drupal]/drupal/modules/poll/poll.pages.inc
ViewVC logotype

Contents of /drupal/modules/poll/poll.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.24 - (show annotations) (download) (as text)
Sun Nov 1 12:11:10 2009 UTC (3 weeks, 6 days ago) by dries
Branch: MAIN
Changes since 1.23: +3 -3 lines
File MIME type: text/x-php
- Patch #595084 by c960657: use type hinting for .
1 <?php
2 // $Id: poll.pages.inc,v 1.23 2009/10/16 19:06:24 dries 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 */
12 function poll_page() {
13 $polls_per_page = 15;
14
15 $count_select = db_select('node', 'n');
16 $count_select->addExpression('COUNT(*)', 'expression');
17 $count_select->join('poll', 'p', 'p.nid = n.nid');
18 $count_select->condition('n.status', 1);
19
20 // List all polls.
21 $select = db_select('node', 'n');
22 $select->join('poll', 'p', 'p.nid = n.nid');
23 $select->join('poll_choice', 'c', 'c.nid = n.nid');
24 $select->addExpression('SUM(c.chvotes)', 'votes');
25 $select = $select->fields('n', array('nid', 'title', 'created'))
26 ->fields('p', array('active'))
27 ->condition('n.status', 1)
28 ->orderBy('n.created', 'DESC')
29 ->groupBy('n.nid')
30 ->groupBy('n.title')
31 ->groupBy('p.active')
32 ->groupBy('n.created')
33 ->extend('PagerDefault')
34 ->limit($polls_per_page)
35 ->addTag('node_access');
36 $select->setCountQuery($count_select);
37 $queried_nodes = $select->execute()
38 ->fetchAllAssoc('nid');
39
40 $output = '<ul>';
41 foreach ($queried_nodes as $node) {
42 $output .= '<li>' . l($node->title, "node/$node->nid") . ' - ' . format_plural($node->votes, '1 vote', '@count votes') . ' - ' . ($node->active ? t('open') : t('closed')) . '</li>';
43 }
44 $output .= '</ul>';
45 $output .= theme("pager", array('tags' => NULL));
46 return $output;
47 }
48
49 /**
50 * Callback for the 'votes' tab for polls you can see other votes on
51 */
52 function poll_votes(stdClass $node) {
53 $votes_per_page = 20;
54 drupal_set_title($node->title[FIELD_LANGUAGE_NONE][0]['value']);
55
56 $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
57 $header[] = array('data' => t('Vote'), 'field' => 'pc.chtext');
58 $header[] = array('data' => t('Timestamp'), 'field' => 'pv.timestamp', 'sort' => 'desc');
59
60 $select = db_select('poll_vote', 'pv')->extend('PagerDefault')->extend('TableSort');
61 $select->join('poll_choice', 'pc', 'pv.chid = pc.chid');
62 $select->join('users', 'u', 'pv.uid = u.uid');
63 $queried_votes = $select
64 ->addTag('translatable')
65 ->fields('pv', array('chid', 'uid', 'hostname', 'timestamp', 'nid'))
66 ->fields('pc', array('chtext'))
67 ->fields('u', array('name'))
68 ->condition('pv.nid', $node->nid)
69 ->limit($votes_per_page)
70 ->orderByHeader($header)
71 ->execute();
72
73 $rows = array();
74 foreach ($queried_votes as $vote) {
75 $rows[] = array(
76 $vote->name ? theme('username', array('account' => $vote)) : check_plain($vote->hostname),
77 check_plain($vote->chtext),
78 format_date($vote->timestamp),
79 );
80 }
81 $build['poll_votes_table'] = array(
82 '#theme' => 'table',
83 '#header' => $header,
84 '#rows' => $rows,
85 '#prefix' => 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.'),
86 );
87 $build['poll_votes_pager'] = array('#theme' => 'pager');
88 return $build;
89 }
90
91 /**
92 * Callback for the 'results' tab for polls you can vote on
93 */
94 function poll_results(stdClass $node) {
95 drupal_set_title($node->title[FIELD_LANGUAGE_NONE][0]['value']);
96 $node->show_results = TRUE;
97 return node_show($node);
98 }

  ViewVC Help
Powered by ViewVC 1.1.2