From 7341be330f49f5717bc4252f8887f26a93eb15ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 31 May 2018 17:47:11 +0900 Subject: [PATCH] Fix: request history and ranking record with maestroID --- src/game/lib/db_connect_manager.js | 10 ++++++---- src/game/result/history_board.js | 1 + src/game/result/ranking_board.js | 2 +- src/game/start/start.js | 1 + src/web/server/record/history_record.php | 9 +++++---- src/web/server/record/ranking_record_day.php | 9 +++++---- src/web/server/record/ranking_record_hour.php | 9 +++++---- src/web/server/record/ranking_record_month.php | 9 +++++---- test/test_db_connect_manager.js | 6 ++++++ 9 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 798a327..9d3a0b0 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -81,7 +81,7 @@ class DBConnectManager { xhr.send("maestro_id=" + maestroID); } - requestPlayerHistory(date, listener) { + requestPlayerHistory(maestroID, date, listener) { let historyRecordManager = new HistoryRecordManager(); /* @@ -111,7 +111,8 @@ class DBConnectManager { onFailedListener(replyJSON); } }; - let params = "AppID=" + sessionStorageManager.playingAppID + let params = "MaestroID=" + sessionStorageManager.maestroID + + "&AppID=" + sessionStorageManager.playingAppID + "&UserID=" + sessionStorageManager.playerUserID + "&Date=" + date; xhr.send(params); @@ -160,7 +161,7 @@ class DBConnectManager { */ } - requestRanking(type, date, time, listener) { + requestRanking(type, maestroID, date, time, listener) { let rankingRecordManager = new RankingRecordManager(); /* @@ -190,7 +191,8 @@ class DBConnectManager { onFailedListener(replyJSON); } }; - let params = "AppID=" + sessionStorageManager.playingAppID + let params = "MaestroID=" + sessionStorageManager.maestroID + + "&AppID=" + sessionStorageManager.playingAppID + "&Date=" + date + "&Time=" + time; xhr.send(params); diff --git a/src/game/result/history_board.js b/src/game/result/history_board.js index 5e26087..9b3caff 100644 --- a/src/game/result/history_board.js +++ b/src/game/result/history_board.js @@ -16,6 +16,7 @@ class HistoryBoard { let today = new Date(); let date = DateUtil.getYYYYMMDD(today); this.dbConnectManager.requestPlayerHistory( + sessionStorageManager.maestroID, date, historyRecordManager => { if(historyRecordManager.count == 0) { diff --git a/src/game/result/ranking_board.js b/src/game/result/ranking_board.js index d085d11..3ed4212 100644 --- a/src/game/result/ranking_board.js +++ b/src/game/result/ranking_board.js @@ -17,7 +17,7 @@ class RankingBoard { let date = DateUtil.getYYYYMMDD(today); let time = DateUtil.getHHMMSS(today); this.dbConnectManager.requestRanking( - type, date, time, + type, sessionStorageManager.maestroID, date, time, (type, rankingRecordManager) => { if(rankingRecordManager.count == 0) { console.log("ranking board - no data"); diff --git a/src/game/start/start.js b/src/game/start/start.js index 3005ca5..2ab8f10 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -28,6 +28,7 @@ class Start { let today = new Date(); let date = DateUtil.getYYYYMMDD(today); this.dbConnectManager.requestPlayerHistory( + sessionStorageManager.maestroID, date, historyRecordManager => { this.printChartBaseLine(); diff --git a/src/web/server/record/history_record.php b/src/web/server/record/history_record.php index dbeb430..e8139d5 100644 --- a/src/web/server/record/history_record.php +++ b/src/web/server/record/history_record.php @@ -3,6 +3,7 @@ header('Content-Type: application/json'); include "./../send_error_code.php"; +$maestro_id = $_POST["MaestroID"]; $app_id = $_POST["AppID"]; $user_id = $_POST["UserID"]; $date = $_POST["Date"]; @@ -10,7 +11,7 @@ $date = $_POST["Date"]; include "./../setup/connect_db.php"; -$replyJSON = get_history_record($app_id, $user_id, $date); +$replyJSON = get_history_record($maestro_id, $app_id, $user_id, $date); if($replyJSON.length === 0) { send_error_message($replyJSON, "히스토리 기록 없음"); $db_conn->close(); @@ -21,20 +22,20 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); $db_conn->close(); -function get_history_record($app_id, $user_id, $date) { +function get_history_record($maestro_id, $app_id, $user_id, $date) { global $db_conn; $query = " SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName FROM moty_best_record BR INNER JOIN moty_app AS AA - ON BR.UserID = ? AND DATE(BR.RecordDateTime) < ? AND BR.AppID = ? AND BR.AppID = AA.AppID + ON BR.MaestroID = ? AND BR.UserID = ? AND DATE(BR.RecordDateTime) < ? AND BR.AppID = ? AND BR.AppID = AA.AppID GROUP BY DATE(BR.RecordDateTime) ORDER BY BR.RecordDateTime DESC LIMIT 7 "; $stmt = $db_conn->prepare($query); - $stmt->bind_param('isi', $user_id, $date, $app_id); + $stmt->bind_param('iisi', $maestro_id, $user_id, $date, $app_id); $stmt->execute(); $stmt->bind_result($date, $score, $app_name); diff --git a/src/web/server/record/ranking_record_day.php b/src/web/server/record/ranking_record_day.php index 230a6d9..6a30a1e 100644 --- a/src/web/server/record/ranking_record_day.php +++ b/src/web/server/record/ranking_record_day.php @@ -3,6 +3,7 @@ header('Content-Type: application/json'); include "./../lib/send_error_code.php"; +$maestro_id = $_POST["MaestroID"]; $app_id = $_POST["AppID"]; $date = $_POST["Date"]; $time = $_POST["Time"]; @@ -10,7 +11,7 @@ $time = $_POST["Time"]; include "./../setup/connect_db.php"; -$replyJSON = get_ranking_record_day($date, $app_id); +$replyJSON = get_ranking_record_day($maestro_id, $date, $app_id); if($replyJSON.length === 0) { send_error_message($replyJSON, "오늘의 랭킹 기록 없음"); $db_conn->close(); @@ -21,18 +22,18 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); $db_conn->close(); -function get_ranking_record_day($date, $app_id) { +function get_ranking_record_day($maestro_id, $date, $app_id) { global $db_conn; $query = " SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore FROM moty_best_record BR, moty_user U - WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND AppID = ? + WHERE BR.MaestroID = ? AND BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND AppID = ? GROUP BY BR.userID ORDER BY max(BR.BestRecord) DESC; "; $stmt = $db_conn->prepare($query); - $stmt->bind_param('si', $date, $app_id); + $stmt->bind_param('isi', $maestro_id, $date, $app_id); $stmt->execute(); $stmt->bind_result($userID, $name, $high_score); diff --git a/src/web/server/record/ranking_record_hour.php b/src/web/server/record/ranking_record_hour.php index a33a378..42c0c54 100644 --- a/src/web/server/record/ranking_record_hour.php +++ b/src/web/server/record/ranking_record_hour.php @@ -3,6 +3,7 @@ header('Content-Type: application/json'); include "./../lib/send_error_code.php"; +$maestro_id = $_POST["MaestroID"]; $app_id = $_POST["AppID"]; $date = $_POST["Date"]; $time = $_POST["Time"]; @@ -10,7 +11,7 @@ $time = $_POST["Time"]; include "./../setup/connect_db.php"; -$replyJSON = get_ranking_record_hour($date, $time, $app_id); +$replyJSON = get_ranking_record_hour($maestro_id, $date, $time, $app_id); if($replyJSON.length === 0) { send_error_message($replyJSON, "수업시간 랭킹 기록 없음"); $db_conn->close(); @@ -20,18 +21,18 @@ if($replyJSON.length === 0) { echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); $db_conn->close(); -function get_ranking_record_hour($date, $time, $app_id) { +function get_ranking_record_hour($maestro_id, $date, $time, $app_id) { global $db_conn; $query = " SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore FROM moty_best_record BR, moty_user U - WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND HOUR(BR.RecordDateTime) = HOUR(?) AND AppID = ? + WHERE BR.MaestroID = ? AND BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND HOUR(BR.RecordDateTime) = HOUR(?) AND AppID = ? GROUP BY BR.userID ORDER BY max(BR.BestRecord) DESC; "; $stmt = $db_conn->prepare($query); - $stmt->bind_param('ssi', $date, $time, $app_id); + $stmt->bind_param('issi', $maestro_id, $date, $time, $app_id); $stmt->execute(); $stmt->bind_result($userID, $name, $high_score); diff --git a/src/web/server/record/ranking_record_month.php b/src/web/server/record/ranking_record_month.php index 2a885be..f3c4cc1 100644 --- a/src/web/server/record/ranking_record_month.php +++ b/src/web/server/record/ranking_record_month.php @@ -3,6 +3,7 @@ header('Content-Type: application/json'); include "./../lib/send_error_code.php"; +$maestro_id = $_POST["MaestroID"]; $app_id = $_POST["AppID"]; $date = $_POST["Date"]; $time = $_POST["Time"]; @@ -10,7 +11,7 @@ $time = $_POST["Time"]; include "./../setup/connect_db.php"; -$replyJSON = get_ranking_record_month($date, $time, $app_id); +$replyJSON = get_ranking_record_month($maestro_id, $date, $time, $app_id); if($replyJSON.length === 0) { send_error_message($replyJSON, "이달의 랭킹 기록 없음"); $db_conn->close(); @@ -21,18 +22,18 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); $db_conn->close(); -function get_ranking_record_month($date, $time, $app_id) { +function get_ranking_record_month($maestro_id, $date, $time, $app_id) { global $db_conn; $query = " SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore FROM moty_best_record BR, moty_user U - WHERE BR.userID = U.userID AND MONTH(BR.RecordDateTime) = MONTH(?) AND AppID = ? + WHERE BR.MaestroID = ? AND BR.userID = U.userID AND MONTH(BR.RecordDateTime) = MONTH(?) AND AppID = ? GROUP BY BR.userID ORDER BY max(BR.BestRecord) DESC; "; $stmt = $db_conn->prepare($query); - $stmt->bind_param('si', $date, $app_id); + $stmt->bind_param('isi', $maestro_id, $date, $app_id); $stmt->execute(); $stmt->bind_result($userID, $name, $high_score); diff --git a/test/test_db_connect_manager.js b/test/test_db_connect_manager.js index 99bb427..84e58a9 100644 --- a/test/test_db_connect_manager.js +++ b/test/test_db_connect_manager.js @@ -24,6 +24,7 @@ QUnit.test( "User login", function( assert ) { }); QUnit.test( "Player history", function( assert ) { + sessionStorageManager.maestroID = 1; // jisangs sessionStorageManager.playerUserID = "8"; // 부현율 sessionStorageManager.playingAppID = 9; let date = "2018-05-16"; @@ -31,6 +32,7 @@ QUnit.test( "Player history", function( assert ) { let done = assert.async(); setTimeout(function() { dbConnectManager.requestPlayerHistory( + 1, // maestroID for jisangs date, (historyRecordManager) => { console.log(historyRecordManager); @@ -50,6 +52,7 @@ QUnit.test( "Player history", function( assert ) { }); QUnit.test( "Player ranking", function( assert ) { + sessionStorageManager.maestroID = 1; // jisangs sessionStorageManager.playingAppID = 9; let date = "2018-05-16"; let time = "14:50:00"; @@ -59,6 +62,7 @@ QUnit.test( "Player ranking", function( assert ) { setTimeout(function() { dbConnectManager.requestRanking( DBConnectManager.TYPE_MY_RANKING_HOUR, + 1, // maestroID for jisangs date, time, (type, rankingRecordManager) => { @@ -80,6 +84,7 @@ QUnit.test( "Player ranking", function( assert ) { setTimeout(function() { dbConnectManager.requestRanking( DBConnectManager.TYPE_MY_RANKING_DAY, + 1, // maestroID for jisangs date, time, (type, rankingRecordManager) => { @@ -101,6 +106,7 @@ QUnit.test( "Player ranking", function( assert ) { setTimeout(function() { dbConnectManager.requestRanking( DBConnectManager.TYPE_MY_RANKING_MONTH, + 1, // maestroID for jisangs date, time, (type, rankingRecordManager) => {