From 438fd9cb25cc740d8ffc2c5f9997992250c8cab6 Mon Sep 17 00:00:00 2001 From: Matthias Grief Date: Mon, 23 Dec 2024 16:09:27 +0100 Subject: [PATCH] =?UTF-8?q?Funktionalit=C3=A4t=20Facheditor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webseite/classes/TopicData.php | 7 ++ .../config/subjects/mathe/properties.json | 4 +- .../config/subjects/physik/properties.json | 6 + webseite/subjectEditor.php | 116 +++++++++++++++--- 4 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 webseite/config/subjects/physik/properties.json diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index c157c0d..6c315ff 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -127,7 +127,14 @@ class TopicData { $result = array(); + if(!is_dir(Config::getTopicsDirectory($subjectId))) { + return array(); + } + $topicNames = scandir(Config::getTopicsDirectory($subjectId)); + if(!$topicNames) { + return array(); + } usort($topicNames, function ($a, $b) { return strcmp($a, $b); diff --git a/webseite/config/subjects/mathe/properties.json b/webseite/config/subjects/mathe/properties.json index 5b6cb74..f49e3fe 100644 --- a/webseite/config/subjects/mathe/properties.json +++ b/webseite/config/subjects/mathe/properties.json @@ -1,6 +1,6 @@ { "displayName": "Mathe", - "description": "Mathe ist blau", - "color": "#3b82f6", + "description": "Mathe ist rot", + "color": "#626cd0", "icon": "fa-square-root-alt" } \ No newline at end of file diff --git a/webseite/config/subjects/physik/properties.json b/webseite/config/subjects/physik/properties.json new file mode 100644 index 0000000..8f3b5c2 --- /dev/null +++ b/webseite/config/subjects/physik/properties.json @@ -0,0 +1,6 @@ +{ + "displayName": "Physik", + "description": "Noch ein Fach", + "color": "#363cfc", + "icon": "fa-square-root-alt" +} \ No newline at end of file diff --git a/webseite/subjectEditor.php b/webseite/subjectEditor.php index 45d6296..448da70 100644 --- a/webseite/subjectEditor.php +++ b/webseite/subjectEditor.php @@ -6,8 +6,70 @@ require_once("classes/TopicData.php"); $allSubjects = SubjectData::getAll(); $editingSubject = null; +$defaultValues = array(); +$defaultValues['displayName'] = ""; +$defaultValues['id'] = ""; +$defaultValues['description'] = ""; +$defaultValues['color'] = "#3b82f6"; +$defaultValues['icon'] = ""; + +$errors = array(); + if (isset($_GET['subjectId'])) { $editingSubject = $allSubjects[$_GET['subjectId']]; + + $defaultValues['displayName'] = $editingSubject->getDisplayName(); + $defaultValues['id'] = $editingSubject->getId(); + $defaultValues['description'] = $editingSubject->getDescription(); + $defaultValues['color'] = $editingSubject->getColor(); + $defaultValues['icon'] = $editingSubject->getIcon(); +} + +if($_SERVER['REQUEST_METHOD'] == 'POST') { + foreach ($defaultValues as $key => $value) { + $defaultValues[$key] = $_POST[$key]; + } + + if(!isset($_POST['displayName']) || trim($_POST['displayName']) == "") { + $errors["displayName"] = "Bitte geben Sie einen Namen an."; + } + + if(!isset($_POST['id']) || trim($_POST['id']) == "") { + $errors["id"] = "Bitte geben Sie eine ID an."; + } + + if(!isset($_POST['description']) || trim($_POST['description']) == "") { + $errors["description"] = "Bitte geben Sie eine Beschreibung an."; + } + + if(!isset($_POST['color']) || trim($_POST['color']) == "") { + $errors["color"] = "Bitte geben Sie eine Farbe an."; + } + + if(!isset($_POST['icon']) || trim($_POST['icon']) == "") { + $errors["icon"] = "Bitte geben Sie ein Icon an."; + } + + if(empty($errors)) { + $newSubject = false; + if(isset($allSubjects[$_POST['id']])) { + $newSubject = $allSubjects[$_POST['id']]; + $newSubject->setDisplayName($_POST['displayName']); + $newSubject->setDescription($_POST['description']); + $newSubject->setColor($_POST['color']); + $newSubject->setIcon($_POST['icon']); + } else { + $newSubject = SubjectData::createNew($_POST['id'], $_POST['displayName'], $_POST['description'], $_POST['color'], $_POST['icon'], array()); + } + + if(!$newSubject) { + $errors["error"] = "Fehler beim Speichern des Faches."; + } else { + $newSubject->save(); + header("Location: " . "subject.php?subject=" . $newSubject->getId()); + } + } + } ?> @@ -29,7 +91,7 @@ if (isset($_GET['subjectId'])) { -
+
@@ -38,11 +100,17 @@ if (isset($_GET['subjectId'])) { required class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400" placeholder="z.B. Mathematik" - value="getDisplayName(); - } - ?>"> + value=""> +
+ +
+ +
@@ -51,26 +119,23 @@ if (isset($_GET['subjectId'])) { required class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400" rows="4" - placeholder="Kurze Beschreibung des Fachs">getDescription(); - } - ?> + placeholder="Kurze Beschreibung des Fachs">
"> + value="">
+
+ + +
+ + + + $error

"; + } + ?> +
+