Skip to content

Commit

Permalink
enforce default behavior of not granting points for self-answers bein…
Browse files Browse the repository at this point in the history
…g selected
  • Loading branch information
ansgarwiechers committed Oct 1, 2020
1 parent a1e5701 commit b6eb82d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions points.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@
function qa_db_points_calculations() {
$points_calculations = qa_db_points_calculations_base();

// Don't grant points for selecting a self-answer.
if (array_key_exists('aselects', $points_calculations)) {
$points_calculations['aselects']['formula'] = "COUNT(*) AS aselects FROM ^posts AS userid_src JOIN ^posts AS answers ON userid_src.selchildid=answers.postid WHERE userid_src.userid~ AND userid_src.type='Q' AND (answers.userid <=> userid_src.userid)";
} else {
// if key 'aselects' is missing: throw a warning, but continue regardless
trigger_error("Missing key 'aselects' in points calculations array", E_USER_WARNING);
}

// Also don't grant points for a self-answer being selected.
// This already is the default behavior, but we enforce it here so that
// changing the default behavior wouldn't break the functionality of this
// plugin.
if (array_key_exists('aselecteds', $points_calculations)) {
$points_calculations['aselecteds']['formula'] = "COUNT(*) AS aselecteds FROM ^posts AS userid_src JOIN ^posts AS questions ON questions.selchildid=userid_src.postid WHERE userid_src.userid~ AND userid_src.type='A' AND NOT (questions.userid <=> userid_src.userid)";
} else {
// if key 'aselecteds' is missing: throw a warning, but continue regardless
trigger_error("Missing key 'aselecteds' in points calculations array", E_USER_WARNING);
}

return $points_calculations;
}

0 comments on commit b6eb82d

Please sign in to comment.