From 0fe8cc900298d9832c0360d6e1c1a2d51985a919 Mon Sep 17 00:00:00 2001 From: Leander Date: Mon, 27 Mar 2017 15:15:40 +0200 Subject: [PATCH] T1703271515 --- Config.txt | 5 ++++- Database.php | 8 +++++--- start.php | 11 +++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Config.txt b/Config.txt index a1d8fb8..d319ec4 100644 --- a/Config.txt +++ b/Config.txt @@ -7,4 +7,7 @@ = register.php = 11101 - User name doesn't match rules -11102 - User name already exists //TODO \ No newline at end of file +11102 - User name already exists + += start.php = +12101 - More questions wanted then existing \ No newline at end of file diff --git a/Database.php b/Database.php index c37b4cb..5dd804c 100644 --- a/Database.php +++ b/Database.php @@ -33,14 +33,14 @@ class Database return $query_response; } - function create_response($data, $error) { - $status_message = Database::create_status_code($error); + function create_response($data, $error, $values = null) { + $status_message = Database::create_status_code($error, $values); $meta = array('status'=>$error, 'message'=>$status_message); $response_element_json = json_encode(array('meta'=>$meta, 'data'=>$data), JSON_PRETTY_PRINT); return $response_element_json; } - function create_status_code($error) { + function create_status_code($error, $values) { switch ($error) { case 0: return 'Success.'; @@ -50,6 +50,8 @@ class Database return 'User name does not match rules. User name must be 6 to 20 characters and consist of English letters and numbers only.'; case 11102: return 'User name already exists. Please pick a different name.'; + case 12101: + return 'We only have '.$values[0].' questions. Please select new game length.'; default: return 'An unknown error occurred.'; } diff --git a/start.php b/start.php index 8193e9f..90113d8 100644 --- a/start.php +++ b/start.php @@ -7,10 +7,17 @@ */ require_once('includes.inc.php'); + $data = ''; + $error = 0; + $values = null; $uid = $_GET['uid']; $length = ($_GET['length'] && gettype(+$_GET['length']) == 'integer') ? +$_GET['length'] : 10; $database = new Database(); - $questions_count = $database->query('SELECT COUNT(*) FROM "Questions"')['data'][0]['count']; - echo($questions_count); + + if($length > $questions_count) { + $error = 12101; + $values = array($questions_count); + } + Database::create_response($data, $error, $values); ?> \ No newline at end of file