Skip to content

Commit 69bc200

Browse files
don't display top if it's empty
Signed-off-by: Diego Andrés <diegoandres_cortes@outlook.com>
1 parent 296fea2 commit 69bc200

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

Sources/SimpleReferrals.php

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* @package Simple Referrals
5-
* @version 1.3.1
5+
* @version 1.4.2
66
* @author Diego Andrés <diegoandres_cortes@outlook.com>
77
* @copyright Copyright (c) 2021, SMF Tricks
88
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
@@ -574,49 +574,55 @@ public function forum_stats()
574574
global $smcFunc, $context, $scripturl, $settings, $modSettings;
575575

576576
// Referrals Top.
577-
if (!empty($modSettings['SimpleReferrals_enable_stats']))
578-
{
579-
// Ref language
580-
loadLanguage('SimpleReferrals/');
577+
if (empty($modSettings['SimpleReferrals_enable_stats']))
578+
return;
581579

582-
// Template
583-
loadTemplate('SimpleReferrals');
580+
// Ref language
581+
loadLanguage('SimpleReferrals/');
584582

585-
// Add the icon without adding a css file...
586-
addInlineCss('
587-
.main_icons.most_referrals::before {
588-
background: url('. $settings['default_images_url'] . '/icons/most_referrals.png);
589-
}
590-
');
583+
// Template
584+
loadTemplate('SimpleReferrals');
591585

592-
// Top 10 referrals
593-
$context['stats_blocks']['most_referrals'] = [];
594-
$max_referrals = 1;
595-
$request = $smcFunc['db_query']('', '
596-
SELECT mem.ref_count, mem.id_member, mem.real_name
597-
FROM {db_prefix}members AS mem
598-
WHERE mem.ref_count > 0
599-
ORDER BY mem.ref_count DESC
600-
LIMIT 10',
601-
[]
602-
);
603-
while ($ref_row = $smcFunc['db_fetch_assoc']($request))
604-
{
605-
$context['stats_blocks']['most_referrals'][] = [
606-
'id' => $ref_row['id_member'],
607-
'num' => $ref_row['ref_count'],
608-
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $ref_row['id_member'] . '">' . $ref_row['real_name'] . '</a>',
609-
];
610-
611-
if ($max_referrals < $ref_row['ref_count'])
612-
$max_referrals = $ref_row['ref_count'];
586+
// Add the icon without adding a css file...
587+
addInlineCss('
588+
.main_icons.most_referrals::before {
589+
background: url('. $settings['default_images_url'] . '/icons/most_referrals.png);
613590
}
614-
$smcFunc['db_free_result']($request);
591+
');
615592

616-
// Percentage
617-
foreach ($context['stats_blocks']['most_referrals'] as $i => $referral_count)
618-
$context['stats_blocks']['most_referrals'][$i]['percent'] = round(($referral_count['num'] * 100) / $max_referrals);
593+
// Top 10 referrals
594+
$max_referrals = 1;
595+
$request = $smcFunc['db_query']('', '
596+
SELECT mem.ref_count, mem.id_member, mem.real_name
597+
FROM {db_prefix}members AS mem
598+
WHERE mem.ref_count > 0
599+
ORDER BY mem.ref_count DESC
600+
LIMIT 10',
601+
[]
602+
);
603+
604+
// Don't do anything if there are no referrals
605+
if (empty($smcFunc['db_num_rows']($request)))
606+
return;
607+
608+
// Setup the block
609+
$context['stats_blocks']['most_referrals'] = [];
610+
while ($ref_row = $smcFunc['db_fetch_assoc']($request))
611+
{
612+
$context['stats_blocks']['most_referrals'][] = [
613+
'id' => $ref_row['id_member'],
614+
'num' => $ref_row['ref_count'],
615+
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $ref_row['id_member'] . '">' . $ref_row['real_name'] . '</a>',
616+
];
617+
618+
if ($max_referrals < $ref_row['ref_count'])
619+
$max_referrals = $ref_row['ref_count'];
619620
}
621+
$smcFunc['db_free_result']($request);
622+
623+
// Percentage
624+
foreach ($context['stats_blocks']['most_referrals'] as $i => $referral_count)
625+
$context['stats_blocks']['most_referrals'][$i]['percent'] = round(($referral_count['num'] * 100) / $max_referrals);
620626
}
621627

622628
/**

0 commit comments

Comments
 (0)