Aufgaben (Task) Schnittstelle eingabaut

This commit is contained in:
Matthias Grief
2024-12-13 22:41:18 +01:00
parent e8a2c641fd
commit 83d74fc252
4 changed files with 111 additions and 1 deletions

41
webseite/classes/Task.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
class Task
{
/**
* @var string Aufgabentext kann z.B. auch LaTeX-Notation enthalten
*/
private string $text;
/**
* @var array Alle verwendeten Variablen mit key als Variable und value als richtigen Wert
*/
private array $variables;
/**
* Erstellt eine neue Aufgabe
* @param string $text Aufgabentext, kann z.B. auch LaTeX-Notation enthalten
* @param array $variables Assoziatives Array mit Variable → Richtiger Wert
*/
public function __construct(string $text, array $variables)
{
$this->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;
}
}

View File

@@ -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;
}
}

View File

@@ -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"
}
}
]

1
webseite/test.php Normal file
View File

@@ -0,0 +1 @@
<?php