You are here

function pay_admin_pay_form_list in Pay 7

Same name and namespace in other branches
  1. 6 includes/pay.admin.inc \pay_admin_pay_form_list()

List payment forms

File

includes/pay.admin.inc, line 78
Administration form settings and related functions.

Code

function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
  $hdrs = array(
    array(
      'data' => t('Title'),
      'field' => 'Title',
    ),
    array(
      'data' => t('Owner'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Handler'),
      'field' => 'handler',
    ),
    array(
      'data' => t('Status'),
      'field' => 'status',
    ),
    array(
      'data' => t('Total'),
      'field' => 'total',
    ),
    array(
      'data' => t('Total paid'),
      'field' => 'total_paid',
    ),
    array(),
  );
  $query = db_select('pay_form', 'f')
    ->fields('f');
  $query
    ->addExpression('SUM(t.total)', 'total');
  $query
    ->addExpression('SUM(t.total_paid)', 'total_paid');
  $query
    ->leftJoin('pay_transaction', 't', 'f.pfid = t.pfid');
  if ($handler) {
    $subclasses = array();
    foreach (pay_handlers('pay_form') as $name => $info) {
      if ($pay_form = pay_form_load($name)) {
        if (is_subclass_of($pay_form, $handler)) {
          $subclasses[] = $name;
        }
      }
    }
    if ($subclasses) {
      $subclasses[] = $handler;
      $query
        ->condition('f.handler', $subclasses, 'in');
    }
    else {
      $query
        ->condition('f.handler', $handler);
    }
    unset($hdrs[2]);
  }
  $query
    ->groupBy('f.pfid');
  $query
    ->extend('tableSort')
    ->orderByHeader($hdrs);
  $query
    ->extend('PagerDefault')
    ->limit(20);
  $res = $query
    ->execute();
  $path = $_GET['q'];
  $rows = array();
  $pay_forms = array();
  foreach ($res as $data) {
    $pay_form = pay_form_load($data);
    $row = array(
      $pay_form
        ->menu_path() ? l($pay_form
        ->title(), $pay_form
        ->menu_path()) : $pay_form
        ->title(),
      theme('username', array(
        'account' => $pay_form
          ->user(),
      )),
      $pay_form
        ->handler_title(),
      $pay_form->status ? t('active') : t('disabled'),
      round($data->total),
      round($data->total_paid),
      l(t('edit'), $path . '/' . $pay_form->pfid . '/edit', array(
        'query' => array(
          'destination' => $path,
        ),
      )),
    );
    if ($handler) {
      unset($row[2]);
    }
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array();
  }
  return theme('table', array(
    'header' => $hdrs,
    'rows' => $rows,
  ));
}