You are here

function vote_up_down_users_votes in Vote Up/Down 6

Same name and namespace in other branches
  1. 5 vote_up_down.module \vote_up_down_users_votes()

Users votes page for the vote_up_down_page data.

1 call to vote_up_down_users_votes()
vote_up_down_page in ./vote_up_down.module
Menu callback; Handles voteupdown and subpages.

File

./vote_up_down.module, line 438

Code

function vote_up_down_users_votes() {
  $sql = "SELECT COUNT(v.value) AS number_votes, SUM(v.value) AS total_votes, v.uid, v.tag, u.uid, u.name FROM {votingapi_vote} v INNER JOIN {users} u on v.uid = u.uid WHERE v.tag = '%s' GROUP BY u.name";
  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {votingapi_vote}";
  $header = array(
    array(
      'data' => t('User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Votes'),
      'field' => 'number_votes',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Vote sum'),
      'field' => 'total_votes',
    ),
  );
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 30, 0, $sql_cnt, variable_get('vote_up_down_tag', 'vote'));
  $rows = array();
  while ($vote = db_fetch_object($result)) {
    $rows[] = array(
      theme('username', $vote),
      $vote->number_votes,
      $vote->total_votes,
    );
  }
  drupal_set_title(t('Users by votes'));
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  return $output;
}