Time left for karma

Started by Lisah746, October 07, 2005, 08:05:42 AM

Previous topic - Next topic

Lisah746

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

Oldiesmann

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.
Michael Eshom
Christian Metal Fans

Elmacik

#2
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
Home of Elmacik

Oldiesmann

That's the wait time. It specifies how long (in hours) people have to wait between consecutive Karma actions on the same person.
Michael Eshom
Christian Metal Fans

Elmacik

and isnt this what Lisah746 asked for anyway?
i am confused now :P
Home of Elmacik

Lisah746

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.

Elmacik

hmm sorry, i newly got the point
Home of Elmacik

Oldiesmann

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.
Michael Eshom
Christian Metal Fans

JayBachatero

I think this should be added to the Tips and tricks board.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

Home of Elmacik

Lisah746

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.

Lisah746

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?

JayBachatero

Can you post the block of code from line 115 to 120?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Jack.R.Abbit™

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));

Oldiesmann

Yep. It should be. Thanks Jack :)
Michael Eshom
Christian Metal Fans

Lisah746

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.

Moocat

excellent trick :) i am using it now! ;D

Hoochie Coochie Man

I've got the following error.  :-\


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

Any ideas?  :-\
İnadına SMF 1.1.X

De4thPr00f

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...

Rumbaar

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.
"An important reward for a job well done is a personal sense of worthwhile achievement."


[ Themes ]

Advertisement: