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

Tim99’s picture

This is the solution:

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 != goals2 AND ( ( (goals1 - goals2) = (%d - %d) ) OR (goals2 - goals1) = (%d - %d))THEN 2 
			WHEN goals1 %s goals2 THEN 1 
			ELSE 0 
			END 
			WHERE mid = %d', $match['goals1'], $match['goals2'], $match['goals1'], $match['goals2'], $match['goals2'], $match['goals1'], $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);
  }
}

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?

EgonO’s picture

someone should add this to the module. i think this is a nice idea...

Tim99’s picture

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