Add: requestTodayBestRecord, updateTodayBestRecord
This commit is contained in:
@@ -352,6 +352,39 @@ class DBConnectManager {
|
||||
xhr.send("AppID=" + appID);
|
||||
}
|
||||
|
||||
updateTodayBestRecord(maestroID, userID, appID, record) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", this.phpPath + "server/record/update_best_record.php", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send(
|
||||
"MaestroID=" + maestroID
|
||||
+ "&UserID=" + userID
|
||||
+ "&AppID=" + appID
|
||||
+ "&BestRecord=" + record
|
||||
);
|
||||
}
|
||||
|
||||
requestTodayBestRecord(maestroID, userID, appID, onSucceededListener, onFailedListener) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", this.phpPath + "server/record/request_best_record.php", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState == 4 && xhr.status == 200) {
|
||||
let replyJSON = JSON.parse(xhr.responseText);
|
||||
|
||||
if(replyJSON != null && replyJSON["BestRecord"] != null)
|
||||
onSucceededListener(replyJSON);
|
||||
else
|
||||
onFailedListener(replyJSON);
|
||||
}
|
||||
};
|
||||
xhr.send(
|
||||
"MaestroID=" + maestroID
|
||||
+ "&UserID=" + userID
|
||||
+ "&AppID=" + appID
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
loadTempPlayerHistory(historyRecordManager) {
|
||||
|
||||
@@ -8,7 +8,7 @@ class Result {
|
||||
}
|
||||
|
||||
create() {
|
||||
this.historyRecordManager = new HistoryRecordManager();
|
||||
this.dbConnectManager = new DBConnectManager();
|
||||
|
||||
this.game.stage.backgroundColor = '#4d4d4d';
|
||||
this.chartGraphics = game.add.graphics(100, game.world.height - 120);
|
||||
@@ -24,6 +24,8 @@ class Result {
|
||||
|
||||
// contents
|
||||
this.printRecord();
|
||||
this.uploadRecord();
|
||||
|
||||
this.makeStartButton();
|
||||
|
||||
let recordBoard = new RecordBoard();
|
||||
@@ -63,7 +65,15 @@ class Result {
|
||||
// .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
bestRecordText.stroke = "#333";
|
||||
bestRecordText.strokeThickness = 5;
|
||||
}
|
||||
|
||||
uploadRecord() {
|
||||
this.dbConnectManager.updateTodayBestRecord(
|
||||
sessionStorageManager.maestroID,
|
||||
sessionStorageManager.playerUserID,
|
||||
sessionStorageManager.playingAppID,
|
||||
sessionStorageManager.record
|
||||
);
|
||||
}
|
||||
|
||||
makeStartButton() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "./../send_error_code.php";
|
||||
|
||||
$maestro_id = $_POST["MaestroID"];
|
||||
$user_id = $_POST["UserID"];
|
||||
$app_id = $_POST["AppID"];
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
|
||||
$replyJSON = array();
|
||||
$replyJSON["BestRecord"] = get_best_record($maestro_id, $app_id, $user_id);
|
||||
if($replyJSON.length === 0) {
|
||||
send_error_message($replyJSON, "히스토리 기록 없음");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function get_best_record($maestro_id, $app_id, $user_id) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT BestRecord
|
||||
FROM moty_best_record
|
||||
WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = Date(NOW())
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iii", $maestro_id, $app_id, $user_id);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($best_record);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $best_record;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "send_error_code.php";
|
||||
|
||||
$user_id = $_POST["UserID"];
|
||||
$language = $_POST["language"];
|
||||
$stageName = $_POST["stageName"];
|
||||
$record = $_POST["Record"];
|
||||
$stage_name = $language."_".$stageName;
|
||||
// $user_id = $_GET["UserID"];
|
||||
// $language = $_GET["language"];
|
||||
// $stageName = $_GET["stageName"];
|
||||
// $best_record = $_GET["BestRecord"];
|
||||
// $typing_stage = $language."_".$stageName;
|
||||
|
||||
// echo $user_id."\n";
|
||||
// echo $typingStage."\n";
|
||||
|
||||
include "connect_db.php";
|
||||
|
||||
$query = "
|
||||
INSERT INTO afterschool_record (UserID, Record, RecordDateTime, StageName)
|
||||
VALUES (?, ?, NOW(), ?);
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ids', $user_id, $record, $stage_name);
|
||||
$stmt->execute();
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "./../send_error_code.php";
|
||||
|
||||
$maestro_id = $_POST["MaestroID"];
|
||||
$user_id = $_POST["UserID"];
|
||||
$app_id = $_POST["AppID"];
|
||||
$best_record = $_POST["BestRecord"];
|
||||
echo $best_record." / ";
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$prev_best_record_id = -1;
|
||||
$prev_best_record = 0;
|
||||
|
||||
$prev_best_record_id = get_best_record($maestro_id, $app_id, $user_id);
|
||||
// echo $prev_best_record_id." ".$prev_best_record;
|
||||
|
||||
if($prev_best_record_id == "") {
|
||||
echo "insert";
|
||||
insert_best_record($maestro_id, $app_id, $user_id, $best_record);
|
||||
} else {
|
||||
echo $best_record." ".$prev_best_record;
|
||||
if($best_record > $prev_best_record) {
|
||||
echo "update";
|
||||
update_best_record($prev_best_record_id, $best_record);
|
||||
}
|
||||
}
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function get_best_record($maestro_id, $app_id, $user_id) {
|
||||
global $db_conn;
|
||||
global $prev_best_record_id, $prev_best_record;
|
||||
|
||||
$query = "
|
||||
SELECT BestRecordID, BestRecord
|
||||
FROM moty_best_record
|
||||
WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = DATE(NOW())
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iii", $maestro_id, $app_id, $user_id);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($prev_best_record_id, $prev_best_record);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
$GLOBALS["prev_best_record_id"] = $prev_best_record_id;
|
||||
$GLOBALS["prev_best_record"] = $prev_best_record;
|
||||
|
||||
return $prev_best_record_id;
|
||||
}
|
||||
|
||||
|
||||
function insert_best_record($maestro_id, $app_id, $user_id, $best_record) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
INSERT INTO moty_best_record (MaestroID, UserID, AppID, BestRecord, RecordDateTime)
|
||||
VALUES (?, ?, ?, ?, NOW());
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iiii', $maestro_id, $user_id, $app_id, $best_record);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function update_best_record($prev_best_record_id, $best_record) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_best_record
|
||||
SET BestRecord = ?, RecordDateTime = now()
|
||||
WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW())
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $best_record, $prev_best_record_id);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -131,11 +131,12 @@ QUnit.test( "HowToPlay", function( assert ) {
|
||||
let howToPlayForSpaceInvaders = "외계인이 나타났다!\\n마우스 왼쪽 버튼으로\\n외계인을 클릭해서 물리쳐 주세요.";
|
||||
|
||||
let done = assert.async(2);
|
||||
|
||||
setTimeout(function() {
|
||||
dbConnectManager.requestHowToPlay(
|
||||
101, // space_invaders app ID
|
||||
(jsonData) => {
|
||||
howToPlay = jsonData["HowToPlay"];
|
||||
let howToPlay = jsonData["HowToPlay"];
|
||||
assert.equal(howToPlay, howToPlayForSpaceInvaders);
|
||||
done();
|
||||
},
|
||||
@@ -148,7 +149,7 @@ QUnit.test( "HowToPlay", function( assert ) {
|
||||
dbConnectManager.requestHowToPlay(
|
||||
1, // korean basic typing
|
||||
(jsonData) => {
|
||||
howToPlay = jsonData["HowToPlay"];
|
||||
let howToPlay = jsonData["HowToPlay"];
|
||||
assert.equal(howToPlay, "");
|
||||
done();
|
||||
},
|
||||
@@ -160,3 +161,50 @@ QUnit.test( "HowToPlay", function( assert ) {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
QUnit.test( "UpdateRecord", function( assert ) {
|
||||
let todayBestRecord = 0;
|
||||
|
||||
let done = assert.async();
|
||||
|
||||
setTimeout(function() {
|
||||
dbConnectManager.requestTodayBestRecord(
|
||||
1, // maestro ID for "jisangs"
|
||||
1, // user ID for jisangs
|
||||
101, // space_invaders app ID
|
||||
(jsonData) => {
|
||||
todayBestRecord = jsonData["BestRecord"];
|
||||
},
|
||||
(jsonData) => {
|
||||
console.log(jsonData);
|
||||
todayBestRecord = 0;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
dbConnectManager.updateTodayBestRecord(
|
||||
1, // maestro ID for "jisangs"
|
||||
1, // user ID for jisangs
|
||||
101, // space_invaders app ID
|
||||
todayBestRecord + 1000 // new record
|
||||
);
|
||||
}, 100);
|
||||
|
||||
setTimeout(function() {
|
||||
dbConnectManager.requestTodayBestRecord(
|
||||
1, // maestro ID for "jisangs"
|
||||
1, // user ID for jisangs
|
||||
101, // space_invaders app ID
|
||||
(jsonData) => {
|
||||
let bestRecord = jsonData["BestRecord"];
|
||||
assert.equal(bestRecord, todayBestRecord + 1000);
|
||||
done();
|
||||
},
|
||||
(jsonData) => {
|
||||
console.log(jsonData);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}, 200);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user