Fix: request history and ranking record with maestroID

This commit is contained in:
2018-05-31 17:47:11 +09:00
parent cec653abb7
commit 7341be330f
9 changed files with 35 additions and 21 deletions
+6 -4
View File
@@ -81,7 +81,7 @@ class DBConnectManager {
xhr.send("maestro_id=" + maestroID); xhr.send("maestro_id=" + maestroID);
} }
requestPlayerHistory(date, listener) { requestPlayerHistory(maestroID, date, listener) {
let historyRecordManager = new HistoryRecordManager(); let historyRecordManager = new HistoryRecordManager();
/* /*
@@ -111,7 +111,8 @@ class DBConnectManager {
onFailedListener(replyJSON); onFailedListener(replyJSON);
} }
}; };
let params = "AppID=" + sessionStorageManager.playingAppID let params = "MaestroID=" + sessionStorageManager.maestroID
+ "&AppID=" + sessionStorageManager.playingAppID
+ "&UserID=" + sessionStorageManager.playerUserID + "&UserID=" + sessionStorageManager.playerUserID
+ "&Date=" + date; + "&Date=" + date;
xhr.send(params); xhr.send(params);
@@ -160,7 +161,7 @@ class DBConnectManager {
*/ */
} }
requestRanking(type, date, time, listener) { requestRanking(type, maestroID, date, time, listener) {
let rankingRecordManager = new RankingRecordManager(); let rankingRecordManager = new RankingRecordManager();
/* /*
@@ -190,7 +191,8 @@ class DBConnectManager {
onFailedListener(replyJSON); onFailedListener(replyJSON);
} }
}; };
let params = "AppID=" + sessionStorageManager.playingAppID let params = "MaestroID=" + sessionStorageManager.maestroID
+ "&AppID=" + sessionStorageManager.playingAppID
+ "&Date=" + date + "&Date=" + date
+ "&Time=" + time; + "&Time=" + time;
xhr.send(params); xhr.send(params);
+1
View File
@@ -16,6 +16,7 @@ class HistoryBoard {
let today = new Date(); let today = new Date();
let date = DateUtil.getYYYYMMDD(today); let date = DateUtil.getYYYYMMDD(today);
this.dbConnectManager.requestPlayerHistory( this.dbConnectManager.requestPlayerHistory(
sessionStorageManager.maestroID,
date, date,
historyRecordManager => { historyRecordManager => {
if(historyRecordManager.count == 0) { if(historyRecordManager.count == 0) {
+1 -1
View File
@@ -17,7 +17,7 @@ class RankingBoard {
let date = DateUtil.getYYYYMMDD(today); let date = DateUtil.getYYYYMMDD(today);
let time = DateUtil.getHHMMSS(today); let time = DateUtil.getHHMMSS(today);
this.dbConnectManager.requestRanking( this.dbConnectManager.requestRanking(
type, date, time, type, sessionStorageManager.maestroID, date, time,
(type, rankingRecordManager) => { (type, rankingRecordManager) => {
if(rankingRecordManager.count == 0) { if(rankingRecordManager.count == 0) {
console.log("ranking board - no data"); console.log("ranking board - no data");
+1
View File
@@ -28,6 +28,7 @@ class Start {
let today = new Date(); let today = new Date();
let date = DateUtil.getYYYYMMDD(today); let date = DateUtil.getYYYYMMDD(today);
this.dbConnectManager.requestPlayerHistory( this.dbConnectManager.requestPlayerHistory(
sessionStorageManager.maestroID,
date, date,
historyRecordManager => { historyRecordManager => {
this.printChartBaseLine(); this.printChartBaseLine();
+5 -4
View File
@@ -3,6 +3,7 @@ header('Content-Type: application/json');
include "./../send_error_code.php"; include "./../send_error_code.php";
$maestro_id = $_POST["MaestroID"];
$app_id = $_POST["AppID"]; $app_id = $_POST["AppID"];
$user_id = $_POST["UserID"]; $user_id = $_POST["UserID"];
$date = $_POST["Date"]; $date = $_POST["Date"];
@@ -10,7 +11,7 @@ $date = $_POST["Date"];
include "./../setup/connect_db.php"; 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) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음"); send_error_message($replyJSON, "히스토리 기록 없음");
$db_conn->close(); $db_conn->close();
@@ -21,20 +22,20 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close(); $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; global $db_conn;
$query = " $query = "
SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName
FROM moty_best_record BR FROM moty_best_record BR
INNER JOIN moty_app AS AA 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) GROUP BY DATE(BR.RecordDateTime)
ORDER BY BR.RecordDateTime DESC ORDER BY BR.RecordDateTime DESC
LIMIT 7 LIMIT 7
"; ";
$stmt = $db_conn->prepare($query); $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->execute();
$stmt->bind_result($date, $score, $app_name); $stmt->bind_result($date, $score, $app_name);
+5 -4
View File
@@ -3,6 +3,7 @@ header('Content-Type: application/json');
include "./../lib/send_error_code.php"; include "./../lib/send_error_code.php";
$maestro_id = $_POST["MaestroID"];
$app_id = $_POST["AppID"]; $app_id = $_POST["AppID"];
$date = $_POST["Date"]; $date = $_POST["Date"];
$time = $_POST["Time"]; $time = $_POST["Time"];
@@ -10,7 +11,7 @@ $time = $_POST["Time"];
include "./../setup/connect_db.php"; 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) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "오늘의 랭킹 기록 없음"); send_error_message($replyJSON, "오늘의 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
@@ -21,18 +22,18 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close(); $db_conn->close();
function get_ranking_record_day($date, $app_id) { function get_ranking_record_day($maestro_id, $date, $app_id) {
global $db_conn; global $db_conn;
$query = " $query = "
SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore
FROM moty_best_record BR, moty_user U 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 GROUP BY BR.userID
ORDER BY max(BR.BestRecord) DESC; ORDER BY max(BR.BestRecord) DESC;
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('si', $date, $app_id); $stmt->bind_param('isi', $maestro_id, $date, $app_id);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($userID, $name, $high_score); $stmt->bind_result($userID, $name, $high_score);
@@ -3,6 +3,7 @@ header('Content-Type: application/json');
include "./../lib/send_error_code.php"; include "./../lib/send_error_code.php";
$maestro_id = $_POST["MaestroID"];
$app_id = $_POST["AppID"]; $app_id = $_POST["AppID"];
$date = $_POST["Date"]; $date = $_POST["Date"];
$time = $_POST["Time"]; $time = $_POST["Time"];
@@ -10,7 +11,7 @@ $time = $_POST["Time"];
include "./../setup/connect_db.php"; 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) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "수업시간 랭킹 기록 없음"); send_error_message($replyJSON, "수업시간 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
@@ -20,18 +21,18 @@ if($replyJSON.length === 0) {
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close(); $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; global $db_conn;
$query = " $query = "
SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore
FROM moty_best_record BR, moty_user U 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 GROUP BY BR.userID
ORDER BY max(BR.BestRecord) DESC; ORDER BY max(BR.BestRecord) DESC;
"; ";
$stmt = $db_conn->prepare($query); $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->execute();
$stmt->bind_result($userID, $name, $high_score); $stmt->bind_result($userID, $name, $high_score);
@@ -3,6 +3,7 @@ header('Content-Type: application/json');
include "./../lib/send_error_code.php"; include "./../lib/send_error_code.php";
$maestro_id = $_POST["MaestroID"];
$app_id = $_POST["AppID"]; $app_id = $_POST["AppID"];
$date = $_POST["Date"]; $date = $_POST["Date"];
$time = $_POST["Time"]; $time = $_POST["Time"];
@@ -10,7 +11,7 @@ $time = $_POST["Time"];
include "./../setup/connect_db.php"; 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) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "이달의 랭킹 기록 없음"); send_error_message($replyJSON, "이달의 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
@@ -21,18 +22,18 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close(); $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; global $db_conn;
$query = " $query = "
SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore
FROM moty_best_record BR, moty_user U 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 GROUP BY BR.userID
ORDER BY max(BR.BestRecord) DESC; ORDER BY max(BR.BestRecord) DESC;
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('si', $date, $app_id); $stmt->bind_param('isi', $maestro_id, $date, $app_id);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($userID, $name, $high_score); $stmt->bind_result($userID, $name, $high_score);
+6
View File
@@ -24,6 +24,7 @@ QUnit.test( "User login", function( assert ) {
}); });
QUnit.test( "Player history", function( assert ) { QUnit.test( "Player history", function( assert ) {
sessionStorageManager.maestroID = 1; // jisangs
sessionStorageManager.playerUserID = "8"; // 부현율 sessionStorageManager.playerUserID = "8"; // 부현율
sessionStorageManager.playingAppID = 9; sessionStorageManager.playingAppID = 9;
let date = "2018-05-16"; let date = "2018-05-16";
@@ -31,6 +32,7 @@ QUnit.test( "Player history", function( assert ) {
let done = assert.async(); let done = assert.async();
setTimeout(function() { setTimeout(function() {
dbConnectManager.requestPlayerHistory( dbConnectManager.requestPlayerHistory(
1, // maestroID for jisangs
date, date,
(historyRecordManager) => { (historyRecordManager) => {
console.log(historyRecordManager); console.log(historyRecordManager);
@@ -50,6 +52,7 @@ QUnit.test( "Player history", function( assert ) {
}); });
QUnit.test( "Player ranking", function( assert ) { QUnit.test( "Player ranking", function( assert ) {
sessionStorageManager.maestroID = 1; // jisangs
sessionStorageManager.playingAppID = 9; sessionStorageManager.playingAppID = 9;
let date = "2018-05-16"; let date = "2018-05-16";
let time = "14:50:00"; let time = "14:50:00";
@@ -59,6 +62,7 @@ QUnit.test( "Player ranking", function( assert ) {
setTimeout(function() { setTimeout(function() {
dbConnectManager.requestRanking( dbConnectManager.requestRanking(
DBConnectManager.TYPE_MY_RANKING_HOUR, DBConnectManager.TYPE_MY_RANKING_HOUR,
1, // maestroID for jisangs
date, date,
time, time,
(type, rankingRecordManager) => { (type, rankingRecordManager) => {
@@ -80,6 +84,7 @@ QUnit.test( "Player ranking", function( assert ) {
setTimeout(function() { setTimeout(function() {
dbConnectManager.requestRanking( dbConnectManager.requestRanking(
DBConnectManager.TYPE_MY_RANKING_DAY, DBConnectManager.TYPE_MY_RANKING_DAY,
1, // maestroID for jisangs
date, date,
time, time,
(type, rankingRecordManager) => { (type, rankingRecordManager) => {
@@ -101,6 +106,7 @@ QUnit.test( "Player ranking", function( assert ) {
setTimeout(function() { setTimeout(function() {
dbConnectManager.requestRanking( dbConnectManager.requestRanking(
DBConnectManager.TYPE_MY_RANKING_MONTH, DBConnectManager.TYPE_MY_RANKING_MONTH,
1, // maestroID for jisangs
date, date,
time, time,
(type, rankingRecordManager) => { (type, rankingRecordManager) => {