You are here

function advpoll_votes_page in Advanced Poll 7.3

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 includes/advpoll.pages.inc \advpoll_votes_page()
  6. 7.2 includes/advpoll.pages.inc \advpoll_votes_page()

Generates page for administering individual voters on a poll.

Enables administrator to clear all votes. For users that can view votes but not administer them, the button is not displayed.

Parameters

$node: An advpoll node.

Return value

string Markup displayed by menu callback for this page.

1 string reference to 'advpoll_votes_page'
advpoll_menu in ./advpoll.module
Implements hook_menu().

File

includes/advpoll.pages.inc, line 23
Advanced Poll Pages Include.

Code

function advpoll_votes_page($node) {
  $data = advpoll_get_data($node);
  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',
  ));
  $tags = array();
  foreach ($data->choices as $choice) {
    $tags[] = $choice['choice_id'];
  }
  $query
    ->condition('tag', $tags);
  $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 polls')) {
      $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;
}