aboutsummaryrefslogtreecommitdiff
path: root/lade_daten.php
diff options
context:
space:
mode:
Diffstat (limited to 'lade_daten.php')
-rw-r--r--lade_daten.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/lade_daten.php b/lade_daten.php
index 85f363a..eeff6c7 100644
--- a/lade_daten.php
+++ b/lade_daten.php
@@ -1,5 +1,5 @@
<?php
-/* Copyright 2025 Florian Fischer
+/* Copyright 2025-2026 Florian Fischer
* punktestand is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
@@ -126,4 +126,34 @@ function lade_daten($config, $schuljahr, $jahrgang): array {
}
return $daten;
}
+
+// Die Funktion schreibe_json schreibt, die Daten die von der Funktion lade_daten
+// zurückgegeben wurden in <script>-Tags als JSON in die Webseite.
+function schreibe_json($CONFIG, $SCHULJAHR, $JAHRGANG): array {
+ // Lade die Daten aus der Datenbank
+ $daten = lade_daten($CONFIG, $SCHULJAHR, $JAHRGANG);
+
+ // Bereite die Klassen und Ereignisse für Javascript vor
+ $daten_json = json_encode($daten);
+
+ // Ersetze die $JAHRGANG und $SCHULJAHR Platzhalter durch die Werte der Variablen
+ $bilder_pfad = str_replace(
+ array('$JAHRGANG', '$SCHULJAHR'),
+ array($JAHRGANG, $SCHULJAHR),
+ $CONFIG['bilder_pfad_format']);
+
+ $bilder_pfad_json = json_encode($bilder_pfad);
+ $streak_anzahl = json_encode($CONFIG['streak_anzahl'] ?? '');
+ $streak_ziel = json_encode($CONFIG['streak_ziel'] ?? '');
+
+ // Schreibe den Javascript Code mit unseren Daten in die Webseite
+ echo "<script>";
+ echo "const daten = $daten_json;\n";
+ echo "const bilder_pfad = $bilder_pfad_json;\n";
+ echo "const streak_anzahl = $streak_anzahl;\n";
+ echo "const streak_ziel = $streak_ziel;\n";
+ echo "</script>";
+
+ return $daten;
+}
?>