Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Lisah746 on October 07, 2005, 08:05:42 AM

Title: Time left for karma
Post by: Lisah746 on October 07, 2005, 08:05:42 AM
I have had this request from many of my users and thought it might be interesting to post here.

Once someone has given karma they are restricted from giving karma to the same person for one hour. (my settings)

How about having a time left display. Something like....

"Sorry, you can't repeat a karma action without waiting 1 hour, you have 25 minutes left."

Or something like that.

Thanks,
Lisa
Title: Re: Time left for karma
Post by: Oldiesmann on October 08, 2005, 08:36:17 PM
Shouldn't be too hard to do. Unfortunately I'm not at home right now so I don't have a copy of SMF to look at... I'll try to post something tomorrow though.
Title: Re: Time left for karma
Post by: Elmacik on October 08, 2005, 08:46:15 PM
thanks Oldiesmann, it should be really nice
and should be added as a feature i think

edit: whats this option in Karma settings?
   Set wait time in hours
Title: Re: Time left for karma
Post by: Oldiesmann on October 08, 2005, 11:38:37 PM
That's the wait time. It specifies how long (in hours) people have to wait between consecutive Karma actions on the same person.
Title: Re: Time left for karma
Post by: Elmacik on October 08, 2005, 11:40:10 PM
and isnt this what Lisah746 asked for anyway?
i am confused now :P
Title: Re: Time left for karma
Post by: Lisah746 on October 12, 2005, 09:17:13 AM
Quote from: elmacik on October 08, 2005, 11:40:10 PM
and isnt this what Lisah746 asked for anyway?
i am confused now :P

I am asking for the time remaining before you can karma the same poster to be shown.
Title: Re: Time left for karma
Post by: Elmacik on October 12, 2005, 01:38:01 PM
hmm sorry, i newly got the point
Title: Re: Time left for karma
Post by: Oldiesmann on October 12, 2005, 02:02:49 PM
Sorry for not posting sooner Lisah. I forgot about this topic :)

Sources/Karma.php

Find
// Find out if this user has done this recently...
$request = db_query("
SELECT action
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
list ($action) = mysql_fetch_row($request);
mysql_free_result($request);


Replace
// Find out if this user has done this recently...
$request = db_query("
SELECT action, logTime
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
list ($action, $time) = mysql_fetch_row($request);
mysql_free_result($request);


Find
// If you are gonna try to repeat.... don't allow it.
if ($action == $dir)
fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . '.', false);


Replace
// If you are gonna try to repeat.... don't allow it.
if ($action == $dir)
{
// How much longer do they have to wait (in minutes)? Round to the nearest integer...
$waittime = round($modSettings['karmaWaitTime'] * 60) - ((time() - $time) / 60));
fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . ' (' . $waittime . ' more ' . $txt['totaltimelogged4'] . ')', false);
}


That will give them an (approximate) value. It rounds to the nearest integer, so the value could be off by as much as 30 seconds in either direction, but 30 seconds doesn't make that much of a difference anyway, so I don't think it's that important.
Title: Re: Time left for karma
Post by: JayBachatero on October 13, 2005, 12:06:27 AM
I think this should be added to the Tips and tricks board.
Title: Re: Time left for karma
Post by: Elmacik on October 13, 2005, 12:13:47 AM
Quote from: JayBachatero on October 13, 2005, 12:06:27 AM
I think this should be added to the Tips and tricks board.
+1
Title: Re: Time left for karma
Post by: Lisah746 on October 13, 2005, 10:06:30 AM
Quote from: elmacik on October 13, 2005, 12:13:47 AM
Quote from: JayBachatero on October 13, 2005, 12:06:27 AM
I think this should be added to the Tips and tricks board.
+1
+2 and maybe intergrated into the karma mod itself. Thanks Oldiesmann. As soon as I get it intergrated I'll let you know.
Title: Re: Time left for karma
Post by: Lisah746 on October 13, 2005, 04:50:17 PM
I added the code exactly as it appears here and got the following error.

Parse error: parse error, unexpected ')' in /home/lisah/public_html/Sources/Karma.php on line 118


Any ideas?
Title: Re: Time left for karma
Post by: JayBachatero on October 13, 2005, 06:21:54 PM
Can you post the block of code from line 115 to 120?
Title: Re: Time left for karma
Post by: Jack.R.Abbitâ„¢ on October 13, 2005, 06:34:55 PM
This line looks to be the problem:
$waittime = round($modSettings['karmaWaitTime'] * 60) - ((time() - $time) / 60));

