function poll_block in Drupal 5
Same name and namespace in other branches
- 4 modules/poll.module \poll_block()
- 6 modules/poll/poll.module \poll_block()
Implementation of hook_block().
Generates a block containing the latest poll.
File
- modules/
poll/ poll.module, line 36 - Enables your site to capture votes on different topics in the form of multiple choice questions.
Code
function poll_block($op = 'list', $delta = 0) {
if (user_access('access content')) {
if ($op == 'list') {
$blocks[0]['info'] = t('Most recent poll');
return $blocks;
}
else {
if ($op == 'view') {
// Retrieve the latest poll.
$sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1");
$timestamp = db_result(db_query($sql));
if ($timestamp) {
$poll = node_load(array(
'type' => 'poll',
'created' => $timestamp,
'status' => 1,
));
if ($poll->nid) {
$poll = poll_view($poll, TRUE, FALSE, TRUE);
}
}
$block['subject'] = t('Poll');
$block['content'] = drupal_render($poll->content);
return $block;
}
}
}
}