T201704032327
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
11102 - User name already exists
|
11102 - User name already exists
|
||||||
|
|
||||||
= start.php =
|
= start.php =
|
||||||
12101 - 0 questions wanted, no game without a question!
|
12101 - User ID not specified
|
||||||
12102 - More questions wanted then existing
|
12102 - 0 questions wanted, no game without a question!
|
||||||
12103 - User ID not specified
|
12103 - More questions wanted then existing
|
||||||
|
12104 - User name not existing
|
||||||
|
|||||||
11
Database.php
11
Database.php
@@ -42,6 +42,9 @@ class Database
|
|||||||
static function create_response($data, $error, $values = null) {
|
static function create_response($data, $error, $values = null) {
|
||||||
$status_message = Database::create_status_code($error, $values);
|
$status_message = Database::create_status_code($error, $values);
|
||||||
$meta = array('status'=>$error, 'message'=>$status_message);
|
$meta = array('status'=>$error, 'message'=>$status_message);
|
||||||
|
if($error == 0){
|
||||||
|
$data = '';
|
||||||
|
}
|
||||||
$response_element_json = json_encode(array('meta'=>$meta, 'data'=>$data), JSON_PRETTY_PRINT);
|
$response_element_json = json_encode(array('meta'=>$meta, 'data'=>$data), JSON_PRETTY_PRINT);
|
||||||
return $response_element_json;
|
return $response_element_json;
|
||||||
}
|
}
|
||||||
@@ -58,11 +61,13 @@ class Database
|
|||||||
case 11102:
|
case 11102:
|
||||||
return 'User name already exists. Please pick a different name.';
|
return 'User name already exists. Please pick a different name.';
|
||||||
case 12101:
|
case 12101:
|
||||||
return 'A game without a question is not possible. Please select new game length.';
|
return 'User name not specified. This is an internal error.';
|
||||||
case 12102:
|
case 12102:
|
||||||
return 'We only have '.$values[0].' questions. Please select new game length.';
|
return 'A game without a question is not possible. Please select new game length.';
|
||||||
case 12103:
|
case 12103:
|
||||||
return 'No user ID specified. Sebastian, please fix the app.';
|
return 'Sorry, we only have '.$values[0].' questions. Please try again.';
|
||||||
|
case 12104:
|
||||||
|
return 'The specified user name does not exist.';
|
||||||
default:
|
default:
|
||||||
return 'An unknown error occurred.';
|
return 'An unknown error occurred.';
|
||||||
}
|
}
|
||||||
|
|||||||
10
start.php
10
start.php
@@ -24,11 +24,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($uid == '') {
|
if($uid == '') {
|
||||||
$error = 12103;
|
|
||||||
} else if($length == 0) {
|
|
||||||
$error = 12101;
|
$error = 12101;
|
||||||
} else if($length > $questions_count) {
|
} else if($length == 0) {
|
||||||
$error = 12102;
|
$error = 12102;
|
||||||
|
} else if($length > $questions_count) {
|
||||||
|
$error = 12103;
|
||||||
$values = array($questions_count);
|
$values = array($questions_count);
|
||||||
} else {
|
} else {
|
||||||
// Delete existing game for user.
|
// Delete existing game for user.
|
||||||
@@ -37,7 +37,9 @@
|
|||||||
}
|
}
|
||||||
// Create new game for user.
|
// Create new game for user.
|
||||||
$db->query('INSERT INTO "Games" ("ID") VALUES ($1)', array($uid));
|
$db->query('INSERT INTO "Games" ("ID") VALUES ($1)', array($uid));
|
||||||
print_r(pg_last_error());
|
if(preg_match('/violates foreign key constraint "Games_ID_fkey"/', pg_last_error()) == 1) {
|
||||||
|
$error = 12104;
|
||||||
|
}
|
||||||
// Find questions for new game and insert into table.
|
// Find questions for new game and insert into table.
|
||||||
$questions = random_numbers(0, $questions_count-1, $length);
|
$questions = random_numbers(0, $questions_count-1, $length);
|
||||||
foreach($questions as $question) {
|
foreach($questions as $question) {
|
||||||
|
|||||||
Reference in New Issue
Block a user