diff --git a/class/ReportBuilder.php b/class/ReportBuilder.php index 43d50b7..4e1dc16 100644 --- a/class/ReportBuilder.php +++ b/class/ReportBuilder.php @@ -7,7 +7,7 @@ require_once "common_func.php"; 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(); $testMgr = new TestMgr(); @@ -122,7 +122,7 @@ class Report { $this->sections[] = $section; } - + // Generate TeX representation. function genTeX() :string { @@ -133,9 +133,13 @@ class Report return $tex; } - // Save TeX representation - function saveTeX(string $fileName) : void { - file_put_contents($fileName, $this->genTeX()); // TODO: cím!!! + const CONTENT_FILE = "content.tex"; + const TITLE_FILE = "title.tex"; + + // 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); } } diff --git a/cli_actions.php b/cli_actions.php index 744c95e..1ed8da6 100644 --- a/cli_actions.php +++ b/cli_actions.php @@ -2,12 +2,12 @@ require_once "class/TestMgr.php"; -$longopts = [ +const longopts = [ "action:", // execute some CLI action "tick" // tick timed objects (e.g. timed tests) ]; -$options = getopt("", $longopts); +$options = getopt("", longopts); // CLI actions if (isset($options["action"])) { diff --git a/interface.php b/interface.php index 2f3736a..488517a 100644 --- a/interface.php +++ b/interface.php @@ -233,7 +233,8 @@ function access_test_data(string $testid): Test|null return $test; } -function exclude_correct_answers(array &$challenges) : void { +function exclude_correct_answers(array &$challenges): void +{ foreach ($challenges as &$challenge) { $challenge["correct_answer"] = -1; } @@ -518,8 +519,35 @@ function get_results_by_gameid(ReqHandler &$rh, array $params): array 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 @@ -532,7 +560,8 @@ function generate_detailed_game_stats(ReqHandler &$rh, array $params): array return $stats; } -function delete_tests(ReqHandler &$rh, array $params): string { +function delete_tests(ReqHandler &$rh, array $params): string +{ global $testMgr; $ids = explode_list(trim($params["ids"])); foreach ($ids as $id) { @@ -695,21 +724,24 @@ function get_all_users(ReqHandler &$rh, array $params): array return $user_data_filtered; } -function get_user_groups(ReqHandler &$rh, array $params): array { +function get_user_groups(ReqHandler &$rh, array $params): array +{ global $groupMgr; $groups = $groupMgr->getUserGroupIDs($params["nickname"]); $groupMgr->resolveGroupIds($groups); return $groups; } -function get_game_groups(ReqHandler &$rh, array $params): array { +function get_game_groups(ReqHandler &$rh, array $params): array +{ global $groupMgr; $groups = $groupMgr->getGameGroupIDs($params["gameid"]); $groupMgr->resolveGroupIds($groups); return $groups; } -function change_group_members(ReqHandler &$rh, array $params): string { +function change_group_members(ReqHandler &$rh, array $params): string +{ global $groupMgr; global $user; global $userMgr; @@ -742,7 +774,7 @@ $rh->add("update_group", ["groupname", "description", "owner", "editors", "id"], $rh->add("delete_groups", ["ids"], PRIVILEGE_QUIZMASTER, "delete_groups", RESP_PLAIN, "Delete group."); $rh->add("get_all_groups", [], PRIVILEGE_QUIZMASTER, "get_all_groups", RESP_JSON, "Get all player groups."); $rh->add("search_groups", ["needle"], PRIVILEGE_QUIZMASTER, "search_groups", RESP_JSON, "Serach and fetch player groups."); -$rh->add("change_group_members", ["groupid", "add", "remove"], PRIVILEGE_QUIZMASTER,"change_group_members", RESP_PLAIN, "Change group members."); +$rh->add("change_group_members", ["groupid", "add", "remove"], PRIVILEGE_QUIZMASTER, "change_group_members", RESP_PLAIN, "Change group members."); $rh->add(["create_user", "update_user"], ["nickname", "password", "realname", "privilege"], PRIVILEGE_QUIZMASTER, "create_update_user", RESP_PLAIN, "Create or update user."); $rh->add("delete_users", ["users"], PRIVILEGE_QUIZMASTER, "delete_users", RESP_PLAIN, "Delete users.");