You are here

function vote_up_down_block in Vote Up/Down 6

Implementation of hook_block().

File

./vote_up_down.module, line 352

Code

function vote_up_down_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Who voted on this?');
    return $blocks;
  }
  if ($op == 'view') {
    $block = array();
    switch ($delta) {
      case 0:
        if (arg(0) == 'node' & is_numeric(arg(1))) {

          // Check that this node type is enabled for vote_up_down, and if not don't display the block.
          $node = node_load(arg(1));
          if (!vote_up_down_node_access($node)) {
            return;
          }
          $block['subject'] = t('Who voted on this?');
          $nid = arg(1);
          $tag = variable_get('vote_up_down_tag', 'vote');
          $votes = array(
            'content_id' => $nid,
            'tag' => $tag,
          );

          // TODO: support multiple 'tag' in a nested table?
          $voteresults = votingapi_select_votes($votes);
          $block['content'] = theme('vote_up_down_whovoted_block', $nid, $voteresults);
        }
        break;
    }
    return $block;
  }
}