- report generation first deploy

This commit is contained in:
Wiesner András 2024-09-26 17:03:59 +02:00
parent ada4c5c496
commit 13743a5681
3 changed files with 50 additions and 14 deletions

View File

@ -7,7 +7,7 @@ require_once "common_func.php";
class ReportBuilder class ReportBuilder
{ {
static private function getStatsByFilters(int $gameid, string $filter, string $groups, string $ordering) static public function getStatsByFilters(int $gameid, string $filter, string $groups, string $ordering)
{ {
$groupMgr = new GroupMgr(); $groupMgr = new GroupMgr();
$testMgr = new TestMgr(); $testMgr = new TestMgr();
@ -133,9 +133,13 @@ class Report
return $tex; return $tex;
} }
// Save TeX representation const CONTENT_FILE = "content.tex";
function saveTeX(string $fileName) : void { const TITLE_FILE = "title.tex";
file_put_contents($fileName, $this->genTeX()); // TODO: cím!!!
// Save TeX representation.
function saveTeX(string $dir) : void {
file_put_contents($dir . DIRECTORY_SEPARATOR . self::CONTENT_FILE, $this->genTeX());
file_put_contents($dir . DIRECTORY_SEPARATOR . self::TITLE_FILE, $this->title);
} }
} }

View File

@ -2,12 +2,12 @@
require_once "class/TestMgr.php"; require_once "class/TestMgr.php";
$longopts = [ const longopts = [
"action:", // execute some CLI action "action:", // execute some CLI action
"tick" // tick timed objects (e.g. timed tests) "tick" // tick timed objects (e.g. timed tests)
]; ];
$options = getopt("", $longopts); $options = getopt("", longopts);
// CLI actions // CLI actions
if (isset($options["action"])) { if (isset($options["action"])) {

View File

@ -233,7 +233,8 @@ function access_test_data(string $testid): Test|null
return $test; return $test;
} }
function exclude_correct_answers(array &$challenges) : void { function exclude_correct_answers(array &$challenges): void
{
foreach ($challenges as &$challenge) { foreach ($challenges as &$challenge) {
$challenge["correct_answer"] = -1; $challenge["correct_answer"] = -1;
} }
@ -518,8 +519,35 @@ function get_results_by_gameid(ReqHandler &$rh, array $params): array
return $result; return $result;
} }
function generate_report(ReqHandler &$rh, array $params): string { function generate_report_by_groups(ReqHandler &$rh, array $params): string
{
global $gameMgr;
global $user;
$gameid = trim($params["gameid"]);
$filter = trim($params["filter"]);
$ordering = trim($params["orderby"]);
$groups = explode_list(trim($params["groups"])); // TODO: lehessen több csoportra is
$game = $gameMgr->getGame($gameid);
// verify game and access
if (($game === null) || (!$game->isUserContributorOrOwner($user->getNickname()) || $user->hasQuizmasterPrivilege())) {
return "FAIL";
}
// assemble report
$report = new Report($game->getName());
foreach ($groups as $groupname) {
$stats = ReportBuilder::getStatsByFilters($gameid, $filter, $groupname, $ordering);
$section = new ReportSection($groupname, $stats);
$report->addSection($section);
}
// generate latex
$report->saveTeX("report/");
return "OK";
} }
function generate_detailed_game_stats(ReqHandler &$rh, array $params): array function generate_detailed_game_stats(ReqHandler &$rh, array $params): array
@ -532,7 +560,8 @@ function generate_detailed_game_stats(ReqHandler &$rh, array $params): array
return $stats; return $stats;
} }
function delete_tests(ReqHandler &$rh, array $params): string { function delete_tests(ReqHandler &$rh, array $params): string
{
global $testMgr; global $testMgr;
$ids = explode_list(trim($params["ids"])); $ids = explode_list(trim($params["ids"]));
foreach ($ids as $id) { foreach ($ids as $id) {
@ -695,21 +724,24 @@ function get_all_users(ReqHandler &$rh, array $params): array
return $user_data_filtered; return $user_data_filtered;
} }
function get_user_groups(ReqHandler &$rh, array $params): array { function get_user_groups(ReqHandler &$rh, array $params): array
{
global $groupMgr; global $groupMgr;
$groups = $groupMgr->getUserGroupIDs($params["nickname"]); $groups = $groupMgr->getUserGroupIDs($params["nickname"]);
$groupMgr->resolveGroupIds($groups); $groupMgr->resolveGroupIds($groups);
return $groups; return $groups;
} }
function get_game_groups(ReqHandler &$rh, array $params): array { function get_game_groups(ReqHandler &$rh, array $params): array
{
global $groupMgr; global $groupMgr;
$groups = $groupMgr->getGameGroupIDs($params["gameid"]); $groups = $groupMgr->getGameGroupIDs($params["gameid"]);
$groupMgr->resolveGroupIds($groups); $groupMgr->resolveGroupIds($groups);
return $groups; return $groups;
} }
function change_group_members(ReqHandler &$rh, array $params): string { function change_group_members(ReqHandler &$rh, array $params): string
{
global $groupMgr; global $groupMgr;
global $user; global $user;
global $userMgr; global $userMgr;