You are here

function poll_block in Drupal 4

Same name and namespace in other branches
  1. 5 modules/poll/poll.module \poll_block()
  2. 6 modules/poll/poll.module \poll_block()

Implementation of hook_block().

Generates a block containing the latest poll.

File

modules/poll.module, line 46
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 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;
      }
    }
  }
}