function advpoll_ranking_votes_page in Advanced Poll 7.2
Same name and namespace in other branches
- 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_votes_page()
- 7 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_votes_page()
Display the overridden votes page. Uses almost the same output but allows grouping for borda and instant-runoff.
1 string reference to 'advpoll_ranking_votes_page'
- advpoll_ranking_menu_alter in advpoll_ranking/
advpoll_ranking.module - Implements hook_menu_alter().
File
- advpoll_ranking/
advpoll_ranking.module, line 136
Code
function advpoll_ranking_votes_page($node) {
drupal_add_css(drupal_get_path('module', 'advpoll') . '/css/advpoll.css', array(
'group' => CSS_DEFAULT,
'every_page' => TRUE,
));
$data = advpoll_get_data($node);
$output = t('This table lists all the recorded votes for this poll.');
if ($data->mode == 'unlimited') {
$output = t('With unlimited voting, a timestamp is used to identify unique votes. If it is important to identify users by ID or IP, switch to normal voting mode which will use your Voting API settings to record votes.');
}
elseif ($data->mode == 'cookie') {
$output = t('With cookie-based voting, a timestamp is used to identify unique votes while the poll\'s id is set in the cookie to limit votes for a limited time. If it is important to identify users by ID or IP, switch to normal voting mode which will use your Voting API settings to record votes.');
}
else {
$output = t('If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.');
}
$header = array();
$header[] = array(
'data' => t('Visitor'),
'field' => 'uid',
);
$header[] = array(
'data' => t('Date'),
'field' => 'timestamp',
'sort' => 'asc',
);
$header[] = array(
'data' => t('Choice'),
'tag',
);
$nid = $node->nid;
$query = db_select('votingapi_vote', 'v')
->condition('entity_id', $nid)
->extend('PagerDefault')
->limit(20)
->extend('TableSort')
->orderByHeader($header)
->fields('v', array(
'uid',
'timestamp',
'tag',
'vote_source',
'value',
));
$results = $query
->execute();
$user_obj = NULL;
$rows = array();
foreach ($results as $item) {
$user_id = $item->uid;
if (!$user_id) {
$user_id = $item->vote_source;
}
else {
$user_obj = user_load($user_id);
if ($user_obj) {
$user_id = l($user_obj->name, 'user/' . $user_id);
}
}
if ($data->behavior == 'borda' || $data->behavior == 'runoff') {
$rows[] = array(
'data' => array(
$user_id,
format_date($item->timestamp),
advpoll_match_tag_to_choice($data->choices, $item->tag),
$item->value,
),
);
}
else {
$rows[] = array(
'data' => array(
$user_id,
format_date($item->timestamp),
advpoll_match_tag_to_choice($data->choices, $item->tag),
),
);
}
}
if ($rows) {
if ($data->behavior == 'borda' || $data->behavior == 'runoff') {
$rows = advpoll_ranking_process_rows($rows);
}
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
));
$output .= theme('pager', array(
'tags' => array(),
));
if (user_access('administer votes')) {
$rendered_form = drupal_get_form('advpoll_clear_votes_form');
$output .= drupal_render($rendered_form);
}
}
else {
$output .= '<hr /><p>' . t('No votes are currently recorded for %title', array(
'%title' => $node->title,
)) . '</p>';
}
return $output;
}