Customizing SMF > Tips and Tricks

Limiting Karma points to one per user?

(1/1)

Adrift:
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

Oldiesmann:
Yeah, it's possible. First, comment out the following db query in Sources/Karma.php:


--- Code: --- // 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__);
--- End code ---

And then

Find

--- Code: --- // 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' => '-'));
--- End code ---

Replace:

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

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.

Navigation

[0] Message Index

Go to full version