From 95b21c6305656fac01642638af8c9971adfed20d Mon Sep 17 00:00:00 2001 From: Matthias Grief Date: Fri, 15 Nov 2024 23:42:46 +0100 Subject: [PATCH] =?UTF-8?q?Downloadlinks=20und=20Erkl=C3=A4rungstexte=20fu?= =?UTF-8?q?nktional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webseite/classes/SubjectData.php | 19 +++++----- webseite/classes/TopicData.php | 35 +++++++++++-------- webseite/classes/Util.php | 28 ++++++++++++--- .../deutsch/topics/topic4/properties.json | 2 +- .../deutsch/topics/topic5/properties.json | 2 +- .../deutsch/topics/topic6/properties.json | 2 +- .../deutsch/topics/topic7/properties.json | 2 +- .../deutsch/topics/topic8/properties.json | 2 +- .../subjects/mathe/topics/topic1/article.html | 5 +++ .../mathe/topics/topic1/properties.json | 3 +- .../mathe/topics/topic2/properties.json | 4 +-- .../mathe/topics/topic3/properties.json | 4 +-- webseite/homepage.php | 1 + webseite/subject.php | 35 +++++++++---------- webseite/topic.php | 25 ++++++++++--- 15 files changed, 106 insertions(+), 63 deletions(-) diff --git a/webseite/classes/SubjectData.php b/webseite/classes/SubjectData.php index ad82c1e..180df3d 100644 --- a/webseite/classes/SubjectData.php +++ b/webseite/classes/SubjectData.php @@ -48,7 +48,7 @@ class SubjectData * Gibt alle Fächer als SubjectData Objekt zurück * @return array Alle Fächer als SubjectData */ - public static function getAll() : array + public static function getAll(): array { $result = array(); @@ -60,7 +60,7 @@ class SubjectData } $subjectData = SubjectData::fromName($subjectName); - if(!isset($subjectData)) { + if (!isset($subjectData)) { continue; } @@ -75,7 +75,7 @@ class SubjectData * @param $subjectId string Die eindeutige ID des Faches * @return SubjectData|null Das Fach zu der ID oder null, wenn kein entsprechendes Fach gefunden wurde */ - public static function fromName(string $subjectId) : SubjectData|null + public static function fromName(string $subjectId): SubjectData|null { $result = new SubjectData(); @@ -84,34 +84,37 @@ class SubjectData $subjectDirectory = "config/subjects/$subjectId"; $filename = "$subjectDirectory/properties.json"; $data = Util::parseJsonFromFile($filename); + if(!isset($data)) { + return null; + } $result->id = $subjectId; - if(isset($data->displayName)) { + if (isset($data->displayName)) { $result->displayName = $data->displayName; } else { return null; } - if(isset($data->description)) { + if (isset($data->description)) { $result->description = $data->description; } else { return null; } - if(isset($data->color)) { + if (isset($data->color)) { $result->color = $data->color; } else { return null; } - if(isset($data->buttonText)) { + if (isset($data->buttonText)) { $result->buttonText = $data->buttonText; } else { return null; } - if(isset($data->icon)) { + if (isset($data->icon)) { $result->icon = $data->icon; } else { return null; diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index 1fd8900..ea09195 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -39,7 +39,7 @@ class TopicData public array $files; /** - * @var string Der gesamte Erklärungstext zum Thema, enthält fertiges HTML + * @var string Der gesamte Erklärungstext zum Thema, enthält fertiges HTML und LATEX Formelsyntax für MathJax https://docs.mathjax.org/en/latest/basic/mathematics.html */ public string $article; @@ -48,7 +48,7 @@ class TopicData * @param $subjectId string Die ID des Faches * @return array Alle zugehörigen Themen als TopicData Objekte */ - public static function getAll(string $subjectId) : array + public static function getAll(string $subjectId): array { $result = array(); @@ -59,7 +59,7 @@ class TopicData continue; } $topicData = TopicData::fromName($subjectId, $topicName); - if(!isset($topicData)) { + if (!isset($topicData)) { continue; } @@ -82,47 +82,52 @@ class TopicData $subjectId = Util::removeIllegalCharacters($subjectId); $topicId = Util::removeIllegalCharacters($topicId); - $topicDirectory = "config/subjects/$subjectId/topics"; - $filename = "$topicDirectory/$topicId/properties.json"; - $data = Util::parseJsonFromFile($filename); + $topicsDirectory = "config/subjects/$subjectId/topics"; + $topicDataDirectory = "$topicsDirectory/$topicId"; + $data = Util::parseJsonFromFile("$topicDataDirectory/properties.json"); + if(!isset($data)) { + return null; + } $result->id = $topicId; $result->subjectId = $subjectId; - if(isset($data->displayName)) { + if (isset($data->displayName)) { $result->displayName = $data->displayName; } else { return null; } - if(isset($data->icon)) { + if (isset($data->icon)) { $result->icon = $data->icon; } else { return null; } - if(isset($data->description)) { + if (isset($data->description)) { $result->description = $data->description; } else { return null; } - if(isset($data->relatedTopics)) { + if (isset($data->relatedTopics)) { $result->relatedTopics = $data->relatedTopics; } else { $result->relatedTopics = array(); } - if(isset($data->files)) { + if (isset($data->files)) { $result->files = $data->files; } else { $result->files = array(); } - if(isset($data->article)) { - $result->article = $data->article; - } else { - return null; + $article = Util::readFileContent("$topicDataDirectory/article.html"); + if (!isset($article)) { + $article = "Kein Erklärtext vorhanden"; } + $article = str_replace('$TOPICPATH', $topicDataDirectory, $article); + + $result->article = $article; return $result; } diff --git a/webseite/classes/Util.php b/webseite/classes/Util.php index b9f3e07..0df7596 100644 --- a/webseite/classes/Util.php +++ b/webseite/classes/Util.php @@ -15,6 +15,24 @@ class Util return preg_replace("/[^a-zA-Z0-9_-]/", "", $string); } + static function readFileContent(string $filename): string|null + { + if (!file_exists($filename)) { + return null; + } + $file = fopen($filename, "r"); + if (!$file) { + return null; + } + $fileContent = fread($file, filesize($filename)); + if (!$fileContent) { + return null; + } + fclose($file); + + return $fileContent; + } + /** * Öffnet eine Datei und gibt JSON-Inhalte als Array zurück * @param string $filename Dateipfad @@ -22,10 +40,10 @@ class Util */ static function parseJsonFromFile(string $filename): mixed { - $file = fopen($filename, "r") or die("Unable to open file!"); - $fileContent = fread($file, filesize($filename)); - fclose($file); - - return json_decode($fileContent); + $content = self::readFileContent($filename); + if(!isset($content)) { + return null; + } + return json_decode($content); } } \ No newline at end of file diff --git a/webseite/config/subjects/deutsch/topics/topic4/properties.json b/webseite/config/subjects/deutsch/topics/topic4/properties.json index 426de26..75b608a 100644 --- a/webseite/config/subjects/deutsch/topics/topic4/properties.json +++ b/webseite/config/subjects/deutsch/topics/topic4/properties.json @@ -1,5 +1,5 @@ { - "displayName": "Thema 1", + "displayName": "Thema 4", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ diff --git a/webseite/config/subjects/deutsch/topics/topic5/properties.json b/webseite/config/subjects/deutsch/topics/topic5/properties.json index 426de26..5b0924d 100644 --- a/webseite/config/subjects/deutsch/topics/topic5/properties.json +++ b/webseite/config/subjects/deutsch/topics/topic5/properties.json @@ -1,5 +1,5 @@ { - "displayName": "Thema 1", + "displayName": "Thema 5", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ diff --git a/webseite/config/subjects/deutsch/topics/topic6/properties.json b/webseite/config/subjects/deutsch/topics/topic6/properties.json index 426de26..fade52f 100644 --- a/webseite/config/subjects/deutsch/topics/topic6/properties.json +++ b/webseite/config/subjects/deutsch/topics/topic6/properties.json @@ -1,5 +1,5 @@ { - "displayName": "Thema 1", + "displayName": "Thema 6", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ diff --git a/webseite/config/subjects/deutsch/topics/topic7/properties.json b/webseite/config/subjects/deutsch/topics/topic7/properties.json index 426de26..d6ad914 100644 --- a/webseite/config/subjects/deutsch/topics/topic7/properties.json +++ b/webseite/config/subjects/deutsch/topics/topic7/properties.json @@ -1,5 +1,5 @@ { - "displayName": "Thema 1", + "displayName": "Thema 7", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ diff --git a/webseite/config/subjects/deutsch/topics/topic8/properties.json b/webseite/config/subjects/deutsch/topics/topic8/properties.json index 426de26..22e4e58 100644 --- a/webseite/config/subjects/deutsch/topics/topic8/properties.json +++ b/webseite/config/subjects/deutsch/topics/topic8/properties.json @@ -1,5 +1,5 @@ { - "displayName": "Thema 1", + "displayName": "Thema 8", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ diff --git a/webseite/config/subjects/mathe/topics/topic1/article.html b/webseite/config/subjects/mathe/topics/topic1/article.html index e69de29..74f9470 100644 --- a/webseite/config/subjects/mathe/topics/topic1/article.html +++ b/webseite/config/subjects/mathe/topics/topic1/article.html @@ -0,0 +1,5 @@ +Das ist der Erklärtext +Ein Bild +
+When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are +$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ \ No newline at end of file diff --git a/webseite/config/subjects/mathe/topics/topic1/properties.json b/webseite/config/subjects/mathe/topics/topic1/properties.json index 4b30111..426de26 100644 --- a/webseite/config/subjects/mathe/topics/topic1/properties.json +++ b/webseite/config/subjects/mathe/topics/topic1/properties.json @@ -7,6 +7,5 @@ ], "files": [ "exercise1.pdf" - ], - "article": "Eine lange Erklärung\n![Alt Text](image.png)" + ] } \ No newline at end of file diff --git a/webseite/config/subjects/mathe/topics/topic2/properties.json b/webseite/config/subjects/mathe/topics/topic2/properties.json index 426de26..d776814 100644 --- a/webseite/config/subjects/mathe/topics/topic2/properties.json +++ b/webseite/config/subjects/mathe/topics/topic2/properties.json @@ -1,9 +1,9 @@ { - "displayName": "Thema 1", + "displayName": "Thema 2", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ - "topic2", "topic3" + "topic1", "topic3" ], "files": [ "exercise1.pdf" diff --git a/webseite/config/subjects/mathe/topics/topic3/properties.json b/webseite/config/subjects/mathe/topics/topic3/properties.json index 426de26..cbe7e38 100644 --- a/webseite/config/subjects/mathe/topics/topic3/properties.json +++ b/webseite/config/subjects/mathe/topics/topic3/properties.json @@ -1,9 +1,9 @@ { - "displayName": "Thema 1", + "displayName": "Thema 3", "icon": "fa-divide", "description": "Eine kurze Beschreibung des Themas", "relatedTopics": [ - "topic2", "topic3" + "topic1", "topic2" ], "files": [ "exercise1.pdf" diff --git a/webseite/homepage.php b/webseite/homepage.php index 9fb93ce..1f30b51 100644 --- a/webseite/homepage.php +++ b/webseite/homepage.php @@ -8,6 +8,7 @@ +