Funktionalität für interaktive Formeln hinzugefügt

This commit is contained in:
Matthias Grief
2025-01-03 18:23:05 +01:00
parent 368480cf0c
commit 46cbe59447
2 changed files with 73 additions and 0 deletions

View File

@@ -475,6 +475,11 @@ class TopicData
return true;
}
public function removeAllTasks()
{
$this->tasks = array();
}
public function getId(): string
{
return $this->id;

View File

@@ -3,6 +3,7 @@
require_once("classes/User.php");
require_once("classes/SubjectData.php");
require_once("classes/TopicData.php");
require_once("classes/Task.php");
session_start();
@@ -22,6 +23,7 @@ $defaultValues['description'] = "";
$defaultValues['icon'] = "";
$defaultValues['relatedTopics'] = "";
$defaultValues['existing_files'] = "";
$defaultValues['formulas'] = "";
$defaultValues['article'] = "";
$errors = array();
@@ -37,6 +39,17 @@ if (isset($_GET['subject']) && isset($_GET['topic'])) {
$defaultValues['icon'] = $editingTopic->getIcon();
$defaultValues['relatedTopics'] = implode(", ", $editingTopic->getRelatedTopics());
$defaultValues['existing_files'] = implode(", ", $editingTopic->getFiles());
$tasks = array();
foreach($editingTopic->getTasks() as $task) {
$variables = array();
foreach($task->getVariables() as $name => $variable) {
$variables[] = $name . "::" . $variable;
}
$tasks[] = $task->getText() . ";;" . implode(";;", $variables);
}
$defaultValues['formulas'] = implode(";;;;", $tasks);
$defaultValues['article'] = $editingTopic->getFinishedArticle();
}
} else if(isset($_GET['subject'])) {
@@ -68,6 +81,18 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors["icon"] = "Bitte geben Sie ein Icon an.";
}
if(!isset($_POST['relatedTopics'])) {
$errors["relatedTopics"] = "Feld relatedTopics nicht mitgesendet!";
}
if(!isset($_POST['existing_files'])) {
$errors["existing_files"] = "Feld existing_files nicht mitgesendet!";
}
if(!isset($_POST['formulas'])) {
$errors["formulas"] = "Feld formulas nicht mitgesendet!";
}
if(!isset($_POST['article']) || trim($_POST['article']) == "") {
$errors["article"] = "Bitte geben Sie einen Erklärtext an.";
}
@@ -97,6 +122,38 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
$existingFiles[] = trim($existingTopic);
}
$formulas = array();
foreach (explode(";;;;", $_POST['formulas']) as $formulaString) {
$text = false;
$answers = array();
foreach (explode(";;", $formulaString) as $formulaEntry) {
if(!$text) {
$text = trim($formulaEntry);
continue;
}
$answer = explode("::", $formulaEntry);
if(count($answer) != 2) {
$errors['formulas'] = "Jede Formel muss einen Text und mindestens eine Antwortmöglichkeit haben!";
break;
}
$answers[trim($answer[0])] = trim($answer[1]);
}
if(!$text) {
$errors['formulas'] = "Jede Formel muss einen Text haben!";
break;
}
if(count($answers) == 0) {
$errors['formulas'] = "Jede Formel muss mindestens eine Antwortmöglichkeit haben!";
break;
}
$formulas[] = new Task($text, $answers);
}
$article = htmlentities($_POST['article'], ENT_HTML401, 'UTF-8');
$dom = new DOMDocument();
$dom->encoding = 'UTF-8';
@@ -147,6 +204,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
}
}
$newTopic->setArticle($article);
$newTopic->removeAllTasks();
} else {
$newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $relatedTopics, $article);
}
@@ -162,6 +220,10 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
$newTopic->uploadImage($name, $image);
}
foreach ($formulas as $formula) {
$newTopic->addTask($formula);
}
if($_POST['submit'] == "Thema löschen") {
$newTopic->delete();
header("Location: " . "subject.php?subject=" . $_POST['subjectId']);
@@ -275,6 +337,12 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
Übungsblätter hinzufügen</label>
<input type="file" name="new_files[]" id="new_files" multiple>
</div>
<div>
<label for="formulas"
class="block text-sm font-medium text-gray-700">Formeln - Format: aufgabentext1;;a::2,5;;b::3;;;;aufgabentext2;;a::1</label>
<input class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm" type="text" name="formulas" id="formulas" value="<?php echo $defaultValues['formulas']; ?>">
</div>
</div>
<!-- Right column - Editor -->