Speichern von Tasks eingebaut

This commit is contained in:
Matthias Grief
2024-12-13 22:58:00 +01:00
parent 83d74fc252
commit b38d4b038c
2 changed files with 45 additions and 27 deletions

View File

@@ -202,10 +202,22 @@ class TopicData
$result->article = str_replace('$TOPICPATH', Config::getTopicDirectory($subjectId, $topicId) . "images", $article);
$taskJson = Util::readFileContent(Config::getTopicDirectory($subjectId, $topicId) . "tasks.json");
$result->tasks = array();
if(isset($taskJson)) {
$result->tasks = json_decode($taskJson, true);
} else {
$result->tasks = array();
$arr = json_decode($taskJson, true);
foreach ($arr as $rawTask) {
$text = $rawTask["text"];
if(!isset($text)) {
continue;
}
$vars = $rawTask["vars"];
if (!isset($vars)) {
continue;
}
$result->tasks[] = new Task($text, $vars);
}
}
$result->cleanupRelatedTopics();
@@ -244,16 +256,22 @@ class TopicData
mkdir($topicDirectory, 0777, true);
}
$taskArray = array();
foreach ($this->tasks as $task) {
$element = array();
$element["text"] = $task->getText();
$element["vars"] = $task->getVariables();
$taskArray[] = $element;
}
$taskJson = json_encode($this->tasks, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$taskJson = json_encode($taskArray, 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 . "tasks.html", $taskJson)
&& Util::writeFileContent($topicDirectory . "tasks.json", $taskJson)
)
) {
return false;