You are here

function userpoints_admin_transactions in User Points 7

Same name and namespace in other branches
  1. 7.2 userpoints.admin.inc \userpoints_admin_transactions()

Displays a list of transactions.

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

File

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

Code

function userpoints_admin_transactions($form, &$form_state, $moderate) {

  // 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'] = $moderate ? 'admin/config/people/userpoints/moderate' : 'admin/config/people/userpoints/transaction';
  }
  $settings = array(
    'show_status' => !$moderate,
  );
  $header = userpoints_get_transaction_header($settings);
  $query = db_select('userpoints_txn', 'p')
    ->extend('PagerDefault')
    ->extend('TableSort')
    ->fields('p')
    ->orderByHeader($header)
    ->orderBy('p.txn_id', 'DESC')
    ->limit(variable_get(USERPOINTS_REPORT_USERCOUNT, 30));
  if ($moderate) {
    $query
      ->condition('p.status', USERPOINTS_TXN_STATUS_PENDING);
  }
  if (module_exists('taxonomy')) {
    $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 ($moderate) {
    if (isset($active_category)) {
      drupal_set_title(t('Moderation (%category category)', userpoints_translation() + array(
        '%category' => $active_category,
      )), PASS_THROUGH);
    }
    else {
      drupal_set_title(t('Moderation'));
    }
  }
  else {
    if (isset($active_category)) {
      drupal_set_title(t('Transactions (%category category)', userpoints_translation() + array(
        '%category' => $active_category,
      )), PASS_THROUGH);
    }
    else {
      drupal_set_title(t('Transactions'));
    }
  }
  $rows = array();
  foreach ($query
    ->execute() as $transaction) {
    $rows[] = userpoints_get_transaction_row($transaction, $settings);
  }

  // Store context in the output array so that modules have access to it.
  $output = array(
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'userpoints') . '/userpoints.css',
      ),
    ),
  );
  $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,
    '#empty' => $moderate ? t('No !points awaiting moderation', userpoints_translation()) : t('No !Points earned', userpoints_translation()),
    '#weight' => -5,
    '#attributes' => array(
      'class' => array(
        $moderate ? 'userpoints-moderation-list' : 'userpoints-transactions-list',
      ),
    ),
  );
  $output['list']['pager'] = array(
    '#theme' => 'pager',
    '#weight' => 0,
  );
  return $output;
}