T1703312158

This commit is contained in:
Leander
2017-03-31 21:58:42 +02:00
parent 3fb0f3e88c
commit c605f1451f
2 changed files with 13 additions and 10 deletions

View File

@@ -14,6 +14,10 @@
$uid = md5(uniqid(rand(), true));
$database = new Database();
$numbers = range(0, 19);
shuffle($numbers);
print numbers;
if(preg_match(PATTERN, $name) != 1 or !$name) {
$error = 11101;
} else {

View File

@@ -16,25 +16,24 @@
$database = new Database();
$questions_count = $database->query('SELECT COUNT(*) FROM "Questions"')['data'][0]['count'];
function create_game($length) {
for($i = 0; $i < $length; $i++) {
do {
} while(pg_last_error != '');
}
}
if($length == 0) {
$error = 12101;
} else if($length > $questions_count) {
$error = 12102;
$values = array($questions_count);
} else {
if($database->query('SELECT EXISTS (SELECT 1 fROM "Games" WHERE "ID" = $1)', array($uid)) == 't') {
if($database->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)) == 't') {
$database->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid));
}
$database->query('INSERT INTO "Games" ("ID") VALUES ($1)', array($uid));
create_game($length);
for($i = 0; $i < $length; $i++) {
do {
$offset = rand(0, $questions_count-1);
$question = $database->query('SELECT "ID" FROM "Questions" OFFSET $1 LIMIT 1', array($offset));
$database->query('INSERT INTO "GamesQuestions" ("Games_ID", "Questions_ID") VALUES ($1, $2)',
array($uid, $question));
} while(pg_last_error != '');
}
}
$response = Database::create_response($data, $error, $values);
print $response;