You are here

function advpoll_votes_page in Advanced Poll 7.2

Same name and namespace in other branches
  1. 5 advpoll.module \advpoll_votes_page()
  2. 6.3 advpoll.pages.inc \advpoll_votes_page()
  3. 6 advpoll.pages.inc \advpoll_votes_page()
  4. 6.2 advpoll.pages.inc \advpoll_votes_page()
  5. 7.3 includes/advpoll.pages.inc \advpoll_votes_page()
  6. 7 includes/advpoll.pages.inc \advpoll_votes_page()
1 string reference to 'advpoll_votes_page'
advpoll_menu in ./advpoll.module
Implements hook_menu()

File

includes/advpoll.pages.inc, line 16

Code

function advpoll_votes_page($node) {
  $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',
  ));
  $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);
      }
    }
    $rows[] = array(
      'data' => array(
        $user_id,
        format_date($item->timestamp),
        advpoll_match_tag_to_choice($data->choices, $item->tag),
      ),
    );
  }
  if ($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;
}