/** * Details of a scoreboard. Returns a list with all contests that belong to * the given scoreboard_alias * * @param Request $r */ public static function apiDetails(Request $r) { self::validateGroupScoreboard($r); $response = array(); // Fill contests $response["contests"] = array(); $response["ranking"] = array(); try { $groupScoreboardContestKey = new GroupsScoreboardsContests(array("group_scoreboard_id" => $r["scoreboard"]->group_scoreboard_id)); $r["gscs"] = GroupsScoreboardsContestsDAO::search($groupScoreboardContestKey); $i = 0; $contest_params = array(); foreach ($r["gscs"] as $gsc) { $contest = ContestsDAO::getByPK($gsc->contest_id); $response["contests"][$i] = $contest->asArray(); $response["contests"][$i]["only_ac"] = $gsc->only_ac; $response["contests"][$i]["weight"] = $gsc->weight; // Fill contest params to pass to scoreboardMerge $contest_params[$contest->alias] = array("only_ac" => $gsc->only_ac == 0 ? false : true, "weight" => $gsc->weight); $i++; } } catch (ApiException $ex) { throw $ex; } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $r["contest_params"] = $contest_params; // Fill details of this scoreboard $response["scoreboard"] = $r["scoreboard"]->asArray(); // If we have contests, calculate merged&filtered scoreboard if (count($response["contests"]) > 0) { // Get merged scoreboard $r["contest_aliases"] = ""; foreach ($response["contests"] as $contest) { $r["contest_aliases"] .= $contest["alias"] . ","; } $r["contest_aliases"] = rtrim($r["contest_aliases"], ","); try { $groupUsers = GroupsUsersDAO::search(new GroupsUsers(array("group_id" => $r["scoreboard"]->group_id))); $r["usernames_filter"] = ""; foreach ($groupUsers as $groupUser) { $user = UsersDAO::getByPK($groupUser->user_id); $r["usernames_filter"] .= $user->username . ","; } $r["usernames_filter"] = rtrim($r["usernames_filter"], ","); } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $mergedScoreboardResponse = ContestController::apiScoreboardMerge($r); $response["ranking"] = $mergedScoreboardResponse["ranking"]; } $response["status"] = "ok"; return $response; }
/** * Removes contest from scoreboard */ public function testRemoveContestFromScoreboard() { $groupData = GroupsFactory::createGroup(); $scoreboardData = GroupsFactory::createGroupScoreboard($groupData); $contestData = ContestsFactory::createContest(); ContestsFactory::addAdminUser($contestData, $groupData["owner"]); GroupsFactory::addContestToScoreboard($contestData, $scoreboardData, $groupData); $response = GroupScoreboardController::apiRemoveContest(new Request(array("auth_token" => self::login($groupData["owner"]), "group_alias" => $groupData["request"]["alias"], "scoreboard_alias" => $scoreboardData["request"]["alias"], "contest_alias" => $contestData["request"]["alias"]))); $this->assertEquals("ok", $response["status"]); $gscs = GroupsScoreboardsContestsDAO::search(new GroupsScoreboardsContests(array("group_scoreboard_id" => $scoreboardData["scoreboard"]->group_scoreboard_id, "contest_id" => $contestData["contest"]->contest_id))); $this->assertEquals(0, count($gscs)); }
/** * Removes contest from scoreboard */ public function testRemoveContestFromScoreboard() { $groupData = GroupsFactory::createGroup(); $scoreboardData = GroupsFactory::createGroupScoreboard($groupData); $contestData = ContestsFactory::createContest(); ContestsFactory::addAdminUser($contestData, $groupData['owner']); GroupsFactory::addContestToScoreboard($contestData, $scoreboardData, $groupData); $response = GroupScoreboardController::apiRemoveContest(new Request(array('auth_token' => self::login($groupData['owner']), 'group_alias' => $groupData['request']['alias'], 'scoreboard_alias' => $scoreboardData['request']['alias'], 'contest_alias' => $contestData['request']['alias']))); $this->assertEquals('ok', $response['status']); $gscs = GroupsScoreboardsContestsDAO::search(new GroupsScoreboardsContests(array('group_scoreboard_id' => $scoreboardData['scoreboard']->group_scoreboard_id, 'contest_id' => $contestData['contest']->contest_id))); $this->assertEquals(0, count($gscs)); }
/** * Details of a scoreboard. Returns a list with all contests that belong to * the given scoreboard_alias * * @param Request $r */ public static function apiDetails(Request $r) { self::validateGroupScoreboard($r); $response = array(); // Fill contests $response['contests'] = array(); $response['ranking'] = array(); try { $groupScoreboardContestKey = new GroupsScoreboardsContests(array('group_scoreboard_id' => $r['scoreboard']->group_scoreboard_id)); $r['gscs'] = GroupsScoreboardsContestsDAO::search($groupScoreboardContestKey); $i = 0; $contest_params = array(); foreach ($r['gscs'] as $gsc) { $contest = ContestsDAO::getByPK($gsc->contest_id); $response['contests'][$i] = $contest->asArray(); $response['contests'][$i]['only_ac'] = $gsc->only_ac; $response['contests'][$i]['weight'] = $gsc->weight; // Fill contest params to pass to scoreboardMerge $contest_params[$contest->alias] = array('only_ac' => $gsc->only_ac == 0 ? false : true, 'weight' => $gsc->weight); $i++; } } catch (ApiException $ex) { throw $ex; } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $r['contest_params'] = $contest_params; // Fill details of this scoreboard $response['scoreboard'] = $r['scoreboard']->asArray(); // If we have contests, calculate merged&filtered scoreboard if (count($response['contests']) > 0) { // Get merged scoreboard $r['contest_aliases'] = ''; foreach ($response['contests'] as $contest) { $r['contest_aliases'] .= $contest['alias'] . ','; } $r['contest_aliases'] = rtrim($r['contest_aliases'], ','); try { $groupUsers = GroupsUsersDAO::search(new GroupsUsers(array('group_id' => $r['scoreboard']->group_id))); $r['usernames_filter'] = ''; foreach ($groupUsers as $groupUser) { $user = UsersDAO::getByPK($groupUser->user_id); $r['usernames_filter'] .= $user->username . ','; } $r['usernames_filter'] = rtrim($r['usernames_filter'], ','); } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $mergedScoreboardResponse = ContestController::apiScoreboardMerge($r); $response['ranking'] = $mergedScoreboardResponse['ranking']; } $response['status'] = 'ok'; return $response; }