/** * Returls a list of contests where current user is the director * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiMyList(Request $r) { self::authenticateRequest($r); // Create array of relevant columns $relevant_columns = array('title', 'alias', 'start_time', 'finish_time', 'public', 'scoreboard_url', 'scoreboard_url_admin'); $contests = null; try { $contests = ContestsDAO::getAll(null, null, 'contest_id', 'DESC'); // If current user is not sys admin, then we need to filter out the contests where // the current user is not contest admin if (!Authorization::IsSystemAdmin($r['current_user_id'])) { $contests_all = $contests; $contests = array(); foreach ($contests_all as $c) { if (Authorization::IsContestAdmin($r['current_user_id'], $c)) { $contests[] = $c; } } } } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } $addedContests = array(); foreach ($contests as $c) { $c->toUnixTime(); $contestInfo = $c->asFilteredArray($relevant_columns); $addedContests[] = $contestInfo; } $response['results'] = $addedContests; $response['status'] = 'ok'; return $response; }
static function DeleteAllContests() { try { $contests = ContestsDAO::getAll(); foreach ($contests as $c) { ContestsDAO::delete($c); } } catch (ApiException $e) { // Propagate exception var_dump($e->getArrayMessage()); throw $e; } }
/** * Returls a list of contests where current user is the director * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiMyList(Request $r) { self::authenticateRequest($r); // Create array of relevant columns $relevant_columns = array("title", "alias", "start_time", "finish_time", "public", "scoreboard_url", "scoreboard_url_admin"); $contests = null; try { $contests = ContestsDAO::getAll(NULL, NULL, "contest_id", 'DESC'); // If current user is not sys admin, then we need to filter out the contests where // the current user is not contest admin if (!Authorization::IsSystemAdmin($r["current_user_id"])) { $contests_all = $contests; $contests = array(); foreach ($contests_all as $c) { if (Authorization::IsContestAdmin($r["current_user_id"], $c)) { $contests[] = $c; } } } } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } $addedContests = array(); foreach ($contests as $c) { $c->toUnixTime(); $contestInfo = $c->asFilteredArray($relevant_columns); $addedContests[] = $contestInfo; } $response["results"] = $addedContests; $response["status"] = "ok"; return $response; }