News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Members time Online - Where to find in the database ??

Started by 420Connect.co.uk, April 04, 2015, 03:48:00 PM

Previous topic - Next topic

420Connect.co.uk

Hey,

I'm trying to add some custom code into a badge awards mod to award a badge that would "trigger" when a users logged in time reached a certain amount.. (say 24hours?)

Could anyone point me in the direction where this is stored or is there some crazy math related php used to display the most time online, found on the stats page?

Cheers
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Pipke

Try this

1 day = $context['user']['total_time_logged_in']['days'] >= 1
2 day's = $context['user']['total_time_logged_in']['days'] >= 2
etc, etc


global $context;

if ($context['user']['total_time_logged_in']['days'] >= 1)
       echo 'Hey, it seems you spent more then 24 hours on this website.';
else
       echo 'Your not online that much here!!';

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

420Connect.co.uk

I've found in Stats.php a similar looking bit of code to what I am after, but converting it to how I need it is really confusing to say the least!

Your way might be easier and/or needed though..

Heres some code parts..

This is from Stats.php to grab / sort the members who have been been logged in the longest..

// Time online top 10.
$temp = cache_get_data('stats_total_time_members', 600);
$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, total_time_logged_in
FROM {db_prefix}members' . (!empty($temp) ? '
WHERE id_member IN ({array_int:member_list_cached})' : '') . '
ORDER BY total_time_logged_in DESC
LIMIT 20',
array(
'member_list_cached' => $temp,
)
);
$context['top_time_online'] = array();
$temp2 = array();
$max_time_online = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
$temp2[] = (int) $row_members['id_member'];
if (count($context['top_time_online']) >= 10)
continue;

// Figure out the days, hours and minutes.
$timeDays = floor($row_members['total_time_logged_in'] / 86400);
$timeHours = floor(($row_members['total_time_logged_in'] % 86400) / 3600);

// Figure out which things to show... (days, hours, minutes, etc.)
$timelogged = '';
if ($timeDays > 0)
$timelogged .= $timeDays . $txt['totalTimeLogged5'];
if ($timeHours > 0)
$timelogged .= $timeHours . $txt['totalTimeLogged6'];
$timelogged .= floor(($row_members['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged7'];

$context['top_time_online'][] = array(
'id' => $row_members['id_member'],
'name' => $row_members['real_name'],
'time_online' => $timelogged,
'seconds_online' => $row_members['total_time_logged_in'],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);

if ($max_time_online < $row_members['total_time_logged_in'])
$max_time_online = $row_members['total_time_logged_in'];
}



This is an example of a working badge award code:

//start of first badge
if (!in_array('tags',$currentBadges))
{

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


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

}


}
//end of first badge




& This is what I've got in the making but like I said I really have no idea what I'm doing :P

//start of new badge
if (!in_array('neversleep',$currentBadges))
{

$resultgroup = $smcFunc['db_query']('', "
SELECT id_member, total_time_logged_in
FROM {db_prefix}members
WHERE ID_MEMBER = $memberID And TOTAL_TIME_LOGGED_IN = $twentyfourlogged
");

$badgeAction = 'neversleep';
if (!in_array($badgeAction,$currentBadges) && $twentyfourlogged >= 1140)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[]  = $badgeAction;
}

}


}
//end of new badge



Appreciated if anyone can give it a shot! :)
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Jade Elizabeth

What mod is this? Do they have a support topic you could ask in or a way to add badges? It seems like time online would be a badge they would include is all.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

total_time_logged_in is already fetched normally by member in Load.php, directly into $user_info

The code you have for stats uses cache and so forth because it wants to save queries but for what you want to do there is already data available per member.

If you only want to have that "badge" to show in Display and Profile, it should be simpler than that. If you want a "full-featured" awards MOD time-based, then you probably want to pick an existing MOD and adapt it (or have the author to help you) to fit your needs.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

420Connect.co.uk

Thanks for the replies!

I've actually since came up with a solution for that particular badge, and the badge awards mod I am using is by the 'SMF Hacks Team'.
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Diego Andrés


SMF Tricks - Free & Premium Responsive Themes for SMF.

420Connect.co.uk

Do you mean marking this topic 'solved'? - Yes I did that today

& Yes, I solved my perticular mod problem.. / found where I was going wrong with my coding
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Jade Elizabeth

Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

420Connect.co.uk

My example would only really work with perticular badge mod I am using I assume but guess it could be easily altered to suit someones needs..

//start
if (!in_array('neversleep',$currentBadges))
{

$resultgroup = $smcFunc['db_query']('', "
SELECT COUNT(*) AS total FROM {db_prefix}members
WHERE ID_MEMBER = $memberID AND TOTAL_TIME_LOGGED_IN >= 86400
");
$totalRow = $smcFunc['db_fetch_assoc']($resultgroup);


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

}


}
//end


Basically if a member's logged in time = 86400 (number of seconds in a day) = they are rewarded with the badge

Part of my problem was before realising the logged in time was stored in seconds  ::)
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Jade Elizabeth

Ahh ok, what's the badge mod so others can use it? Thanks for sharing it, this will be sure to help someone out!!
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

420Connect.co.uk

The one I am using/referring to is this one: http://www.smfhacks.com/badgeawards.php
although I believe there are similar free alternatives available! :)

PS: Awesome little site you've got Jade!  :D I really like how much customisation has gone into it! (it doesn't feel like an SMF based site at all!?!) .. (http://www.creativeburrow.org/)
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Jade Elizabeth

It's definitely SMF, take a look at the stats page ha ha. But I have redone a lot of the templates, yeah :D. And thank you! It's my pride and joy :D.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Advertisement: