SMFHacks.com

Badge Awards => Support => Topic started by: 200mV on May 27, 2014, 10:59:43 am

Title: Keep a certain badge in 1st position?
Post by: 200mV on May 27, 2014, 10:59:43 am
Is there an easy way to keep a certain badge in the 1st position when badges are being shown on the forum under your avatar?

I made a custom badge called "Paid Member" and if possible, I would like that one (when applicable) to be the first one being shown always...

Is this possible?

Thanks!
Title: Re: Keep a certain badge in 1st position?
Post by: SMFHacks on May 27, 2014, 12:40:40 pm
You can try this code unsted.
Just change the $firstBadgeID = 111111;
To the id of the badge you want first

Find
Code: [Select]
function Badges_DisplayBadges($memberID = 0, $order = 'recent', $maxToShow = 5)
{
global $smcFunc, $modSettings, $boardurl;

if (empty($modSettings['badgeawards_enable']))
return;

    if (empty($memberID))
        return; 
       
if (empty($modSettings['badgeawards_url']))
$modSettings['badgeawards_url'] = $boardurl . '/badges/';
       
$badgesCache = array();
if (($badgesCache = cache_get_data('badge_display_' . $memberID, 60)) == null)
{

$result = $smcFunc['db_query']('', "
SELECT
b.id_badge, b.title, b.image, b.enabled
FROM ({db_prefix}badgeawards_badges as b, {db_prefix}badgeawards_badge_log as l)
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
ORDER BY l.id_log DESC
LIMIT  $maxToShow
");
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$badgesCache[] = $row;

}

Code: [Select]


function Badges_DisplayBadges($memberID = 0, $order = 'recent', $maxToShow = 5)
{
global $smcFunc, $modSettings, $boardurl;

if (empty($modSettings['badgeawards_enable']))
return;

    if (empty($memberID))
        return; 
       
if (empty($modSettings['badgeawards_url']))
$modSettings['badgeawards_url'] = $boardurl . '/badges/';
       
$badgesCache = array();
if (($badgesCache = cache_get_data('badge_display_' . $memberID, 60)) == null)
{

$result = $smcFunc['db_query']('', "
SELECT
b.id_badge, b.title, b.image, b.enabled
FROM ({db_prefix}badgeawards_badges as b, {db_prefix}badgeawards_badge_log as l)
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
ORDER BY l.id_log DESC

");
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$badgesCache[] = $row;

}

$firstBadgeID = 111111;


$finalBadges = array();
$count = 0;
// Get first badge
foreach($badgesCache as $row)
{
if ($badgesCache['id_badge'] == $firstBadgeID)
    {
        $finalBadges[] = $row;
        $count++;
        break;
    }
}



foreach($badgesCache as $row)
{
if ($badgesCache['id_badge'] != $firstBadgeID)
    {
        $finalBadges[] = $row;
        $count++;
       
        if ($count > $maxToShow)
            break;
    }
}

$badgesCache = $finalBadges





Title: Re: Keep a certain badge in 1st position?
Post by: 200mV on May 28, 2014, 02:47:15 pm
Thanks much!

I'll give it a shot and let ya know how it goes...

A+ service, thanks!