You are here

function referral_admin_view_summary in User Referral 7

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

File

./referral.module, line 692
The referral module.

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'),
    ),
  );
  $query = db_select('referral', 'r');
  $query
    ->addExpression('COUNT(*)', 'num_referrals');
  $query
    ->addExpression('MAX(r.created)', 'last');
  $query
    ->innerJoin('users', 'u', 'u.uid = r.referral_uid');
  $query
    ->innerJoin('users', 'u2', 'u2.uid = r.uid');
  $result = $query
    ->fields('u', array(
    'name',
  ))
    ->fields('r', array(
    'referral_uid',
  ))
    ->condition('u2.status', 1)
    ->groupBy('r.referral_uid')
    ->extend('PagerDefault')
    ->range(0, REFERRAL_PAGE_COUNT)
    ->extend('TableSort')
    ->orderByHeader($header)
    ->execute();
  $rows = array();

  /*$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);*/
  foreach ($result as $data) {
    $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', array(
    'tags' => array(),
  ));
  if (!empty($pager)) {
    $rows[] = array(
      array(
        'data' => $pager,
        'colspan' => '4',
      ),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}