I couldn't find anything like this. I wanted to associate a poll with a group, so each group can have polls, nothing special here, but what if I want to display the poll in a block?. There's no module to do that. So I came up with a mini-module that shows the last poll for each group. I don't have a CVS account so If anyone finds it interesting please create a new module.

This module will ONLY create a new block to display the latest group's poll and uses advpoll but I think it could be adapted to work with poll and decisions.

<?php
function ogpolls_block($op = 'list') {
  switch ($op) {
    case 'list':
      $blocks['ogpolls']['info'] = t('Latest Group Poll');
      return $blocks;
    case 'view':
      $block['subject'] = t('Latest Group Poll');
      $block['content'] = theme('ogpolls_block_latest_poll');
      return $block;
  }
}

function theme_ogpolls_block_latest_poll() {
  $node = ogpolls_latest_poll();
  $output = '';
  if ($node) {
    $output .= '<h3>'. check_plain($node->title) .'</h3>';  
    $output .= drupal_render($node->content);
    if ($node->voted) {
      $output .= '<p>'. l(t('Older polls'), 'polls', array('class' => 'old-polls', 'title' => t('View the list of polls on this site.'))) .'</p>'; 
    }
  }
  return $output;
}

function ogpolls_latest_poll() {
  if ($group_node = og_get_group_context()) {
    $gid = $group_node->nid;
    $result = db_query('SELECT MAX(og.nid) AS nid FROM {og_ancestry} AS og INNER JOIN {advpoll} AS p ON p.nid = og.nid WHERE p.active = 1 AND og.group_nid = %d', $gid);
    $poll = db_fetch_object($result);
    // The nid will be NULL if there ar no active polls.
    if($poll->nid) {
      $node = advpoll_view(node_load($poll->nid), FALSE, FALSE);
    }
    return $node;
  }
}
?>

If anyone can test it, I'll appreciate it.

Luis

CommentFileSizeAuthor
#1 ogpolls.module.txt1.19 KBlelizondo

Comments

lelizondo’s picture

StatusFileSize
new1.19 KB

just to attach the file

mikhailkrainiuk’s picture

Issue summary: View changes
Status: Needs review » Needs work

Is it an integration between https://www.drupal.org/project/og and Advanced Poll?

Hmm... Looks like the code is outdated. If the issue is still actual and you can create actual code for current OG and AdvPoll, I can create a submodule to Advanced Poll with this integration (and dependencies from OG).