Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Adrift on May 31, 2004, 10:31:09 AM

Title: Limiting Karma points to one per user?
Post by: Adrift on May 31, 2004, 10:31:09 AM
I would like to set it up so users can only give one karma point to other users - a positive or negative. That way the total possible number of karma points any single user has can not be larger than the total number of users.

I'm currently doing something like this by setting wait time to 2147483647 hours, but is there a more elegant solution?
Thanks
Adrift
Title: Re: Limiting Karma points to one per user?
Post by: Oldiesmann on May 31, 2004, 07:59:16 PM
Yeah, it's possible. First, comment out the following db query in Sources/Karma.php:

// Delete any older items from the log. (karmaWaitTime is by hour.)
db_query("
DELETE FROM {$db_prefix}log_karma
WHERE " . time() . " - logTime > " . ($modSettings['karmaWaitTime'] * 3600), __FILE__, __LINE__);


And then

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

// You decided to go back on your previous choice?
db_query("
UPDATE {$db_prefix}log_karma
SET action = $dir, logTime = " . time() . "
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);

// It was recently changed the OTHER way... so... reverse it!
if ($dir == 1)
updateMemberData($_REQUEST['uid'], array('karmaGood' => '+', 'karmaBad' => '-'));
else
updateMemberData($_REQUEST['uid'], array('karmaBad' => '+', 'karmaGood' => '-'));


Replace:
fatal_error('Sorry. You have already applauded or smitten this user. You cannot do this again.', false);

The only thing you might want to do is add some javascript to warn the person that they will not be allowed to undo that action.