You are here

function poll_block_view in Drupal 7

Implements hook_block_view().

Generates a block containing the latest poll.

File

modules/poll/poll.module, line 144
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_block_view($delta = '') {
  if (user_access('access content')) {

    // Retrieve the latest poll.
    $select = db_select('node', 'n');
    $select
      ->join('poll', 'p', 'p.nid = n.nid');
    $select
      ->fields('n', array(
      'nid',
    ))
      ->condition('n.status', 1)
      ->condition('p.active', 1)
      ->orderBy('n.created', 'DESC')
      ->range(0, 1)
      ->addTag('node_access');
    $record = $select
      ->execute()
      ->fetchObject();
    if ($record) {
      $poll = node_load($record->nid);
      if ($poll->nid) {
        $poll = poll_block_latest_poll_view($poll);
        $block['subject'] = t('Poll');
        $block['content'] = $poll->content;
        return $block;
      }
    }
  }
}