function advpoll_get_recent in Advanced Poll 7.3
Same name and namespace in other branches
- 7 advpoll.module \advpoll_get_recent()
- 7.2 advpoll.module \advpoll_get_recent()
Gets content for most recent poll block.
Return value
A rendered node or NULL.
1 call to advpoll_get_recent()
- advpoll_block_view in ./
advpoll.module - Implements hook_block_view().
File
- ./
advpoll.module, line 922
Code
function advpoll_get_recent() {
// Check to see if the page that is loading this block is a node page.
$loaded_node = menu_get_object();
$node = '';
$result = db_query_range("\n SELECT n.nid FROM {node} n\n LEFT JOIN {field_data_advpoll_dates} d\n ON d.revision_id = n.vid\n LEFT JOIN {field_data_advpoll_closed} c\n ON c.revision_id = n.vid\n LEFT JOIN {field_data_advpoll_options} o\n ON o.revision_id = n.vid\n LEFT JOIN {field_data_advpoll_results} r\n ON r.revision_id = n.vid\n WHERE\n n.nid NOT IN(\n SELECT entity_id\n FROM {field_data_advpoll_options}\n WHERE advpoll_options_value = 'electoral'\n ) AND\n n.type = 'advpoll' AND\n n.status = 1 AND\n (\n c.advpoll_closed_value = 'open' \n OR (c.advpoll_closed_value = 'close' AND r.advpoll_results_value = 'afterclose')\n )\n AND\n d.advpoll_dates_value < NOW() AND\n (d.advpoll_dates_value2 > NOW()\n OR r.advpoll_results_value = 'afterclose')\n ORDER BY n.created DESC", 0, 1);
if ($result) {
foreach ($result as $record) {
$node = node_load($record->nid);
break;
}
if ($node) {
// Prevent block from showing on its node's page.
if ($loaded_node) {
if ($loaded_node->nid == $record->nid) {
return '';
}
}
$rendered_node = node_view($node);
return drupal_render($rendered_node);
}
}
return $node;
}