55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: leanderschmedemann
|
|
* Date: 10.04.17
|
|
* Time: 13:24
|
|
*/
|
|
|
|
require_once('includes.inc.php');
|
|
$data = array();
|
|
$error = 0;
|
|
$cid = isset($_GET['category']) ? $_GET['category'] : -1;
|
|
$limit = isset($_GET['limit']) ? $_GET['limit'] : 10;
|
|
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
|
|
$db = new Database();
|
|
|
|
if($cid == -1) {
|
|
$overview = $db->query('SELECT "name", "highscore" FROM "Users" ORDER BY "highscore" DESC
|
|
LIMIT $1 OFFSET $2', array($limit, $offset))['data'];
|
|
foreach($overview as $row) {
|
|
$name = $row['name'];
|
|
$score = $row['highscore'];
|
|
$place = $db->query('SELECT COUNT(*) FROM "Users" WHERE "highscore" > $1', array($score))['data'][0]['count'] + 1;
|
|
$data[] = array('place' => $place, 'name' => $name, 'score' => $score);
|
|
}
|
|
} else {
|
|
$overview = $db->query('SELECT u."name", h."score" ISNULL(h."score", -1)
|
|
FROM "Users" u LEFT OUTER JOIN "Highscores" h ON u."ID" = h."Users_ID"
|
|
WHERE h."Categories_ID" = $1
|
|
ORDER BY h."score" DESC
|
|
LIMIT $2 OFFSET $3', array($cid, $limit, $offset))['data'];
|
|
foreach($overview as $row) {
|
|
$name = $row['name'];
|
|
//$score = ($row['score'] == NULL) ? -1 : $row['score'];
|
|
$place = $db->query('SELECT COUNT(*) FROM "Highscores" WHERE "score" > $1 AND "Categories_ID" = $2',
|
|
array($score, $cid))['data'][0]['count'] + 1;
|
|
$data[] = array('place' => $place, 'name' => $name, 'score' => $score);
|
|
}
|
|
/*
|
|
$all_cat_highscores = $db->query('SELECT COUNT(*) FROM "Highscores" WHERE "Categories_ID" = $1', array($cid))
|
|
['data'][0]['count'];
|
|
$all_users = $db->query('SELECT "ID", "name" FROM "Users" ORDER BY "name"')['data'];
|
|
foreach($all_users as $user) {
|
|
if($db->query('SELECT EXISTS (SELECT * FROM "Highscores" WHERE "Users_ID" = $1 AND "Categories_ID" = $2)',
|
|
array($user['ID'], $cid))['data'][0]['exists'] == 'f') {
|
|
$name = $user['name'];
|
|
$score = -1;
|
|
$place = $all_cat_highscores + 1;
|
|
$data[] = array('place' => $place, 'name' => $name, 'score' => $score);
|
|
}
|
|
}*/
|
|
}
|
|
|
|
$response = Database::create_response($data, $error);
|
|
print_r($response); |