Add: selected subject name to license time db

This commit is contained in:
2018-12-13 12:51:21 +09:00
parent 7b0664f8d5
commit 4e31886281
8 changed files with 80 additions and 55 deletions
+4 -2
View File
@@ -420,7 +420,7 @@ DBConnectManager.prototype.requestLicenseTimeData = function(maestroID, playerID
); );
} }
DBConnectManager.prototype.updateLicenseStartTime = function(maestroID, playerID, startTime, onSucceededListener, onFailedListener) { DBConnectManager.prototype.updateLicenseStartTime = function(maestroID, playerID, startTime, subjectName, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/license_timer/update_license_start_time.php", true); xhr.open("POST", this.phpPath + "server/license_timer/update_license_start_time.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -438,10 +438,11 @@ DBConnectManager.prototype.updateLicenseStartTime = function(maestroID, playerID
"MaestroID=" + maestroID "MaestroID=" + maestroID
+ "&PlayerID=" + playerID + "&PlayerID=" + playerID
+ "&StartTime=" + startTime + "&StartTime=" + startTime
+ "&SubjectName=" + subjectName
); );
} }
DBConnectManager.prototype.updateLicenseLeftTime = function(maestroID, playerID, leftTime, onSucceededListener, onFailedListener) { DBConnectManager.prototype.updateLicenseLeftTime = function(maestroID, playerID, leftTime, subjectName, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/license_timer/update_license_left_time.php", true); xhr.open("POST", this.phpPath + "server/license_timer/update_license_left_time.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -459,6 +460,7 @@ DBConnectManager.prototype.updateLicenseLeftTime = function(maestroID, playerID,
"MaestroID=" + maestroID "MaestroID=" + maestroID
+ "&PlayerID=" + playerID + "&PlayerID=" + playerID
+ "&LeftTime=" + leftTime + "&LeftTime=" + leftTime
+ "&SubjectName=" + subjectName
); );
} }
+22
View File
@@ -3,6 +3,8 @@ var LicenseTimer = {
create: function() { create: function() {
game.stage.backgroundColor = "#4d4d4d"; game.stage.backgroundColor = "#4d4d4d";
this.dbConnectManager = new DBConnectManager();
// keyboard shortcut // keyboard shortcut
this.keyboardShortcut = new KeyboardShortcut(); this.keyboardShortcut = new KeyboardShortcut();
this.keyboardShortcut.addCallback( this.keyboardShortcut.addCallback(
@@ -28,6 +30,8 @@ var LicenseTimer = {
this.chart = new Chart(this.licenseDataManager); this.chart = new Chart(this.licenseDataManager);
this.inputScore = new InputScore(this.licenseDataManager, this.timer, this.chart); this.inputScore = new InputScore(this.licenseDataManager, this.timer, this.chart);
this.loadDataFromServer();
}, },
back: function() { back: function() {
@@ -36,4 +40,22 @@ var LicenseTimer = {
game.state.start('Login'); game.state.start('Login');
}, },
loadDataFromServer: function() {
this.dbConnectManager.requestLicenseTimeData(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
Timer.TIME_DEFAULT_SEC,
(function(replyJson) {
console.log(replyJson);
this.timer.loadDataFromServer(replyJson.leftTime, replyJson.startTime, replyJson.subjectName);
this.inputScore.loadDataFromServer(replyJson.subjectName);
}).bind(this),
(function(replyJson) {
console.log(replyJson);
this.timer.loadDataFromServer(Timer.TIME_DEFAULT_SEC, Timer.TIME_DEFAULT_SEC);
})
);
},
} }
+8 -1
View File
@@ -76,7 +76,7 @@ function InputScore(licenseDataManager, timer, chart) {
InputScore.prototype.initVariables = function() { InputScore.prototype.initVariables = function() {
this.inputScorePosY = GAME_SCREEN_SIZE.y - InputScore.INPUT_SCORE_GROUP_OFFSET_Y; this.inputScorePosY = GAME_SCREEN_SIZE.y - InputScore.INPUT_SCORE_GROUP_OFFSET_Y;
this.subjectFullname = "ITQ 파워포인트"; this.subjectFullname = "";
this.recentSubject = this.subjectFullname; this.recentSubject = this.subjectFullname;
this.companyButtonList = []; this.companyButtonList = [];
@@ -85,6 +85,11 @@ InputScore.prototype.initVariables = function() {
this.maestroPassword; this.maestroPassword;
} }
InputScore.prototype.loadDataFromServer = function(subjectName) {
this.setSubjectFullname(subjectName);
this.recentSubject = this.subjectFullname;
}
InputScore.prototype.makeInputTextSetting = function(width, placeHolder) { InputScore.prototype.makeInputTextSetting = function(width, placeHolder) {
return { return {
font: "32px Arial", font: "32px Arial",
@@ -271,6 +276,7 @@ InputScore.prototype.onClickCompanySubjectButton = function(subjectFullname) {
this.selectedSubjectData = this.licenseDataManager.getSubjectDataByName(subjectFullname); this.selectedSubjectData = this.licenseDataManager.getSubjectDataByName(subjectFullname);
// console.log(this.selectedSubjectData); // console.log(this.selectedSubjectData);
this.timer.setSubjectName(this.subjectFullname);
this.timer.setStartTime(this.selectedSubjectData.timeLimit * Timer.TIME_SECONDS_FOR_MINUTE); this.timer.setStartTime(this.selectedSubjectData.timeLimit * Timer.TIME_SECONDS_FOR_MINUTE);
this.setVisibleCompanyPanel(false); this.setVisibleCompanyPanel(false);
@@ -325,6 +331,7 @@ InputScore.prototype.addScoreToServer = function(subjectName, score) {
(function(replyJson) { (function(replyJson) {
console.log(replyJson); console.log(replyJson);
this.scoreText.setText("");
this.chart.loadScoreFromServer(); this.chart.loadScoreFromServer();
}).bind(this), }).bind(this),
+22 -33
View File
@@ -16,8 +16,6 @@ function Timer() {
this.pauseButton = this.makePauseButton(); this.pauseButton = this.makePauseButton();
this.showButton(this.pauseButton, false); this.showButton(this.pauseButton, false);
this.playButton = this.makePlayButton(); this.playButton = this.makePlayButton();
this.loadDataFromServer();
} }
@@ -26,6 +24,8 @@ Timer.prototype.initVariables = function() {
this.isTimerGoingOn = false; this.isTimerGoingOn = false;
this.isTimeOver = false; this.isTimeOver = false;
this.subjectName = "";
this.startTime = 0 this.startTime = 0
this.leftTime = 0; this.leftTime = 0;
this.timerEvent = null; this.timerEvent = null;
@@ -45,39 +45,27 @@ Timer.prototype.initVariables = function() {
this.timeMinusButtonPosY = this.timerCenterY + 75; this.timeMinusButtonPosY = this.timerCenterY + 75;
} }
Timer.prototype.loadDataFromServer = function() { Timer.prototype.loadDataFromServer = function(leftTime, startTime, subjectName) {
this.dbConnectManager.requestLicenseTimeData( this.setSubjectName(subjectName);
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
Timer.TIME_DEFAULT_SEC,
(function(replyJson) {
// console.log(replyJson);
if(replyJson.leftTime == null || replyJson.leftTime == 0) { if(leftTime == null || leftTime == 0) {
this.startTime = replyJson.startTime; this.startTime = startTime;
this.leftTime = replyJson.timeStart; this.leftTime = startTime;
this.resetTimer(); this.resetTimer();
return; return;
} }
// this.setTimerTextColor(Timer.TEXT_COLOR_CYAN); this.startTime = startTime;
// this.updateTimeText(); this.leftTime = leftTime;
this.startTime = replyJson.startTime; this.pauseTimer();
this.leftTime = replyJson.leftTime;
this.pauseTimer();
}).bind(this),
(function(replyJson) {
console.log(replyJson);
this.startTime = Timer.TIME_DEFAULT_SEC;
this.leftTime = this.startTime;
this.updateTimeText();
})
);
} }
Timer.prototype.setSubjectName = function(subjectName) {
this.subjectName = subjectName;
}
Timer.prototype.makeTimer = function() { Timer.prototype.makeTimer = function() {
this.timeHourText = this.makeTimerTextContent(this.timerCenterX - 240, this.timerCenterY, 160, "00"); this.timeHourText = this.makeTimerTextContent(this.timerCenterX - 240, this.timerCenterY, 160, "00");
this.timeHourMinuteSeperator = this.makeTimerTextContent(this.timerCenterX - 185, this.timerCenterY, 160, ":"); this.timeHourMinuteSeperator = this.makeTimerTextContent(this.timerCenterX - 185, this.timerCenterY, 160, ":");
@@ -325,8 +313,6 @@ Timer.prototype.resetTimer = function() {
this.isTimerGoingOn = false; this.isTimerGoingOn = false;
this.setTimerTextColor(Timer.TEXT_COLOR_CYAN); this.setTimerTextColor(Timer.TEXT_COLOR_CYAN);
// this.loadDataFromServer();
} }
Timer.prototype.tickLeftTime = function() { Timer.prototype.tickLeftTime = function() {
@@ -587,6 +573,7 @@ Timer.prototype.updateStartTimeToServer = function() {
sessionStorageManager.getMaestroID(), sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayerID(),
this.startTime, this.startTime,
this.subjectName,
(function(replyJson) { /*console.log(replyJson);*/ }).bind(this), (function(replyJson) { /*console.log(replyJson);*/ }).bind(this),
(function(replyJson) { /*console.log(replyJson);*/ }) (function(replyJson) { /*console.log(replyJson);*/ })
); );
@@ -599,6 +586,7 @@ Timer.prototype.resetLeftTimeToServer = function() {
sessionStorageManager.getMaestroID(), sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayerID(),
0, 0,
this.subjectName,
(function(replyJson) { /*console.log(replyJson);*/ }).bind(this), (function(replyJson) { /*console.log(replyJson);*/ }).bind(this),
(function(replyJson) { /*console.log(replyJson);*/ }) (function(replyJson) { /*console.log(replyJson);*/ })
); );
@@ -611,6 +599,7 @@ Timer.prototype.updateLeftTimeToServer = function() {
sessionStorageManager.getMaestroID(), sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayerID(),
this.leftTime, this.leftTime,
this.subjectName,
(function(replyJson) { /*console.log(replyJson);*/ }).bind(this), (function(replyJson) { /*console.log(replyJson);*/ }).bind(this),
(function(replyJson) { /*console.log(replyJson);*/ }) (function(replyJson) { /*console.log(replyJson);*/ })
); );
@@ -5,8 +5,6 @@ $maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"]; $player_id = $_POST["PlayerID"];
$default_start_time = $_POST["DefaultStartTime"]; $default_start_time = $_POST["DefaultStartTime"];
// echo $maestro_id." / ".$player_id; // echo $maestro_id." / ".$player_id;
// if($default_start_time === null)
// $default_start_time = 60 * 60; // 60 min * 60 sec
include "./../lib/send_reply_json.php"; include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php"; include "./../setup/connect_db.php";
@@ -15,6 +13,7 @@ include "./../setup/connect_db.php";
$start_time = $default_start_time; $start_time = $default_start_time;
$left_time = null; $left_time = null;
$saved_date_time = null; $saved_date_time = null;
$subject_name = "";
// get license_time data // get license_time data
@@ -30,12 +29,14 @@ if($time_data["StartTime"] == null) {
$start_time = $time_data["StartTime"]; $start_time = $time_data["StartTime"];
$left_time = $time_data["LeftTime"]; $left_time = $time_data["LeftTime"];
$saved_date_time = $time_data["SavedDateTime"]; $saved_date_time = $time_data["SavedDateTime"];
$subject_name = $time_data["SubjectName"];
} }
// send license_time data back to client // send license_time data back to client
set_data("startTime", $start_time); set_data("startTime", $start_time);
set_data("leftTime", $left_time); set_data("leftTime", $left_time);
set_data("savedDateTime", $saved_date_time); set_data("savedDateTime", $saved_date_time);
set_data("subjectName", $subject_name);
send_result_success(); send_result_success();
exit; exit;
@@ -45,20 +46,21 @@ function get_time_data($maestro_id, $player_id) {
global $db_conn; global $db_conn;
$query = " $query = "
SELECT StartTime, LeftTime, SavedDateTime SELECT StartTime, LeftTime, SavedDateTime, SubjectName
FROM license_time FROM license_time
WHERE MaestroID = ? AND PlayerID = ? WHERE MaestroID = ? AND PlayerID = ?
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $maestro_id, $player_id); $stmt->bind_param("ii", $maestro_id, $player_id);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($start_time, $left_time, $saved_date_time); $stmt->bind_result($start_time, $left_time, $saved_date_time, $subject_name);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
$license_time["StartTime"] = $start_time; $license_time["StartTime"] = $start_time;
$license_time["LeftTime"] = $left_time; $license_time["LeftTime"] = $left_time;
$license_time["SavedDateTime"] = $saved_date_time; $license_time["SavedDateTime"] = $saved_date_time;
$license_time["SubjectName"] = $subject_name;
return $license_time; return $license_time;
} }
@@ -67,8 +69,8 @@ function insert_default_time_data($maestro_id, $player_id, $default_start_time)
global $db_conn; global $db_conn;
$query = " $query = "
INSERT INTO license_time (MaestroID, PlayerID, StartTime) INSERT INTO license_time (MaestroID, PlayerID, StartTime, SubjectName)
VALUES (?, ?, ?); VALUES (?, ?, ?, '');
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $player_id, $default_start_time); $stmt->bind_param("iii", $maestro_id, $player_id, $default_start_time);
@@ -4,6 +4,7 @@ header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"]; $maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"]; $player_id = $_POST["PlayerID"];
$left_time = $_POST["LeftTime"]; $left_time = $_POST["LeftTime"];
$subject_name = $_POST["SubjectName"];
// echo $maestro_id." / ".$player_id; // echo $maestro_id." / ".$player_id;
include "./../lib/send_reply_json.php"; include "./../lib/send_reply_json.php";
@@ -11,38 +12,38 @@ include "./../setup/connect_db.php";
if($left_time == 0) if($left_time == 0)
reset_left_time($maestro_id, $player_id); reset_left_time($maestro_id, $player_id, $subject_name);
else else
update_left_time($maestro_id, $player_id, $left_time); update_left_time($maestro_id, $player_id, $left_time, $subject_name);
send_result_success(); send_result_success();
exit; exit;
function reset_left_time($maestro_id, $player_id) { function reset_left_time($maestro_id, $player_id, $subject_name) {
global $db_conn; global $db_conn;
$query = " $query = "
UPDATE license_time UPDATE license_time
SET LeftTime = null, SavedDateTime = null SET LeftTime = null, SavedDateTime = null, SubjectName = ''
WHERE MaestroID = ? AND PlayerID = ? WHERE MaestroID = ? AND PlayerID = ?
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestro_id, $player_id); $stmt->bind_param('sii', $subject_name, $maestro_id, $player_id);
$stmt->execute(); $stmt->execute();
} }
function update_left_time($maestro_id, $player_id, $left_time) { function update_left_time($maestro_id, $player_id, $left_time, $subject_name) {
global $db_conn; global $db_conn;
$query = " $query = "
UPDATE license_time UPDATE license_time
SET LeftTime = ?, SavedDateTime = NOW() SET LeftTime = ?, SavedDateTime = NOW(), SubjectName = ?
WHERE MaestroID = ? AND PlayerID = ? WHERE MaestroID = ? AND PlayerID = ?
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('iii', $left_time, $maestro_id, $player_id); $stmt->bind_param('isii', $left_time, $subject_name, $maestro_id, $player_id);
$stmt->execute(); $stmt->execute();
} }
@@ -4,29 +4,30 @@ header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"]; $maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"]; $player_id = $_POST["PlayerID"];
$start_time = $_POST["StartTime"]; $start_time = $_POST["StartTime"];
// echo $maestro_id." / ".$player_id; $subject_name = $_POST["SubjectName"];
// echo $maestro_id." / ".$player_id." / ".$start_time." / ".$subject_name;
include "./../lib/send_reply_json.php"; include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php"; include "./../setup/connect_db.php";
update_start_time($maestro_id, $player_id, $start_time); update_start_time($maestro_id, $player_id, $start_time, $subject_name);
send_result_success(); send_result_success();
exit; exit;
function update_start_time($maestro_id, $player_id, $start_time) { function update_start_time($maestro_id, $player_id, $start_time, $subject_name) {
global $db_conn; global $db_conn;
$query = " $query = "
UPDATE license_time UPDATE license_time
SET StartTime = ? SET StartTime = ?, SubjectName = ?
WHERE MaestroID = ? AND PlayerID = ? WHERE MaestroID = ? AND PlayerID = ?
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('iii', $start_time, $maestro_id, $player_id); $stmt->bind_param('isii', $start_time, $subject_name, $maestro_id, $player_id);
$stmt->execute(); $stmt->execute();
} }
+1
View File
@@ -5,6 +5,7 @@ CREATE TABLE license_time (
StartTime INT UNSIGNED NOT NULL, StartTime INT UNSIGNED NOT NULL,
LeftTime INT NOT NULL, LeftTime INT NOT NULL,
SavedDateTime DATETIME NOT NULL, SavedDateTime DATETIME NOT NULL,
SubjectName CHAR(50) NOT NULL,
FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID), FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
FOREIGN KEY (PlayerID) REFERENCES player(PlayerID) FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)