Index: question.module =================================================================== --- question.module (revision 11) +++ question.module (working copy) @@ -463,6 +463,12 @@ return $node; } +function question_get_random() { + $obj = db_fetch_object(db_query('SELECT n.nid FROM {question_node} q INNER JOIN {node} n ON n.nid = q.nid WHERE n.status = 1 ORDER BY RAND()')); + $node = node_load($obj->nid); + return $node; +} + /** * Returns rendered listing of questions * $teaser is a true/false indicating whether the teaser version @@ -487,4 +493,39 @@ return $output; } +/** + * Implementation of hook_block. + * + * Offers 2 blocks: latest question and random question + */ +function question_block($op, $delta = 0) { + switch ($op) { + case 'list': + $block[0]['info'] = t('Latest question'); + $block[1]['info'] = t('Random question'); + + return $block; + case 'view': + if (user_access('access content')) { + switch($delta) { + case 0: + $question = question_get_latest(); + $block['subject'] = t('Latest question'); + $block['content'] = theme('question_block', $question); + break; + case 1: + $question = question_get_random(); + $block['subject'] = t('Random question'); + $block['content'] = theme('question_block', $question); + break; + } + } + return $block; + } +} + +function theme_question_block($node) { + return theme_question_teaser($node); +} + ?>