Active
Project:
Tipping
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Jun 2008 at 14:19 UTC
Updated:
3 Jun 2008 at 07:59 UTC
This is the function that is responsibly for the score a user receives:
function tipping_update_scores($matches) {
foreach ($matches as $mid => $match) {
$comparision = $match['goals1'] == $match['goals2'] ? '=' : ($match['goals1'] > $match['goals2'] ? '>' : '<');
db_query('
UPDATE {tipping_tips}
SET score = CASE
WHEN goals1 = %d AND goals2 = %d THEN 3
WHEN goals1 %s goals2 THEN 1
ELSE 0
END
WHERE mid = %d', $match['goals1'], $match['goals2'], $comparision, $mid);
}
$result = db_query('SELECT uid, SUM(score) AS sum FROM {tipping_tips} GROUP BY uid');
$scores = array();
while ($score = db_fetch_object($result)) {
db_query('UPDATE {tipping_players} SET score = %d WHERE uid = %d', $score->sum, $score->uid);
}
}
In short:
- Correct winner/draw --> 1 point
- 100% Correct result --> 3 points
Now I'd like to add a rule that a user receives 2 points if
- The game is not a draw AND the goal difference was correct (i.e. the tip was 2:0 and the result was 3:1).
I assume it's only one line between the 2 WHEN statements.
Would somebody please be so kind to write down that line?
Of course this could be made configurable.
Comments
Comment #1
Tim99 commentedThis is the solution:
I inserted an additional WHEN statement and added some parameters.
Unfortunately I had to insert the OR-part, because otherwise 2:0 and 3:1 would work, but not 0:2 and 1:3. Don't know why... Can't this system deal with negative values?
Comment #2
EgonO commentedsomeone should add this to the module. i think this is a nice idea...
Comment #3
Tim99 commentedIt is safe to replace the function
tipping_update_scores($matches)in tipping.module with the function above. You don't have to re-install the module.