function advpoll_node_view in Advanced Poll 7.2
Same name and namespace in other branches
- 7.3 advpoll.module \advpoll_node_view()
- 7 advpoll.module \advpoll_node_view()
Implements hook_node_view().
Since node is defined as CCK in install script, needed to use this instead of hook_view.
File
- ./
advpoll.module, line 170
Code
function advpoll_node_view($node, $view_mode) {
if ($node->type == 'advpoll') {
$data = advpoll_get_data($node);
if ($data->behavior == 'approval' || $data->behavior == 'pool') {
drupal_add_css(drupal_get_path('module', 'advpoll') . '/css/advpoll.css', array(
'group' => CSS_DEFAULT,
'every_page' => TRUE,
));
// replace the markup for choices with appropriate markup.
unset($node->content['advpoll_choice']);
// check for eligibility to vote
if (advpoll_user_eligibility($node)) {
// print out voting form
$voteform = drupal_get_form('advpoll_choice_form', $node);
$node->content['advpoll_choice'] = array(
0 => $voteform,
'#weight' => 1,
);
}
else {
// get user's votes if they're logged in and if voting is normal
$votes = array();
if ($data->mode == 'normal') {
$votes = advpoll_get_user_votes($node->nid);
}
// Depending upon the reasons that the user is ineligible to vote,
// select the appropriate theme.
if ($data->state == 'close' && $data->show_results != 'afterclose' || ($data->start_date > time() || $data->end_date < time())) {
$results = theme('advpoll_closed', array(
'data' => $data,
));
}
elseif ($data->electoral && $data->show_results != 'aftervote') {
$results = theme('advpoll_ineligible', array(
'data' => $data,
));
}
else {
$results = advpoll_display_results($node->nid, $data);
}
$node->content['advpoll_choice'] = array(
'#markup' => $results,
'#weight' => 1,
);
}
}
}
}