Fix: remove old codes - best record

This commit is contained in:
2018-10-23 23:41:20 +09:00
parent f0dc660018
commit c7a5926b21
16 changed files with 47 additions and 401 deletions
@@ -109,7 +109,7 @@ function get_high_score_list($maestro_id, $player_id, $appList) {
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id);
$stmt->execute();
$stmt->bind_result($best_record);
$stmt->bind_result($highest_record);
$returnValue = $stmt->fetch();
$stmt->close();
@@ -120,10 +120,10 @@ function get_high_score_list($maestro_id, $player_id, $appList) {
// $row_array['maestro_id'] = $maestro_id;
// $row_array['player_id'] = $player_id;
$row_array['AppID'] = $app_id_list;
if($best_record === NULL)
$row_array['BestRecord'] = 0;
if($highest_record === NULL)
$row_array['AppHighestRecord'] = 0;
else
$row_array['BestRecord'] = $best_record;
$row_array['AppHighestRecord'] = $highest_record;
array_push($return_array, $row_array);
}
@@ -101,15 +101,20 @@ function get_high_score_list($maestro_id, $player_id, $appList) {
$app_id_list = $appList[$i]['AppID'];
$query = "
SELECT MAX(BR.BestRecord)
SELECT MAX(AHR.HighestRecord)
FROM app AS A
INNER JOIN best_record AS BR
ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ?
INNER JOIN app_highest_record AS AHR
ON A.AppID = ? AND A.AppID = AHR.AppID AND AHR.MaestroID = ? AND AHR.PlayerID = ?
ORDER BY A.AppID ASC";
// SELECT MAX(BR.AppHighestRecord)
// FROM app AS A
// INNER JOIN best_record AS BR
// ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ?
// ORDER BY A.AppID ASC";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id);
$stmt->execute();
$stmt->bind_result($best_record);
$stmt->bind_result($highest_record);
$returnValue = $stmt->fetch();
$stmt->close();
@@ -120,10 +125,10 @@ function get_high_score_list($maestro_id, $player_id, $appList) {
// $row_array['maestro_id'] = $maestro_id;
// $row_array['player_id'] = $player_id;
$row_array['AppID'] = $app_id_list;
if($best_record === NULL)
$row_array['BestRecord'] = 0;
if($highest_record === NULL)
$row_array['AppHighestRecord'] = 0;
else
$row_array['BestRecord'] = $best_record;
$row_array['AppHighestRecord'] = $highest_record;
array_push($return_array, $row_array);
}
@@ -1,41 +0,0 @@
<?php
header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"];
$app_id = $_POST["AppID"];
include "./../setup/connect_db.php";
$replyJSON = array();
$replyJSON["BestRecord"] = get_best_record($maestro_id, $app_id, $player_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, $player_id) {
global $db_conn;
$query = "
SELECT BestRecord
FROM best_record
WHERE MaestroID = ? AND AppID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW())
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
$stmt->execute();
$stmt->bind_result($best_record);
$stmt->fetch();
$stmt->close();
return $best_record;
}
?>
@@ -1,93 +0,0 @@
<?php
header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"];
$app_id = $_POST["AppID"];
$best_record = $_POST["BestRecord"];
// echo $best_record." / ";
include "./../setup/connect_db.php";
include "./../lib/app_highest_record.php";
$prev_best_record_id = -1;
$prev_best_record = 0;
$prev_best_record_id = get_best_record($maestro_id, $app_id, $player_id);
echo "id : ".$prev_best_record_id." ".$prev_best_record;
if($prev_best_record_id === null || $prev_best_record_id < 0) {
// echo "insert";
insert_best_record($maestro_id, $app_id, $player_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);
}
}
$app_highest_record = get_app_highest_record($maestro_id, $app_id, $player_id);
if($app_highest_record == null) {
insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record);
}
else if($best_record > $app_highest_record) {
remove_app_highest_record($maestro_id, $app_id, $player_id);
insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record);
}
$db_conn->close();
function get_best_record($maestro_id, $app_id, $player_id) {
global $db_conn;
global $prev_best_record_id, $prev_best_record;
$query = "
SELECT BestRecordID, BestRecord
FROM best_record
WHERE MaestroID = ? AND AppID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW())
/*AND HOUR(RecordDateTime) = HOUR(NOW())*/
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $app_id, $player_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, $player_id, $best_record) {
global $db_conn;
$query = "
INSERT INTO best_record (MaestroID, PlayerID, AppID, BestRecord, RecordDateTime)
VALUES (?, ?, ?, ?, NOW());
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $best_record);
$stmt->execute();
}
function update_best_record($prev_best_record_id, $best_record) {
global $db_conn;
$query = "
UPDATE best_record
SET BestRecord = ?, RecordDateTime = NOW()
WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW())
/* AND HOUR(RecordDateTime) = HOUR(NOW()) */
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('di', $best_record, $prev_best_record_id);
$stmt->execute();
}
?>