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