From 83d74fc252390edc5a4833b13312afd735e32439 Mon Sep 17 00:00:00 2001 From: Matthias Grief Date: Fri, 13 Dec 2024 22:41:18 +0100 Subject: [PATCH] Aufgaben (Task) Schnittstelle eingabaut --- webseite/classes/Task.php | 41 +++++++++++++++++ webseite/classes/TopicData.php | 46 ++++++++++++++++++- .../mathe/topics/bruchrechnung/tasks.json | 24 ++++++++++ webseite/test.php | 1 + 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 webseite/classes/Task.php create mode 100644 webseite/config/subjects/mathe/topics/bruchrechnung/tasks.json create mode 100644 webseite/test.php diff --git a/webseite/classes/Task.php b/webseite/classes/Task.php new file mode 100644 index 0000000..0aecb01 --- /dev/null +++ b/webseite/classes/Task.php @@ -0,0 +1,41 @@ +text = $text; + $this->variables = $variables; + } + + /** + * @return string Aufgabentext + */ + public function getText(): string + { + return $this->text; + } + + /** + * @return array Assoziatives Array mit Variable → Richtiger Wert + */ + public function getVariables(): array + { + return $this->variables; + } +} \ No newline at end of file diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index 95d7177..f3d699f 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -48,6 +48,12 @@ class TopicData */ public string $article; + /** + * @var array Alle zugehörigen Formelaufgaben als Task + * @see Task + */ + private array $tasks; + /** * Erstellt ein neues Thema. Es wird noch nichts gespeichert! * @param string $id Innerhalb des zugehörigen Faches eindeutige ID, darf nur A-Z, a-z, 0-9 sowie - und _ enthalten @@ -91,6 +97,8 @@ class TopicData $result->article = $article; + $result->tasks = array(); + return $result; } @@ -193,6 +201,13 @@ class TopicData } $result->article = str_replace('$TOPICPATH', Config::getTopicDirectory($subjectId, $topicId) . "images", $article); + $taskJson = Util::readFileContent(Config::getTopicDirectory($subjectId, $topicId) . "tasks.json"); + if(isset($taskJson)) { + $result->tasks = json_decode($taskJson, true); + } else { + $result->tasks = array(); + } + $result->cleanupRelatedTopics(); $result->cleanupFiles(); @@ -229,8 +244,17 @@ class TopicData mkdir($topicDirectory, 0777, true); } + + $taskJson = json_encode($this->tasks, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + if (!$taskJson) { + return false; + } + var_dump($taskJson); + if (!(Util::writeFileContent($topicDirectory . "properties.json", $json) - && Util::writeFileContent($topicDirectory . "article.html", $json)) + && Util::writeFileContent($topicDirectory . "article.html", $json) + //&& Util::writeFileContent($topicDirectory . "tasks.html", $taskJson) + ) ) { return false; } @@ -383,6 +407,18 @@ class TopicData return true; } + public function addTask(Task $task): bool + { + $this->tasks[] = $task; + return true; + } + + public function removeTask(Task $task): bool + { + $this->tasks = array_diff($this->tasks, [$task]); + return true; + } + public function getId(): string { return $this->id; @@ -463,5 +499,13 @@ class TopicData $this->article = $article; } + public function getTasks(): array + { + return $this->tasks; + } + public function setTasks(array $tasks): void + { + $this->tasks = $tasks; + } } \ No newline at end of file diff --git a/webseite/config/subjects/mathe/topics/bruchrechnung/tasks.json b/webseite/config/subjects/mathe/topics/bruchrechnung/tasks.json new file mode 100644 index 0000000..18d3991 --- /dev/null +++ b/webseite/config/subjects/mathe/topics/bruchrechnung/tasks.json @@ -0,0 +1,24 @@ +[ + { + "text": "34 + 26 = ?", + "vars": { + "?": "60", + "x": "5", + "y": "2" + } + }, + { + "text": "a + b = c", + "vars": { + "a": "1", + "b": "2", + "c": "4" + } + }, + { + "text": "Wie schreibt man nähmlich richtig?", + "vars": { + "?": "nämlich" + } + } +] \ No newline at end of file diff --git a/webseite/test.php b/webseite/test.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/webseite/test.php @@ -0,0 +1 @@ +