You are here

function referral_admin_view_summary in User Referral 6

Same name and namespace in other branches
  1. 5 referral.module \referral_admin_view_summary()
  2. 7 referral.module \referral_admin_view_summary()
1 string reference to 'referral_admin_view_summary'
referral_menu in ./referral.module

File

./referral.module, line 487

Code

function referral_admin_view_summary() {
  $header = array(
    array(
      'data' => t('Referring User'),
      'field' => 'r.referral_uid',
    ),
    array(
      'data' => t('# Referred'),
      'field' => 'num_referrals',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Last Referral'),
      'field' => 'r.created',
    ),
    array(
      'data' => t('Details'),
    ),
  );
  $sql = 'SELECT r.referral_uid, u.name, COUNT(*) AS num_referrals, MAX(r.created) AS last
    FROM {referral} r INNER JOIN {users} u ON u.uid = r.referral_uid
    INNER JOIN {users} u2 ON u2.uid = r.uid
    WHERE u2.status = 1
    GROUP BY r.referral_uid' . tablesort_sql($header);
  $result = pager_query($sql, REFERRAL_PAGE_COUNT);
  while ($data = db_fetch_object($result)) {
    $rows[] = array(
      array(
        'data' => l($data->name, "user/{$data->referral_uid}"),
      ),
      array(
        'data' => $data->num_referrals,
      ),
      array(
        'data' => format_date($data->last, 'custom', REFERRAL_DATE_FORMAT),
      ),
      array(
        'data' => l(t('details'), "admin/reports/referral/details/{$data->referral_uid}"),
      ),
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No data.'),
        'colspan' => '4',
      ),
    );
  }
  $pager = theme('pager', NULL, REFERRAL_PAGE_COUNT, 0);
  if (!empty($pager)) {
    $rows[] = array(
      array(
        'data' => $pager,
        'colspan' => '4',
      ),
    );
  }
  return theme('table', $header, $rows);
}