Fertig
This commit is contained in:
@@ -69,7 +69,10 @@ if($uid == '') {
|
|||||||
$end = array('score' => $new_points, 'time' => $new_time);
|
$end = array('score' => $new_points, 'time' => $new_time);
|
||||||
$data = array('results' => $results, 'end' => $end);
|
$data = array('results' => $results, 'end' => $end);
|
||||||
$db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid));
|
$db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid));
|
||||||
$old_user_high = $db->query('SELECT "highscore" FROM "Users" WHERE "ID" = $1', array($uid));
|
$old_user_high = $db->query(
|
||||||
|
'SELECT "highscore" FROM "Users" WHERE "ID" = $1',
|
||||||
|
array($uid)
|
||||||
|
)['data'][0]['highscore'];
|
||||||
$new_user_high = $old_user_high == 0 ? $new_points : intval($old_user_high * 0.95 + $new_points * 0.05);
|
$new_user_high = $old_user_high == 0 ? $new_points : intval($old_user_high * 0.95 + $new_points * 0.05);
|
||||||
$db->query('UPDATE "Users" SET "highscore" = $1 WHERE "ID" = $1', array($uid));
|
$db->query('UPDATE "Users" SET "highscore" = $1 WHERE "ID" = $1', array($uid));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,23 +12,32 @@ $error = 0;
|
|||||||
$uid = isset($_GET['uid']) ? $_GET['uid'] : '';
|
$uid = isset($_GET['uid']) ? $_GET['uid'] : '';
|
||||||
$db = new Database();
|
$db = new Database();
|
||||||
|
|
||||||
$categories[] = array('id' => 1, 'name' => "BWL", 'score' => 321, 'place' => 123);
|
|
||||||
$categories[] = array('id' => 2, 'name' => "Mathematik", 'score' => 1454, 'place' => 1);
|
|
||||||
$info = array('score' => 3253, 'place' => 122, 'all' => 321, 'categories' => $categories);
|
|
||||||
|
|
||||||
$response = Database::create_response($info, $error);
|
|
||||||
print_r($response);
|
|
||||||
|
|
||||||
if($uid == '') {
|
if($uid == '') {
|
||||||
$error = 15101;
|
$error = 15101;
|
||||||
} else if($db->query('SELECT EXISTS (SELECT 1 FROM "Users" WHERE "ID" = $1)', array($uid))
|
} else if($db->query('SELECT EXISTS (SELECT 1 FROM "Users" WHERE "ID" = $1)', array($uid))
|
||||||
['data']['0']['exists'] == 'f') {
|
['data']['0']['exists'] == 'f') {
|
||||||
$error = 15102;
|
$error = 15102;
|
||||||
} else {
|
} else {
|
||||||
$score = $db->query('SELECT "highscore" FROM "Users" WHERE "ID" = $1', array($uid))['data'][0]['highscore'];
|
$score_all = $db->query('SELECT "highscore" FROM "Users" WHERE "ID" = $1', array($uid))['data'][0]['highscore'];
|
||||||
$all = $db->query('SELECT COUNT (*) FROM "Users"')['data']['0']['count'];
|
$all = $db->query('SELECT COUNT (*) FROM "Users"')['data'][0]['count'];
|
||||||
echo 'Score: '.$score;
|
$place_all = $db->query('SELECT COUNT (*) FROM "Users" WHERE "highscore" > $1', array($score))['data'][0]['count'] + 1;
|
||||||
print 'All: '.$all;
|
//get categories highscores
|
||||||
|
$categories = $db->query('SELECT "ID", "name" from "Categories"')['data'];
|
||||||
|
foreach($categories as $category) {
|
||||||
|
$cid = $category['ID'];
|
||||||
|
$cat = $category['name'];
|
||||||
|
$score = $db->query('SELECT "score" FROM "Highscores" WHERE "Users_ID" = $1 AND "Categories_ID" = $2',
|
||||||
|
array($uid, $cid)['data'][0]['score']);
|
||||||
|
$place = $db->query(
|
||||||
|
'SELECT COUNT (*) FROM "Highscores"
|
||||||
|
WHERE "Users_ID" = $1 AND "Categories_ID" = $2 AND "score" > $3',
|
||||||
|
array($uid, $cid, $score));
|
||||||
|
$cat_scores[] = array('id' => $cid, 'name' => $cat, 'score' => $score, 'place' => $place);
|
||||||
|
}
|
||||||
|
$data = array('score' => $score_all, 'place' => $place_all, 'all' => $all, 'categories' => $categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$response = Database::create_response($data, $error);
|
||||||
|
print_r($response);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user