54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
define("TEAMS", [
|
|
"|Math Lads|"
|
|
]);
|
|
|
|
define("TEAM_COLORS", [
|
|
"|Math Lads|" => "#2ca02c"
|
|
]);
|
|
|
|
define("QUESTION_POINTS", [
|
|
"1" => 1
|
|
]);
|
|
|
|
define("MEDAL_COLORS", ["amber", "gray", "orange"]);
|
|
|
|
function loadScoreFile() {
|
|
$result = file_get_contents("score.json");
|
|
if ($result === false) {
|
|
throw new Exception("Score-bestand kan niet geopend worden.");
|
|
}
|
|
|
|
$teamQuestionDates = array_fill_keys(TEAMS, []);
|
|
|
|
$scoreJson = json_decode($result, true);
|
|
if ($scoreJson === false) {
|
|
throw new Exception("Er is een fout opgetreden bij het decoderen van het score-bestand.");
|
|
}
|
|
|
|
return array_merge($teamQuestionDates, $scoreJson);
|
|
}
|
|
|
|
function updateScoreFile($teamQuestionDates) {
|
|
$scoreJson = json_encode($teamQuestionDates, JSON_PRETTY_PRINT);
|
|
if ($scoreJson === false) {
|
|
throw new Exception("Er is een fout opgetreden bij het coderen van het score-bestand.");
|
|
}
|
|
|
|
$result = file_put_contents("score.json", $scoreJson."\n");
|
|
if ($result === false) {
|
|
throw new Exception("Score-bestand kan niet bijgewerkt worden.");
|
|
}
|
|
}
|
|
|
|
function showError($error) {
|
|
exit($error." Stuur een berichtje naar kerstpuzzel@deleidscheflesch.nl, dan wordt het zo voor je gefixt!");
|
|
}
|
|
|
|
function calculatePoints(array $questionDates) {
|
|
$points = array_intersect_key(QUESTION_POINTS, $questionDates);
|
|
return array_sum($points);
|
|
}
|
|
|
|
?>
|