Block with the latest poll for each OG

lelizondob - January 7, 2009 - 10:05
Project:Advanced Poll
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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

#1

lelizondob - January 7, 2009 - 10:06

just to attach the file

AttachmentSize
ogpolls.module.txt 1.19 KB
 
 

Drupal is a registered trademark of Dries Buytaert.