You are here

function i18npoll_block in Internationalization 6

Implementation of hook_block().

Generates a block containing the latest poll with aggregated results.

File

i18npoll/i18npoll.module, line 63
Multilingual poll - Aggregates poll results for all translations.

Code

function i18npoll_block($op = 'list', $delta = 0) {
  if (user_access('access content')) {
    if ($op == 'list') {
      $blocks[0]['info'] = t('Most recent poll (Aggregated translations)');
      return $blocks;
    }
    elseif ($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 = i18npoll_view($poll, TRUE, FALSE, TRUE);
        }
      }
      $block['subject'] = t('Poll');
      $block['content'] = drupal_render($poll->content);
      return $block;
    }
  }
}