You are here

function referral_view in User Referral 7

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

File

./referral.module, line 446
The referral module.

Code

function referral_view() {

  // TODO: Views for this page is at 'my-referrals'. Redirect to the views page.
  // TODO: Remove code from this function
  global $user;
  $output = '<div class="referral_link">';
  $output .= t('Your referral link: ');
  $output .= url('referral/' . _referral_uid2ref($user->uid), array(
    'query' => NULL,
    'fragment' => NULL,
    'absolute' => TRUE,
  ));
  $output .= '</div>';
  $header = array(
    array(
      'data' => t('User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Roles'),
    ),
    array(
      'data' => t('Flag'),
      'field' => 'r.flag',
    ),
    array(
      'data' => t('Time'),
      'field' => 'r.created',
      'sort' => 'desc',
    ),
  );
  $query = db_select('referral', 'r');
  $query
    ->innerJoin('users', 'u', 'r.uid = u.uid');
  $result = $query
    ->fields('u', array(
    'uid',
    'name',
  ))
    ->fields('r', array(
    'created',
    'flag',
  ))
    ->condition('referral_uid', $user->uid)
    ->condition('u.status', 1)
    ->orderBy('r.created', 'DESC')
    ->extend('PagerDefault')
    ->range(0, REFERRAL_PAGE_COUNT)
    ->extend('TableSort')
    ->orderByHeader($header)
    ->execute();
  $rows = array();
  foreach ($result as $data) {
    $rows[] = array(
      array(
        'data' => l($data->name, "user/{$data->uid}"),
      ),
      array(
        'data' => implode(',', _referral_get_user_roles($data->uid)),
      ),
      array(
        'data' => $data->flag ? 'Yes' : 'No',
      ),
      array(
        'data' => format_date($data->created, 'custom', REFERRAL_DATE_FORMAT),
      ),
    );
  }
  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',
      ),
    );
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  return $output;
}