poll_block

Versions
4.6 – 6
poll_block($op = 'list', $delta = 0)

Implementation of hook_block().

Generates a block containing the latest poll.

Code

modules/poll.module, line 45

<?php
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 AND n.moderate = 0");
      $timestamp = db_result(db_query($sql));
      if ($timestamp) {
        $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'moderate' => 0, 'status' => 1));

        if ($poll->nid) {
          // poll_view() dumps the output into $poll->body.
          poll_view($poll, 1, 0, 1);
        }
      }
      $block['subject'] = t('Poll');
      $block['content'] = $poll->body;
      return $block;
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.