Add: test_db_connect_manager

This commit is contained in:
2018-05-24 17:27:01 +09:00
parent e982ee4381
commit 8e2cf7f38f
10 changed files with 256 additions and 24 deletions
+7 -7
View File
@@ -22,13 +22,13 @@ const GAME_SCREEN_SIZE = { x: 1024, y: 768 }
let sessionStorageManager = new SessionStorageManager();
{
if(isDebugMode()) {
sessionStorageManager.playerName = "부현율";
sessionStorageManager.playerUserID = 8;
sessionStorageManager.playingAppName = "space_invaders";
sessionStorageManager.score = 1000;
sessionStorageManager.highScore = 2000;
}
// if(isDebugMode()) {
// sessionStorageManager.playerName = "부현율";
// sessionStorageManager.playerUserID = 8;
// sessionStorageManager.playingAppName = "space_invaders";
// sessionStorageManager.score = 1000;
// sessionStorageManager.highScore = 2000;
// }
console.log("maestroID : " + sessionStorageManager.maestroID);
console.log("playerName : " + sessionStorageManager.playerName);
+45 -11
View File
@@ -1,16 +1,21 @@
class DBConnectManager {
constructor() {
this.path = this.getPath();
this.directoryName = this.getDirectoryName(this.path);
this.phpPath = this.getPHPPath(this.directoryName);
this.maestroID = 0;
this.playerUserID = 0;
this.appName = "";
this.dateAndTime = null;
}
setMaestro(maestroID) {
setMaestroID(maestroID) {
this.maestroID = maestroID;
}
setPlayer(userID) {
setPlayerID(userID) {
this.playerUserID = userID;
}
@@ -18,9 +23,33 @@ class DBConnectManager {
this.appName = appName;
}
setDateTime(date, time) {
this.dateAndTime = date + time;
}
resetDateTime() {
this.dateAndTime = null;
}
getPath() {
return window.location.pathname;
}
getDirectoryName(path) {
let pathAndFileNames = path.split("/");
return pathAndFileNames[pathAndFileNames.length - 2];
}
getPHPPath(directoryName) {
if(directoryName === "test") // mouse_typing/test/
return "../src/web/";
else // mousetyping/src/web/client/
return "../";
}
requestCheckUserLogin(userName, enterCode, onSucceededListener, onFailedListener) {
let xhr = new XMLHttpRequest();
xhr.open("POST", "../../web/server/user/login.php", true);
xhr.open("POST", this.phpPath + "server/user/login.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
@@ -32,7 +61,7 @@ class DBConnectManager {
onFailedListener(jsonData);
}
};
xhr.send("name=" + sessionStorageManager.playerName + "&enter_code=" + enterCode);
xhr.send("name=" + userName + "&enter_code=" + enterCode);
}
requestPlayerHistory(listener) {
@@ -52,7 +81,7 @@ class DBConnectManager {
let self = this;
let xhr = new XMLHttpRequest();
xhr.open("POST", "../../web/server/record/history_record.php", true);
xhr.open("POST", this.phpPath + "server/record/history_record.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
@@ -128,7 +157,7 @@ class DBConnectManager {
let self = this;
let xhr = new XMLHttpRequest();
xhr.open("POST", this.getPHPUrl(type), true);
xhr.open("POST", this.getRankingRecordUrl(type), true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
@@ -146,22 +175,27 @@ class DBConnectManager {
xhr.send(params);
}
getPHPUrl(type) {
getRankingRecordUrl(type) {
let rankingRecordURL = this.phpPath;
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
return "../../web/server/record/ranking_hour_record.php";
rankingRecordURL += "server/record/ranking_record_hour.php";
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
return "../../web/server/record/ranking_day_record.php";
rankingRecordURL += "server/record/ranking_record_day.php";
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
return "../../web/server/record/ranking_month_record.php";
rankingRecordURL += "server/record/ranking_record_month.php";
break;
}
return "";
return rankingRecordURL;
}
parseJSONtoRankingRecord(type, json) {
+1 -1
View File
@@ -14,7 +14,7 @@ class HistoryBoard {
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
this.dbConnectManager.requestPlayerHistory( historyRecordManager => {
let maxIndex = historyRecordManager.count;
let maxIndex = historyRecordManager.count - 1;
if(maxIndex > 6)
maxIndex = 6;
@@ -0,0 +1,49 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking month
/*
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
*/
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH('2018-05-18') AND AppName = 'korean_word'
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingMonth'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>