You are here

function userpoints_admin_transactions in User Points 7.2

Same name and namespace in other branches
  1. 7 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 566
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', UserpointsTransaction::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();
  $result = $query
    ->execute();
  $transactions = userpoints_transaction_load_multiple($result
    ->fetchCol());
  foreach ($transactions as $transaction) {
    $rows[] = $transaction
      ->getTableRow($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;
}