- game result summary added
This commit is contained in:
parent
665ef62b3d
commit
055be5b6a4
@ -100,6 +100,14 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
|
||||
<input type="checkbox" id="repeatable">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Eredmények:
|
||||
</td>
|
||||
<td>
|
||||
<input type="button" value="Mutat" onclick="list_results_by_game(EDITED_GAME)">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
</section>
|
||||
@ -110,6 +118,15 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section class="window" shown="false" id="results_viewer_window">
|
||||
<section class="window-inner">
|
||||
<section id="results_display">
|
||||
|
||||
</section>
|
||||
<input type="button" value="Bezárás" onclick="hide('results_viewer_window')">
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
list_all_games();
|
||||
</script>
|
||||
|
@ -47,6 +47,7 @@ if ((session_status() != PHP_SESSION_ACTIVE) || (!isset($_SESSION["nickname"]))
|
||||
$user_data = get_user($_SESSION["nickname"]);
|
||||
$nickname = $user_data["nickname"];
|
||||
$privilege = $user_data["privilege"];
|
||||
$is_quizmaster = $privilege === QUIZMASTER_NICKNAME;
|
||||
|
||||
// login-requiring actions
|
||||
switch ($action) {
|
||||
@ -160,7 +161,7 @@ if (($privilege !== PRIVILEGE_CREATOR) && ($privilege !== PRIVILEGE_QUIZMASTER))
|
||||
goto print_result;
|
||||
}
|
||||
|
||||
$requester_nickname = ($privilege === PRIVILEGE_QUIZMASTER) ? "*" : $nickname; // "*" means every game
|
||||
$requester_nickname = $is_quizmaster ? "*" : $nickname; // "*" means every game
|
||||
|
||||
switch ($action) {
|
||||
case "create_game":
|
||||
@ -184,7 +185,7 @@ switch ($action) {
|
||||
// remove group ID's this user cannot edit
|
||||
$groupids_with_editor_access = [];
|
||||
foreach ($groupids as $groupid) {
|
||||
if (is_user_editor_to_group($groupid, $nickname) || ($privilege === PRIVILEGE_QUIZMASTER)) {
|
||||
if (is_user_editor_to_group($groupid, $nickname) || $is_quizmaster) {
|
||||
$groupids_with_editor_access[] = $groupid;
|
||||
}
|
||||
}
|
||||
@ -192,7 +193,7 @@ switch ($action) {
|
||||
// create or update
|
||||
if (!$update) {
|
||||
create_game($name, $owner, $description);
|
||||
} else if (is_user_contributor_to_game($gameid, $nickname) || ($privilege === PRIVILEGE_QUIZMASTER)) {
|
||||
} else if (is_user_contributor_to_game($gameid, $nickname) || $is_quizmaster) {
|
||||
$game_data = get_game($gameid);
|
||||
if (count($game_data) !== 0) {
|
||||
// group management
|
||||
@ -271,7 +272,7 @@ switch ($action) {
|
||||
{
|
||||
$gameid = ($_REQUEST["gameid"] ?: "");
|
||||
$game_data = get_game($gameid);
|
||||
if ((count($game_data) > 0) && (($requester_nickname === "*") || (is_user_contributor_to_game($gameid, $requester_nickname)))) {
|
||||
if ((count($game_data) > 0) && ($is_quizmaster || (is_user_contributor_to_game($gameid, $requester_nickname)))) {
|
||||
$result = file_get_contents(get_game_file_by_gameid($gameid));
|
||||
}
|
||||
}
|
||||
@ -299,6 +300,14 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "get_results_by_gameid":
|
||||
{
|
||||
$gameid = trim($_REQUEST["gameid"] ?: "");
|
||||
if (($gameid !== "") && (is_user_contributor_to_game($gameid, $nickname) || $is_quizmaster)) {
|
||||
$result = json_encode(get_results_by_gameid($gameid));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// quizmaster actions
|
||||
|
@ -211,6 +211,54 @@ function edit_challenges(game) {
|
||||
});
|
||||
}
|
||||
|
||||
function list_results_by_game(game) {
|
||||
let req = {action: "get_results_by_gameid", gameid: game["_id"]};
|
||||
request(req).then(resp => {
|
||||
let rd = document.getElementById("results_display");
|
||||
let results = JSON.parse(resp);
|
||||
if (results.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
rd.innerHTML = "";
|
||||
let n = results.length;
|
||||
|
||||
results.sort((a, b) => {
|
||||
return Number(b["testid"]) - Number(a["testid"])
|
||||
}); // sort records by ID
|
||||
|
||||
results.forEach((record) => {
|
||||
console.log(record);
|
||||
|
||||
let test_summary_record = document.createElement("section");
|
||||
test_summary_record.classList.add("test-summary-record");
|
||||
|
||||
let sequence_number_sec = document.createElement("section");
|
||||
sequence_number_sec.classList.add("summary-name-id-block");
|
||||
sequence_number_sec.innerText = record["nickname"] + "#" + n;
|
||||
let duration_sec = document.createElement("section");
|
||||
duration_sec.classList.add("summary-duration");
|
||||
let start_time = unix_time_to_human_readable(record["start_time"]);
|
||||
let end_time = unix_time_to_human_readable(record["end_time"]);
|
||||
|
||||
let summary = record["summary"];
|
||||
duration_sec.innerHTML = `${start_time}-<br>${end_time}<br>${summary["correct_answer_n"]}/${summary["challenge_n"]}`;
|
||||
|
||||
let percentage = document.createElement("section");
|
||||
percentage.classList.add("summary-percentage");
|
||||
let r = Math.floor((summary["correct_answer_n"] / summary["challenge_n"]) * 100);
|
||||
percentage.innerHTML = `${r}%`;
|
||||
|
||||
test_summary_record.append(sequence_number_sec, duration_sec, percentage);
|
||||
rd.appendChild(test_summary_record);
|
||||
|
||||
n--;
|
||||
|
||||
});
|
||||
show("results_viewer_window");
|
||||
});
|
||||
}
|
||||
|
||||
// function hint_all_groups(target_element_id) {
|
||||
// const hintbox_insert_fn = (record) => {
|
||||
// let targetF = document.getElementById(target_element_id);
|
||||
|
3
main.php
3
main.php
@ -35,6 +35,9 @@ $privilege = $user_data["privilege"];
|
||||
<section id="user_info" class="info-pane-element">
|
||||
<?= $user_data["nickname"]; ?>
|
||||
<section style="margin-top: 1em">
|
||||
<php? if ($privilege === PRIVILEGE_QUIZMASTER) { ?>
|
||||
<span style="font-size: 10pt;"><?= $_COOKIE[SESSION_NAME] ?></span><br>
|
||||
<php? } ?>
|
||||
<input type="button" value="Beállítások"><br>
|
||||
<input type="button" value="Kijelentkezés" onclick="logout()">
|
||||
</section>
|
||||
|
@ -60,4 +60,22 @@ section.window-inner td {
|
||||
section.window-inner tr td:first-of-type {
|
||||
min-width: 10em;
|
||||
text-align: right !important;
|
||||
}
|
||||
|
||||
.summary-name-id-block {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
background-color: #176767;
|
||||
color: whitesmoke;
|
||||
padding: 0.5em;
|
||||
height: 3.5em;
|
||||
top: -1.1em;
|
||||
box-shadow: 5px 0 #d3e5e5;
|
||||
min-width: 12em;
|
||||
}
|
||||
|
||||
.test-summary-record {
|
||||
min-width: 25em;
|
||||
height: 3.5em;
|
||||
overflow: clip;
|
||||
}
|
@ -97,7 +97,7 @@ section#user_info {
|
||||
}
|
||||
|
||||
section#user_info:hover {
|
||||
height: 5em;
|
||||
height: 6em;
|
||||
border-width: 0.5em;
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ section.test-summary-record {
|
||||
background-color: #176767;
|
||||
color: whitesmoke;
|
||||
padding: 0.5em;
|
||||
width: 1.5em;
|
||||
/*width: 1.5em;*/
|
||||
box-shadow: 5px 0 #d3e5e5;
|
||||
}
|
||||
|
||||
|
@ -179,4 +179,11 @@ function conclude_test(string $testid) {
|
||||
];
|
||||
|
||||
update_test($test_data);
|
||||
}
|
||||
|
||||
function get_results_by_gameid(string $gameid) : array {
|
||||
global $testdb;
|
||||
$fetch_criteria = ["gameid", "=", (int)$gameid];
|
||||
$test_data_array = $testdb->findBy($fetch_criteria);
|
||||
return $test_data_array;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user