Commit f5b99cb0 by Scott

Comment voting recalc

parent e871abe5
......@@ -105,6 +105,16 @@ function qa_db_points_calculations()
'formula' => "COUNT(*) AS adownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='A' AND userid_src.vote<0",
),
'cupvotes' => array(
'multiple' => 0,
'formula' => "COUNT(*) AS cupvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='C' AND userid_src.vote>0",
),
'cdownvotes' => array(
'multiple' => 0,
'formula' => "COUNT(*) AS cdownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='C' AND userid_src.vote<0",
),
'qvoteds' => array(
'multiple' => $options['points_multiple'],
'formula' => "COALESCE(SUM(" .
......@@ -123,6 +133,15 @@ function qa_db_points_calculations()
"), 0) AS avoteds FROM ^posts AS userid_src WHERE LEFT(type, 1)='A' AND userid~",
),
'cvoteds' => array(
'multiple' => $options['points_multiple'],
'formula' => "COALESCE(SUM(" .
"LEAST(" . ((int)$options['points_per_c_voted_up']) . "*upvotes," . ((int)$options['points_c_voted_max_gain']) . ")" .
"-" .
"LEAST(" . ((int)$options['points_per_c_voted_down']) . "*downvotes," . ((int)$options['points_c_voted_max_loss']) . ")" .
"), 0) AS cvoteds FROM ^posts AS userid_src WHERE LEFT(type, 1)='C' AND userid~",
),
'upvoteds' => array(
'multiple' => 0,
'formula' => "COALESCE(SUM(upvotes), 0) AS upvoteds FROM ^posts AS userid_src WHERE userid~",
......
......@@ -282,24 +282,26 @@ function qa_db_users_recalc_points($firstuserid, $lastuserid)
);
$zeropoints = 'points=0';
foreach ($qa_userpoints_calculations as $field => $calculation)
foreach ($qa_userpoints_calculations as $field => $calculation) {
$zeropoints .= ', ' . $field . '=0';
}
qa_db_query_sub(
'UPDATE ^userpoints SET ' . $zeropoints . ' WHERE userid>=# AND userid<=#', // zero out the rest
$firstuserid, $lastuserid
);
if (QA_FINAL_EXTERNAL_USERS)
if (QA_FINAL_EXTERNAL_USERS) {
qa_db_query_sub(
'INSERT IGNORE INTO ^userpoints (userid) SELECT DISTINCT userid FROM ^posts WHERE userid>=# AND userid<=# UNION SELECT DISTINCT userid FROM ^uservotes WHERE userid>=# AND userid<=#',
$firstuserid, $lastuserid, $firstuserid, $lastuserid
);
else
} else {
qa_db_query_sub(
'INSERT IGNORE INTO ^userpoints (userid) SELECT DISTINCT userid FROM ^users WHERE userid>=# AND userid<=#',
$firstuserid, $lastuserid
);
}
$updatepoints = (int)qa_opt('points_base');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment