T201704101427

This commit is contained in:
Leander
2017-04-10 14:27:20 +02:00
parent 5f31fbf929
commit bd0a35f594

View File

@@ -51,7 +51,7 @@ if($uid == '') {
$new_time = $old_time + $time;
$db->query('UPDATE "Games" SET "total_time" = $1 WHERE "ID" = $2', array($new_time, $uid));
//set highscore
//set category highscore
$cid = $db->query('SELECT "current_category" FROM "Games" WHERE "ID" = $1', array($uid))
['data'][0]['current_category'];
if($db->query('SELECT EXISTS (SELECT 1 FROM "Highscores" WHERE "Users_ID" = $1 AND "Categories_ID" = $2)',
@@ -64,7 +64,7 @@ if($uid == '') {
$db->query('UPDATE "Highscores" SET "score" = $1 WHERE "Users_ID" = $2 AND "Categories_ID" = $3',
array($new_high, $uid, $cid));
//create next question if existing, end object otherwise
//create next question if existing, end object otherwise - then set user highscore
if($db->query('SELECT EXISTS (SELECT 1 FROM "GamesQuestions" WHERE "Games_ID" = $1)',array($uid))
['data'][0]['exists'] == 't') {
$next_question = Question::get_next_question($db, $uid);
@@ -77,6 +77,9 @@ if($uid == '') {
'SELECT "highscore" FROM "Users" WHERE "ID" = $1',
array($uid)
)['data'][0]['highscore'];
$answered_questions = $db->query('SELECT "answered_questions" FROM "Games" WHERE "ID" = $1',
array($uid))['data'][0]['answered_questions'];
$new_points = round($new_points / $answered_questions);
$new_user_high = $old_user_high == 0 ? $new_points : round($old_user_high * 0.95 + $new_points * 0.05);
$db->query('UPDATE "Users" SET "highscore" = $1 WHERE "ID" = $2', array($new_user_high, $uid));
}