Levertine

Please login or register.

Author Topic: Connecting LevGal to SMFHacks Badge Awards  (Read 1665 times)

testing123

  • Newbie
  • *
  • Posts: 43

Connecting LevGal to SMFHacks Badge Awards
« on: April 04, 2015, 12:34:51 PM »
The title is pretty self explanatory but wondered if anyone else happens to be using 'SMFHacks Badge Awards' Mod, as well as LevGal?

I've found the basics of what I think would need to be done to have the badges awarded but putting the relevant parts together is where I get stuck..



Quote from: SMFHacks.com Team
Custom Badge Action Guides

It is easy to expand Badge Awards. To create a custom badge. Click on the Add Badge link inside the Badge Awards admin.
On that page the main requirement is a unique action name. You will use this action name in your call to badgeawards to add a badge to a member if you are using it dynamically.


The Badges_AwardBadge takes a couple different parameters only the memberid and actionname are required Badges_AwardBadge($memberID,$actionname,$sendpm)

Example code below for custom actions

Code: [Select]
// Badge Awards
global $sourcedir, $user_info;
require_once($sourcedir . '/badgeawards2.php');
Badges_AwardBadge($user_info['id'],'customactionname');
Badges_CheckMember($user_info['id']);
// End Badge Awards


However, the badge awards mod already has 2 pre-installed badges, that I think could be tweaked to work with LevGal..

I think the below codes are connected to SMFHacks Gallery:

The first badge is awarded when a user adds an item to the gallery, and the second when they have 10+ items.

Code: [Select]
if (isset($modSettings['gallery_set_images_per_page']))
{

$result2 = $smcFunc['db_query']('', "
SELECT COUNT(*) AS total FROM {db_prefix}gallery_pic
WHERE ID_MEMBER = $memberID");
$totalRow = $smcFunc['db_fetch_assoc']($result2);


$badgeAction = 'gallery';
if (!in_array($badgeAction,$currentBadges) && $totalRow['total'] >= 1)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}
// photographer
$badgeAction = 'photographer';
if (!in_array($badgeAction,$currentBadges) && $totalRow['total'] >= 10)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}


}


I'd like to make the most out of the badge awards mod and tying it in with the gallery would be sweet!
(possibly another idea for a hook in the future of LevGal, if theres enough interest? :) )

Unlimited Coffee, Tea and Cake provided :P
 O:-)  :tea:
« Last Edit: April 04, 2015, 12:36:44 PM by testing123 »

testing123

  • Newbie
  • *
  • Posts: 43

Re: Connecting LevGal to SMFHacks Badge Awards
« Reply #1 on: April 04, 2015, 02:12:34 PM »
So, I'm having a go at this myself until I hear anything back from SMFHacks or anyone else..

It appears SMFHacks gallery creates a db table (db_prefix{gallery_pic}) that has a column to store the owner (id_member) and another with their total number of items (total)..


I keep having new ideas about how to do this but my latest idea, in my thought chain is:

if the members ID exists in the id_member column of ({db_prefix}lgal_items) then give badge..

(I think LevGal only adds a members ID to the id_member column, if they have any items.)


--------------------------
Thought chain 2:

Like I said before, SMFHacks gallery creates a db table (db_prefix{gallery_pic}) that has a column to store the owner (id_member) and another with their total number of items (total).. Whereas,  LevGal stores this information in a different way, across multiple tables..

Below are my attempts to:
- grab (memberID) from (db_prefix{lgal_items})
- if (num_views) from (db_prefix{lgal_items}) equals or more than 0

My idea behind it, if the member is found in that column and has has 0+ views, the badge would be awarded.

Code: [Select]
if (isset($modSettings['gallery_set_images_per_page']))
{

$result2 = $smcFunc['db_query']('', "
SELECT COUNT(*) AS num_views FROM {db_prefix}lgal_items
WHERE ID_MEMBER = $memberID");
$totalRow = $smcFunc['db_fetch_assoc']($result2);


$badgeAction = 'gallery';
if (!in_array($badgeAction,$currentBadges) && $totalRow['num_views'] >= 0)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}
// photographer
$badgeAction = 'photographer';
if (!in_array($badgeAction,$currentBadges) && $totalRow['num_views'] >= 10)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}


}


(I thought of this idea before noticing a members ID is only added to the column, if they own an item)
--------------



3rd, original idea:


- grab (memberID) from (db_prefix{lgal_items})
- if (album_items) from (db_prefix{lgal_albums}) has 1 or more items then award the badge

(10+ items would award the 2nd badge)

Code: [Select]
if (isset($modSettings['gallery_set_images_per_page']))
{

$result2 = $smcFunc['db_query']('', "
SELECT COUNT(*) AS total FROM {db_prefix}lgal_albums
WHERE NUM_ITEMS = $numITEM");
$totalRow = $smcFunc['db_fetch_assoc']($result2);

$result9 = $smcFunc ['db_query']('', "
SELECT COUNT (*) AS total FROM {db_prefix}lgal_items
WHERE ID_MEMBER = $memberID");
$totalRow = $smcFunc['db_fetch_assoc']($result2);

$badgeAction = 'gallery';
if (!in_array($badgeAction,$currentBadges) && $totalRow['num_items'] >= 1)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}
// photographer
$badgeAction = 'photographer';
if (!in_array($badgeAction,$currentBadges) && $totalRow['num_items'] >= 10)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}


}



I seem to quite often overthink things and make them harder than they actually need to be so I'm probably overlooking the obvious here, as well as not having any real experience with PHP.. all knowledge I have is from reading and editing existing code.. also forgive me for my awful attempts :P .. hopefully I've provided enough info to achieve what I am looking for!

 :tea: time!

testing123

  • Newbie
  • *
  • Posts: 43

Re: Connecting LevGal to SMFHacks Badge Awards
« Reply #2 on: April 04, 2015, 05:44:51 PM »
Wooooooo Hoooooooooo!


As always, I was overthinking everything... partly because I'm reading the code and not really knowing what each part does but I've solved it on my own :D

from the above code, replace as follows to have it work with levgal:

Code: [Select]
if (!in_array('gallery',$currentBadges) || !in_array('photographer',$currentBadges))
{

$result2 = $smcFunc['db_query']('', "
SELECT COUNT(*) AS total FROM {db_prefix}lgal_items
WHERE ID_MEMBER = $memberID");
$totalRow = $smcFunc['db_fetch_assoc']($result2);


$badgeAction = 'gallery';
if (!in_array($badgeAction,$currentBadges) && $totalRow['total'] >= 1)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}
// photographer
$badgeAction = 'photographer';
if (!in_array($badgeAction,$currentBadges) && $totalRow['total'] >= 10)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}


}

:D

Actually can't believe I got this working!
Now off to make a million more badges to 'win'!
 

SMF 2.0.9 | SMF © 2014, Simple Machines
BlueLight design by Bloc