- checking maintenance in each file added
- a few CLI commands added - ticking and concluding expired tests added
This commit is contained in:
parent
9bb77e8c4e
commit
e313923ad4
8
check_maintenance.php
Normal file
8
check_maintenance.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
require_once "globals.php";
|
||||||
|
|
||||||
|
// check MAINTENANCE file
|
||||||
|
if (file_exists(MAINTENANCE_FLAG_FILE)) {
|
||||||
|
header("Location: maintenance.html");
|
||||||
|
exit(0);
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
require_once "AutoStoring.php";
|
require_once "AutoStoring.php";
|
||||||
|
|
||||||
class Game extends AutoStoring
|
class Game extends AutoStoring
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
require_once "AutoStoring.php";
|
require_once "AutoStoring.php";
|
||||||
|
|
||||||
require_once "privilege_levels.php";
|
require_once "privilege_levels.php";
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
require_once "AutoStoring.php";
|
require_once "AutoStoring.php";
|
||||||
|
|
||||||
require_once "ExpressionBuilder.php";
|
require_once "ExpressionBuilder.php";
|
||||||
|
|
||||||
|
require_once "globals.php";
|
||||||
|
|
||||||
const TEST_ONGOING = "ongoing";
|
const TEST_ONGOING = "ongoing";
|
||||||
const TEST_CONCLUDED = "concluded";
|
const TEST_CONCLUDED = "concluded";
|
||||||
|
|
||||||
@ -11,11 +15,22 @@ class TestSummary
|
|||||||
{
|
{
|
||||||
public int $challengeN; // Number of challenges
|
public int $challengeN; // Number of challenges
|
||||||
public int $correctAnswerN; // Number of correct answers
|
public int $correctAnswerN; // Number of correct answers
|
||||||
|
private float $percentage; // Ratio of correct answers
|
||||||
|
|
||||||
|
// Calculate percentage.
|
||||||
|
private function calculatePercentage() : void {
|
||||||
|
if ($this->challengeN > 0) {
|
||||||
|
$this->percentage = $this->correctAnswerN / (double)$this->challengeN * 100.0;
|
||||||
|
} else { // avoid division by zero
|
||||||
|
$this->percentage = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function __construct(int $challengeN, int $correctAnswerN)
|
function __construct(int $challengeN, int $correctAnswerN)
|
||||||
{
|
{
|
||||||
$this->challengeN = $challengeN;
|
$this->challengeN = $challengeN;
|
||||||
$this->correctAnswerN = $correctAnswerN;
|
$this->correctAnswerN = $correctAnswerN;
|
||||||
|
$this->calculatePercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get challenge count.
|
// Get challenge count.
|
||||||
@ -33,6 +48,7 @@ class TestSummary
|
|||||||
function setCorrectAnswerN(int $correctAnswerN): void
|
function setCorrectAnswerN(int $correctAnswerN): void
|
||||||
{
|
{
|
||||||
$this->correctAnswerN = $correctAnswerN;
|
$this->correctAnswerN = $correctAnswerN;
|
||||||
|
$this->calculatePercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get ratio of correct results.
|
// Get ratio of correct results.
|
||||||
@ -50,7 +66,7 @@ class TestSummary
|
|||||||
// Convert to array.
|
// Convert to array.
|
||||||
function toArray(): array
|
function toArray(): array
|
||||||
{
|
{
|
||||||
return ["challenge_n" => $this->challengeN, "correct_answer_n" => $this->correctAnswerN];
|
return ["challenge_n" => $this->challengeN, "correct_answer_n" => $this->correctAnswerN, "percentage" => $this->percentage];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +174,7 @@ class Test extends AutoStoring
|
|||||||
// auto-conclude time-constrained test if expired
|
// auto-conclude time-constrained test if expired
|
||||||
if ($this->timeLimited && $this->isOngoing() && ($this->endLimitTime <= time())) {
|
if ($this->timeLimited && $this->isOngoing() && ($this->endLimitTime <= time())) {
|
||||||
$this->concludeTest();
|
$this->concludeTest();
|
||||||
|
$this->endTime = $this->endLimitTime; // date back end time to the limiting value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,4 +502,31 @@ class TestMgr
|
|||||||
// match challenges
|
// match challenges
|
||||||
return $aggregated;
|
return $aggregated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upgrade test. Just load tests and save them.
|
||||||
|
function upgradeTests(array $ids = []) : void {
|
||||||
|
$a = [];
|
||||||
|
if ($ids === []) {
|
||||||
|
$a = $this->db->findAll();
|
||||||
|
} else {
|
||||||
|
$a = $this->db->findBy(["_id", "IN", $ids]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($a as $t) {
|
||||||
|
$test = new Test($this, $t);
|
||||||
|
$test->storeMods();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract timed test IDs. Scan the database for tests with time limit ON.
|
||||||
|
function extractExpiredTimedTestIds(bool $ongoingOnly = true) : array {
|
||||||
|
$query = [["time_limited", "=", true], "AND", ["end_limit_time", "<", time()]];
|
||||||
|
if ($ongoingOnly) {
|
||||||
|
$query = [ ...$query, "AND", ["state", "=", TEST_ONGOING]];
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb = $this->db->createQueryBuilder();
|
||||||
|
$a = $qb->where($query)->select(["_id"])->orderBy(["_id" => "ASC"])->getQuery()->fetch();
|
||||||
|
return array_map(fn($a) => $a["_id"], $a);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
require_once "common_func.php";
|
require_once "common_func.php";
|
||||||
|
|
||||||
require_once "AutoStoring.php";
|
require_once "AutoStoring.php";
|
||||||
|
39
cli_actions.php
Normal file
39
cli_actions.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "class/TestMgr.php";
|
||||||
|
|
||||||
|
$longopts = [
|
||||||
|
"action:", // execute some CLI action
|
||||||
|
"tick" // tick timed objects (e.g. timed tests)
|
||||||
|
];
|
||||||
|
|
||||||
|
$options = getopt("", $longopts);
|
||||||
|
|
||||||
|
// CLI actions
|
||||||
|
if (isset($options["action"])) {
|
||||||
|
$action = $options["action"];
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case "upgrade_tests":
|
||||||
|
{
|
||||||
|
printf("Upgrading tests...");
|
||||||
|
$testMgr = new TestMgr();
|
||||||
|
$testMgr->upgradeTests();
|
||||||
|
printf("OK!\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "get_timed_tests":
|
||||||
|
{
|
||||||
|
$testMgr = new TestMgr();
|
||||||
|
printf("Expired timed tests: %s\n", join(", ", $testMgr->extractExpiredTimedTestIds()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tick tests
|
||||||
|
if (isset($options["tick"])) {
|
||||||
|
$testMgr = new TestMgr();
|
||||||
|
$timedTestIDs = $testMgr->extractExpiredTimedTestIds();
|
||||||
|
$testMgr->upgradeTests($timedTestIDs);
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
//require_once "frames_common.php";
|
//require_once "frames_common.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
@ -35,9 +35,3 @@ function init_datadir() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check MAINTENANCE file
|
|
||||||
if (file_exists(MAINTENANCE_FLAG_FILE)) {
|
|
||||||
header("Location: maintenance.html");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
//ini_set('display_startup_errors', '1');
|
//ini_set('display_startup_errors', '1');
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
@ -16,14 +18,6 @@ if (!isset($_REQUEST["action"])) {
|
|||||||
|
|
||||||
require_once "common_func.php";
|
require_once "common_func.php";
|
||||||
|
|
||||||
// load databases only if something meaningful have arrived
|
|
||||||
//require_once "usermgr.php";
|
|
||||||
//require_once "groupmgr.php";
|
|
||||||
//require_once "gamemgr.php";
|
|
||||||
//require_once "testmgr.php";
|
|
||||||
//
|
|
||||||
//require_once "controller.php";
|
|
||||||
|
|
||||||
require_once "class/ReqHandler.php";
|
require_once "class/ReqHandler.php";
|
||||||
|
|
||||||
require_once "class/UserMgr.php";
|
require_once "class/UserMgr.php";
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
|
||||||
|
2
main.php
2
main.php
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
|
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "privilege_levels.php";
|
require_once "privilege_levels.php";
|
||||||
|
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "check_maintenance.php";
|
||||||
|
|
||||||
require_once "globals.php";
|
require_once "globals.php";
|
||||||
require_once "autologin.php";
|
require_once "autologin.php";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user