You are here

function vote_up_down_users_votes in Vote Up/Down 5

Same name and namespace in other branches
  1. 6 vote_up_down.module \vote_up_down_users_votes()
1 call to vote_up_down_users_votes()
vote_up_down_page in ./vote_up_down.module

File

./vote_up_down.module, line 347
vote_up_down is a module that adds a widget for +1/-1 votes on nodes. It depends upon Voting API. It's based upon "simplevote.module".

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'));
  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;
}