diff --git a/class/ExpressionBuilder.php b/class/ExpressionBuilder.php index 47ab51d..87776d2 100644 --- a/class/ExpressionBuilder.php +++ b/class/ExpressionBuilder.php @@ -20,6 +20,8 @@ class ExpressionBuilder } else { // is it a float? return (double)$rval; } + } else if (in_array(strtolower($rval), ["true", "false"]) ) { // it's a boolean + return $rval === "true"; } else if (str_starts_with($rval, '"') && str_ends_with($rval, '"')){ // it's a string return substr($rval, 1, strlen($rval) - 2); // strip leading and trailing quotes } else { // it must be a column name diff --git a/class/GroupMgr.php b/class/GroupMgr.php index c3cc548..eca14e3 100644 --- a/class/GroupMgr.php +++ b/class/GroupMgr.php @@ -403,4 +403,17 @@ class GroupMgr $a = $qb->where(["games", "CONTAINS", (int)$gameid])->select(["_id"])->getQuery()->fetch(); return array_map(fn($r) => $r["_id"], $a); } + + // Get group by group compound (name#id). + function getGroupByUniqueName(string $uniqueName): Group|null { + $a = $this->db->findOneBy([ function($g) use ($uniqueName) : bool { + $group = Group::fromArray($this, $g); + return $group->getUniqueName() === $uniqueName; + }]); + if ($a !== null) { + return Group::fromArray($this, $a); + } else { + return null; + } + } } \ No newline at end of file diff --git a/class/TestMgr.php b/class/TestMgr.php index 04c61af..e4729d1 100644 --- a/class/TestMgr.php +++ b/class/TestMgr.php @@ -400,7 +400,7 @@ class TestMgr } // Get test results by game ID. - function getResultsByGameId(string $gameid, string $filter, string $orderby, bool $exclude_challenge_data): array + function getResultsByGameId(string $gameid, string $filter, string $orderby, bool $exclude_challenge_data, array ...$furtherFilters): array { $qb = $this->db->createQueryBuilder(); $qb = $qb->where(["gameid", "=", (int)$gameid]); @@ -417,9 +417,19 @@ class TestMgr } $criteria = ExpressionBuilder::buildQuery($filter); + $qb->where($criteria); } + // add further filters + if (count($furtherFilters) > 0) { + foreach ($furtherFilters as $ff) { + if ($ff !== []) { + $qb->where($ff); + } + } + } + // ordering if (trim($orderby) !== "") { $ordering = ExpressionBuilder::buildOrdering($orderby); diff --git a/interface.php b/interface.php index 5572be7..1d8e3ac 100644 --- a/interface.php +++ b/interface.php @@ -481,12 +481,35 @@ function get_results_by_gameid(ReqHandler &$rh, array $params): array $gameid = trim($params["gameid"]); $filter = trim($params["filter"] ?? ""); $ordering = trim($params["orderby"] ?? ""); + $groups = explode_list(trim($params["groups"] ?? "")); $game = $gameMgr->getGame($gameid); $result = []; if (($game !== null) && ($game->isUserContributorOrOwner($user->getNickname()) || $user->hasQuizmasterPrivilege())) { - $game_results = $testMgr->getResultsByGameId($gameid, $filter, $ordering, true); + $group_filter = []; + if ($groups !== []) { + global $groupMgr; + $n = 0; + foreach ($groups as $groupname) { + if ($n > 0) { // place OR between each group criterion + $group_filter[] = "OR"; + } + $group = $groupMgr->getGroupByUniqueName($groupname); + if ($group !== null) { + $nicknames = $group->getMembers(); + $group_filter[] = ["nickname", "IN", $nicknames]; + } + $n++; + } + + // prepend filter criteria with AND +// if (count($group_filter) > 0) { +// $group_filter = ["AND", $group_filter]; +// } + } + + $game_results = $testMgr->getResultsByGameId($gameid, $filter, $ordering, true, $group_filter); $result = $game_results; } diff --git a/js/result_analyzer.js b/js/result_analyzer.js index fec5b8c..513b7ff 100644 --- a/js/result_analyzer.js +++ b/js/result_analyzer.js @@ -35,6 +35,7 @@ function fetch_results() { let filterF = document.getElementById("filter"); let orderbyF = document.getElementById("orderby"); + let groupsF = document.getElementById("groups"); let filter = autoconvert_datetime(filterF.value.trim()); @@ -44,7 +45,8 @@ function fetch_results() { action: "get_results_by_gameid", gameid: GAMEID, filter: filter.trim(), - orderby: orderbyF.value.trim() + orderby: orderbyF.value.trim(), + groups: groupsF.value.trim() }; request(req).then(resp => { diff --git a/result_analyzer.php b/result_analyzer.php index 0fb71e3..d0b208c 100644 --- a/result_analyzer.php +++ b/result_analyzer.php @@ -48,7 +48,8 @@ if (!$gameMgr->getGame($game_id)->isUserContributorOrOwner($user_data["nickname"
- + +