You are here

function advpoll_ranking_votes_page in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_votes_page()
  2. 7.2 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 123

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.');
  }
  else {
    if ($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();
  $userObj = null;
  $rows = array();
  foreach ($results as $item) {
    $userID = $item->uid;
    if (!$userID) {
      $userID = $item->vote_source;
    }
    else {
      $userObj = user_load($userID);
      if ($userObj) {
        $userID = l($userObj->name, 'user/' . $userID);
      }
    }
    if ($data->behavior == 'borda' || $data->behavior == 'runoff') {
      $rows[] = array(
        'data' => array(
          $userID,
          format_date($item->timestamp),
          advpoll_match_tag_to_choice($data->choices, $item->tag),
          $item->value,
        ),
      );
    }
    else {
      $rows[] = array(
        'data' => array(
          $userID,
          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')) {
      $output .= drupal_render(drupal_get_form('advpoll_clear_votes_form'));
    }
  }
  else {
    $output .= '<hr /><p>' . t('No votes are currently recorded for %title', array(
      '%title' => $node->title,
    )) . '</p>';
  }
  return $output;
}