function poll_page
7.x poll.pages.inc | poll_page() |
6.x 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 drupal-7.x/
modules/ poll/ poll.module - Implements hook_menu().
File
- drupal-7.x/
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;
}