function referral_block_content in User Referral 7
Same name and namespace in other branches
- 5 referral.module \referral_block_content()
- 6 referral.module \referral_block_content()
1 call to referral_block_content()
File
- ./
referral.module, line 389 - The referral module.
Code
function referral_block_content() {
$header = array();
/*$query = db_select('referral', 'r');
$query->innerJoin('users', 'u', 'u.uid = r.referral_uid');
$query->innerJoin('users', 'u2', 'u2.uid = r.uid');
$result = $query
->fields('r', array('referral_uid'))
->fields('u', array('name'))
->condition('u2.status', 1)
->groupBy('r.referral_uid')
->range(0, REFERRAL_BLOCK_COUNT)
->execute();
*/
$sql = 'SELECT r.referral_uid, u.name, COUNT(*) AS num_referrals
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
ORDER BY num_referrals DESC
LIMIT :count';
$result = db_query($sql, array(
'count' => REFERRAL_BLOCK_COUNT,
));
$rows = array();
foreach ($result as $data) {
$rows[] = array(
array(
'data' => l($data->name, "user/{$data->referral_uid}"),
),
array(
'data' => $data->num_referrals,
),
);
}
if (!$rows) {
$rows[] = array(
array(
'data' => t('No data.'),
),
);
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
));
}