I'll assume that the entire result should be rounded and the line should look like this:
$waittime = round(($modSettings['karmaWaitTime'] * 60) - ((time() - $time) / 60));
Title: Re: Time left for karma
Post by: Oldiesmann on October 14, 2005, 10:13:10 AM
Yep. It should be. Thanks Jack :)
Title: Re: Time left for karma
Post by: Lisah746 on October 16, 2005, 08:39:37 AM
Quote from: Jack.R.Abbit on October 13, 2005, 06:34:55 PM
This line looks to be the problem:
$waittime = round($modSettings['karmaWaitTime'] * 60) - ((time() - $time) / 60));

I'll assume that the entire result should be rounded and the line should look like this:
$waittime = round(($modSettings['karmaWaitTime'] * 60) - ((time() - $time) / 60));

Yep that did it! I did add to it 'Minutes Remaining' so it looks like.... Sorry you have 45 minutes remaining.

Thank-You everyone.
Title: Re: Time left for karma
Post by: Moocat on October 25, 2005, 10:35:48 PM
excellent trick :) i am using it now! ;D
Title: Re: Time left for karma
Post by: Hoochie Coochie Man on November 18, 2007, 07:20:53 PM
I've got the following error.  :-\


8: Undefined index: totaltimelogged4
Dosya: /home/blues/public_html/forum/Sources/Karma.php
on line: 111

Any ideas?  :-\
Title: Re: Time left for karma
Post by: De4thPr00f on November 30, 2007, 10:31:09 AM
If you have karma description log mod, and want to use this trick, this is what you need to replace.
Sources/Karma.php

Find
// Find out if this user has done this recently...
$request = db_query("
SELECT action
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
list ($action) = mysql_fetch_row($request);
mysql_free_result($request);


Replace
// Find out if this user has done this recently...
$request = db_query("
SELECT action, logTime
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
list ($action, $time) = mysql_fetch_row($request);
mysql_free_result($request);


Find
                // If you are gonna try to repeat.... don't allow it.
                if ($restricttime < $timelog)
                        fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . '.', false);


Replace
// If you are gonna try to repeat.... don't allow it.
if ($restricttime < $timelog)
{
// How much longer do they have to wait (in minutes)? Round to the nearest integer...
$waittime = $timelog - $restricttime;
$minutes = round(($waittime / 60));
fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . ' (' . $minutes . ' more minutes)', false);
}


Note: I had some troubles with the provided $waittime function referred a few posts ago, but this works perfect...
Title: Re: Time left for karma
Post by: Rumbaar on December 14, 2007, 04:13:26 AM
Quote from: Hoochie Coochie Man on November 18, 2007, 07:20:53 PM
I've got the following error.  :-\

8: Undefined index: totaltimelogged4
Dosya: /home/blues/public_html/forum/Sources/Karma.php
on line: 111

Any ideas?  :-\
Are you still experiencing this problem?

What is your current language settings.  Check you Index.english.php file to make sure it's present.  If you are using a language other than english, make sure you have the appropriate index.{language}.php file in your default language folder.
Title: Re: Time left for karma
Post by: Hoochie Coochie Man on December 14, 2007, 05:20:17 AM
Quote from: Rumbaar on December 14, 2007, 04:13:26 AM
Quote from: Hoochie Coochie Man on November 18, 2007, 07:20:53 PM
I've got the following error.  :-\

8: Undefined index: totaltimelogged4
Dosya: /home/blues/public_html/forum/Sources/Karma.php
on line: 111

Any ideas?  :-\
Are you still experiencing this problem?

What is your current language settings.  Check you Index.english.php file to make sure it's present.  If you are using a language other than english, make sure you have the appropriate index.{language}.php file in your default language folder.

That was an old post :)
I solved my problem!
Thankyou very much anyway :)
Title: Re: Time left for karma
Post by: robinrobin on February 10, 2009, 09:03:19 AM
But what about the function to be under a time-limit for each person You give a point separately, instead of not being able to give anyone else a point once You've given it to one person?
Title: Re: Time left for karma
Post by: folkandfaith on February 26, 2009, 09:49:15 PM
on Vbulletin boards you can change it where it is not a specific amount of time that one has to wait, but that one "must pass some reputation around before giving it to ABC person again". Is there a way to do that on SMF?
Title: Re: Time left for karma
Post by: Rumbaar on February 26, 2009, 10:02:26 PM
I can only think of a post count based option at the moment.

You might want to search some more or try the Mod Request section.