You are here

function userpoints_admin_points in User Points 7

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_admin_points()
  2. 6 userpoints.module \userpoints_admin_points()
  3. 7.2 userpoints.admin.inc \userpoints_admin_points()

Provides an administrative interface for managing points.

1 string reference to 'userpoints_admin_points'
userpoints_menu in ./userpoints.module
Implements hook_menu().

File

./userpoints.admin.inc, line 378
Admin menu callbacks for userpoints.module.

Code

function userpoints_admin_points($form, &$form_state) {

  // If this is an AJAX request, update $_GET['q'] so that table sorting and
  // similar links are using the correct base path.
  if ($_GET['q'] == 'system/ajax') {
    $_GET['q'] = 'admin/config/people/userpoints';
  }
  $header = userpoints_get_list_header();
  $query = db_select('userpoints', 'p')
    ->extend('PagerDefault')
    ->extend('TableSort')
    ->fields('p', array(
    'uid',
    'points',
    'tid',
  ))
    ->fields('u', array(
    'name',
  ))
    ->groupBy('p.uid')
    ->groupBy('u.name')
    ->groupBy('p.points')
    ->groupBy('p.tid')
    ->orderByHeader($header)
    ->limit(variable_get(USERPOINTS_REPORT_USERCOUNT, 30));
  $query
    ->join('users', 'u', 'p.uid = u.uid');
  if (module_exists('taxonomy')) {
    $query
      ->groupBy('t.name');
    $query
      ->leftJoin('taxonomy_term_data', 't', 'p.tid = t.tid');
  }
  $values = userpoints_filter_parse_input($form_state);
  $active_category = userpoints_filter_query($query, $values);
  if (isset($active_category)) {
    drupal_set_title(t('Totals (%category category)', userpoints_translation() + array(
      '%category' => $active_category,
    )), PASS_THROUGH);
  }
  else {
    drupal_set_title(t('Totals'));
  }
  if (variable_get(USERPOINTS_REPORT_DISPLAYZERO, 1) == 0) {

    // The user would NOT like to see users with zero points.
    $query
      ->condition('p.points', 0, '<>');
  }
  $rows = array();
  foreach ($query
    ->execute() as $data) {
    $rows[] = userpoints_get_list_row($data);
  }
  $output = array();
  $output['form'] = userpoints_filter_form(NULL, $values);
  $output['list'] = array(
    '#type' => 'container',
    '#id' => 'userpoints_list_wrapper',
  );
  $output['list']['table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  $output['list']['pager'] = array(
    '#theme' => 'pager',
  );
  return $output;
}