You are here

function referral_admin_view_unflagged in User Referral 7

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

File

./referral.module, line 560
The referral module.

Code

function referral_admin_view_unflagged() {
  $header = array(
    array(
      'data' => t('Referring User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('# Unflagged'),
      'field' => 'cnt',
    ),
    array(
      'data' => t('Last'),
      'field' => 'last',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Operations'),
    ),
  );
  $select_condition = db_select('users', 'u')
    ->fields('u', array(
    'uid',
  ))
    ->condition('status', 1);
  $query = db_select('referral', 'r');
  $query
    ->addExpression('COUNT(*)', 'cnt');
  $query
    ->addExpression('MAX(r.created)', 'last');
  $query
    ->innerJoin('users', 'u', 'u.uid = r.referral_uid');
  $result = $query
    ->fields('u', array(
    'name',
  ))
    ->fields('r', array(
    'referral_uid',
    'uid',
  ))
    ->condition('r.flag', 0)
    ->condition('r.uid', $select_condition, 'IN')
    ->groupBy('r.referral_uid')
    ->extend('PagerDefault')
    ->range(0, REFERRAL_PAGE_COUNT)
    ->extend('TableSort')
    ->orderByHeader($header)
    ->execute();

  /*$sql = 'SELECT r.referral_uid, u.name, COUNT(*) AS cnt, MAX(r.created) AS last
    FROM {referral} r INNER JOIN {users} u ON(r.referral_uid = u.uid)
    WHERE r.flag = 0
    AND r.uid IN
    ( SELECT u.uid FROM {users} u WHERE status = 1 )
    GROUP BY r.referral_uid' . tablesort_sql($header);*/
  $rows = array();
  foreach ($result as $data) {
    $rows[] = array(
      array(
        'data' => l($data->name, "user/{$data->referral_uid}"),
      ),
      array(
        'data' => $data->cnt,
      ),
      array(
        'data' => format_date($data->last, 'custom', REFERRAL_DATE_FORMAT),
      ),
      array(
        'data' => l(t('details'), "admin/reports/referral/roles/{$data->referral_uid}") . ' | ' . l(t('flag'), "admin/referral/flag/{$data->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,
  ));
}