function poll_page in Drupal 7
Same name and namespace in other branches
- 4 modules/poll.module \poll_page()
- 5 modules/poll/poll.module \poll_page()
- 6 modules/poll/poll.pages.inc \poll_page()
Menu callback to provide a simple list of all polls available.
1 string reference to 'poll_page'
- poll_menu in modules/
poll/ poll.module - Implements hook_menu().
File
- modules/
poll/ poll.pages.inc, line 11 - User page callbacks for the poll module.
Code
function poll_page() {
$polls_per_page = 15;
$count_select = db_select('node', 'n');
$count_select
->addExpression('COUNT(*)', 'expression');
$count_select
->join('poll', 'p', 'p.nid = n.nid');
$count_select
->condition('n.status', 1);
// List all polls.
$select = db_select('node', 'n');
$select
->join('poll', 'p', 'p.nid = n.nid');
$select
->join('poll_choice', 'c', 'c.nid = n.nid');
$select
->addExpression('SUM(c.chvotes)', 'votes');
$select = $select
->fields('n', array(
'nid',
'title',
'created',
))
->fields('p', array(
'active',
))
->condition('n.status', 1)
->orderBy('n.created', 'DESC')
->groupBy('n.nid')
->groupBy('n.title')
->groupBy('p.active')
->groupBy('n.created')
->extend('PagerDefault')
->limit($polls_per_page)
->addTag('node_access');
$select
->setCountQuery($count_select);
$queried_nodes = $select
->execute()
->fetchAllAssoc('nid');
$output = '<ul>';
foreach ($queried_nodes as $node) {
$output .= '<li>' . l($node->title, "node/{$node->nid}") . ' - ' . format_plural($node->votes, '1 vote', '@count votes') . ' - ' . ($node->active ? t('open') : t('closed')) . '</li>';
}
$output .= '</ul>';
$output .= theme('pager');
return $output;
}