SHARE
TWEET

referral

a guest Feb 18th, 2015 254 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function referral_admin_view_summary() {
  3.   $header = array(
  4.     array('data' => t('Referring User'), 'field' => 'r.referral_uid'),
  5.     array('data' => t('# Referred'),     'field' => 'num_referrals', 'sort' => 'desc'),
  6.     array('data' => t('Last Referral'),  'field' => 'r.created'),
  7.     array('data' => t('Details')),
  8.     );
  9.  
  10.   $query = db_select('referral', 'r');
  11.   $query->addExpression('COUNT(*)', 'num_referrals');
  12.   $query->addExpression('MAX(r.created)', 'last');
  13.   $query->innerJoin('users', 'u', 'u.uid = r.referral_uid');
  14.   $query->innerJoin('users', 'u2', 'u2.uid = r.uid');
  15.   $result = $query
  16.     ->fields('u', array('name'))
  17.         ->fields('r', array('referral_uid'))
  18.         ->condition('u2.status', 1)
  19.         ->groupBy('r.referral_uid')
  20.         ->extend('PagerDefault')
  21.         ->range(0, REFERRAL_PAGE_COUNT)
  22.         ->extend('TableSort')
  23.         ->orderByHeader($header)
  24.         ->execute();
  25.        
  26.   $rows = array();     
  27.  
  28.   foreach ($result as $data) {
  29.     $rows[] = array(
  30.       array('data' => l($data->name, "user/$data->referral_uid")),
  31.       array('data' => $data->num_referrals),
  32.       array('data' => format_date($data->last, 'custom', REFERRAL_DATE_FORMAT)),
  33.       array('data' => l(t('details'), "admin/reports/referral/details/$data->referral_uid")),
  34.     );
  35.   }
  36.   if (!$rows) {
  37.     $rows[] = array(array('data' => t('No data.'), 'colspan' => '4'));
  38.   }
  39.   $pager = theme('pager', array('tags' => array()));
  40.   if (!empty($pager)) {
  41.     $rows[] = array(array('data' => $pager, 'colspan' => '4'));
  42.   }
  43.  
  44.   return theme('table', array('header' => $header, 'rows' => $rows));
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top