Downloadlinks und Erklärungstexte funktional
This commit is contained in:
@@ -48,7 +48,7 @@ class SubjectData
|
||||
* Gibt alle Fächer als SubjectData Objekt zurück
|
||||
* @return array Alle Fächer als SubjectData
|
||||
*/
|
||||
public static function getAll() : array
|
||||
public static function getAll(): array
|
||||
{
|
||||
$result = array();
|
||||
|
||||
@@ -60,7 +60,7 @@ class SubjectData
|
||||
}
|
||||
|
||||
$subjectData = SubjectData::fromName($subjectName);
|
||||
if(!isset($subjectData)) {
|
||||
if (!isset($subjectData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class SubjectData
|
||||
* @param $subjectId string Die eindeutige ID des Faches
|
||||
* @return SubjectData|null Das Fach zu der ID oder null, wenn kein entsprechendes Fach gefunden wurde
|
||||
*/
|
||||
public static function fromName(string $subjectId) : SubjectData|null
|
||||
public static function fromName(string $subjectId): SubjectData|null
|
||||
{
|
||||
$result = new SubjectData();
|
||||
|
||||
@@ -84,34 +84,37 @@ class SubjectData
|
||||
$subjectDirectory = "config/subjects/$subjectId";
|
||||
$filename = "$subjectDirectory/properties.json";
|
||||
$data = Util::parseJsonFromFile($filename);
|
||||
if(!isset($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result->id = $subjectId;
|
||||
|
||||
if(isset($data->displayName)) {
|
||||
if (isset($data->displayName)) {
|
||||
$result->displayName = $data->displayName;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->description)) {
|
||||
if (isset($data->description)) {
|
||||
$result->description = $data->description;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->color)) {
|
||||
if (isset($data->color)) {
|
||||
$result->color = $data->color;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->buttonText)) {
|
||||
if (isset($data->buttonText)) {
|
||||
$result->buttonText = $data->buttonText;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->icon)) {
|
||||
if (isset($data->icon)) {
|
||||
$result->icon = $data->icon;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -39,7 +39,7 @@ class TopicData
|
||||
public array $files;
|
||||
|
||||
/**
|
||||
* @var string Der gesamte Erklärungstext zum Thema, enthält fertiges HTML
|
||||
* @var string Der gesamte Erklärungstext zum Thema, enthält fertiges HTML und LATEX Formelsyntax für MathJax https://docs.mathjax.org/en/latest/basic/mathematics.html
|
||||
*/
|
||||
public string $article;
|
||||
|
||||
@@ -48,7 +48,7 @@ class TopicData
|
||||
* @param $subjectId string Die ID des Faches
|
||||
* @return array Alle zugehörigen Themen als TopicData Objekte
|
||||
*/
|
||||
public static function getAll(string $subjectId) : array
|
||||
public static function getAll(string $subjectId): array
|
||||
{
|
||||
$result = array();
|
||||
|
||||
@@ -59,7 +59,7 @@ class TopicData
|
||||
continue;
|
||||
}
|
||||
$topicData = TopicData::fromName($subjectId, $topicName);
|
||||
if(!isset($topicData)) {
|
||||
if (!isset($topicData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -82,47 +82,52 @@ class TopicData
|
||||
$subjectId = Util::removeIllegalCharacters($subjectId);
|
||||
$topicId = Util::removeIllegalCharacters($topicId);
|
||||
|
||||
$topicDirectory = "config/subjects/$subjectId/topics";
|
||||
$filename = "$topicDirectory/$topicId/properties.json";
|
||||
$data = Util::parseJsonFromFile($filename);
|
||||
$topicsDirectory = "config/subjects/$subjectId/topics";
|
||||
$topicDataDirectory = "$topicsDirectory/$topicId";
|
||||
$data = Util::parseJsonFromFile("$topicDataDirectory/properties.json");
|
||||
if(!isset($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result->id = $topicId;
|
||||
$result->subjectId = $subjectId;
|
||||
|
||||
if(isset($data->displayName)) {
|
||||
if (isset($data->displayName)) {
|
||||
$result->displayName = $data->displayName;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->icon)) {
|
||||
if (isset($data->icon)) {
|
||||
$result->icon = $data->icon;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->description)) {
|
||||
if (isset($data->description)) {
|
||||
$result->description = $data->description;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->relatedTopics)) {
|
||||
if (isset($data->relatedTopics)) {
|
||||
$result->relatedTopics = $data->relatedTopics;
|
||||
} else {
|
||||
$result->relatedTopics = array();
|
||||
}
|
||||
if(isset($data->files)) {
|
||||
if (isset($data->files)) {
|
||||
$result->files = $data->files;
|
||||
} else {
|
||||
$result->files = array();
|
||||
}
|
||||
|
||||
if(isset($data->article)) {
|
||||
$result->article = $data->article;
|
||||
} else {
|
||||
return null;
|
||||
$article = Util::readFileContent("$topicDataDirectory/article.html");
|
||||
if (!isset($article)) {
|
||||
$article = "Kein Erklärtext vorhanden";
|
||||
}
|
||||
$article = str_replace('$TOPICPATH', $topicDataDirectory, $article);
|
||||
|
||||
$result->article = $article;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,24 @@ class Util
|
||||
return preg_replace("/[^a-zA-Z0-9_-]/", "", $string);
|
||||
}
|
||||
|
||||
static function readFileContent(string $filename): string|null
|
||||
{
|
||||
if (!file_exists($filename)) {
|
||||
return null;
|
||||
}
|
||||
$file = fopen($filename, "r");
|
||||
if (!$file) {
|
||||
return null;
|
||||
}
|
||||
$fileContent = fread($file, filesize($filename));
|
||||
if (!$fileContent) {
|
||||
return null;
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnet eine Datei und gibt JSON-Inhalte als Array zurück
|
||||
* @param string $filename Dateipfad
|
||||
@@ -22,10 +40,10 @@ class Util
|
||||
*/
|
||||
static function parseJsonFromFile(string $filename): mixed
|
||||
{
|
||||
$file = fopen($filename, "r") or die("Unable to open file!");
|
||||
$fileContent = fread($file, filesize($filename));
|
||||
fclose($file);
|
||||
|
||||
return json_decode($fileContent);
|
||||
$content = self::readFileContent($filename);
|
||||
if(!isset($content)) {
|
||||
return null;
|
||||
}
|
||||
return json_decode($content);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 4",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 5",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 6",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 7",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 8",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
Das ist der Erklärtext
|
||||
<img alt="Ein Bild" src="$TOPICPATH/image.png">
|
||||
<br>
|
||||
When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
|
||||
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
|
||||
@@ -7,6 +7,5 @@
|
||||
],
|
||||
"files": [
|
||||
"exercise1.pdf"
|
||||
],
|
||||
"article": "Eine lange Erklärung\n"
|
||||
]
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 2",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
"topic2", "topic3"
|
||||
"topic1", "topic3"
|
||||
],
|
||||
"files": [
|
||||
"exercise1.pdf"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"displayName": "Thema 1",
|
||||
"displayName": "Thema 3",
|
||||
"icon": "fa-divide",
|
||||
"description": "Eine kurze Beschreibung des Themas",
|
||||
"relatedTopics": [
|
||||
"topic2", "topic3"
|
||||
"topic1", "topic2"
|
||||
],
|
||||
"files": [
|
||||
"exercise1.pdf"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
<style>
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translateY(0px); }
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
require_once ("classes/SubjectData.php");
|
||||
require_once ("classes/TopicData.php");
|
||||
|
||||
if(!isset($_GET["subject"])) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
$subjectData = SubjectData::fromName($_GET["subject"]);
|
||||
if(!isset($subjectData)) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
$topics = $subjectData->topics;
|
||||
?>
|
||||
|
||||
@@ -15,6 +21,7 @@ $topics = $subjectData->topics;
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo($subjectData->displayName); ?> 5. Klasse - Modern</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
@@ -536,23 +543,23 @@ $topics = $subjectData->topics;
|
||||
|
||||
<?php
|
||||
|
||||
foreach ($topics as $topic) {
|
||||
foreach ($topics as $topicData) {
|
||||
?>
|
||||
|
||||
<div class="topic-card" onclick="window.location.href='topic.php?subject=<?php echo($topic->subjectId); ?>&topic=<?php echo($topic->id); ?>'" style="cursor: pointer;">
|
||||
<div class="topic-card" onclick="window.location.href='topic.php?subject=<?php echo($topicData->subjectId); ?>&topic=<?php echo($topicData->id); ?>'" style="cursor: pointer;">
|
||||
<div class="topic-header">
|
||||
<i class="fas <?php echo($topic->icon); ?> topic-icon"></i>
|
||||
<h3 class="topic-title"><?php echo($topic->displayName); ?></h3>
|
||||
<i class="fas <?php echo($topicData->icon); ?> topic-icon"></i>
|
||||
<h3 class="topic-title"><?php echo($topicData->displayName); ?></h3>
|
||||
</div>
|
||||
<div class="topic-content">
|
||||
<p class="topic-description">
|
||||
<?php echo($topic->description); ?>
|
||||
<?php echo($topicData->description); ?>
|
||||
</p>
|
||||
<div class="related-topics">
|
||||
<h4>Verwandte Themen:</h4>
|
||||
<ul>
|
||||
<?php
|
||||
foreach ($topic->relatedTopics as $relatedTopic) {
|
||||
foreach ($topicData->relatedTopics as $relatedTopic) {
|
||||
?>
|
||||
|
||||
<li><?php echo($relatedTopic); ?></li>
|
||||
@@ -567,28 +574,18 @@ $topics = $subjectData->topics;
|
||||
<h4>Übungen herunterladen:</h4>
|
||||
<div class="download-links">
|
||||
<?php
|
||||
foreach ($topic->files as $file) {
|
||||
foreach ($topicData->files as $fileName) {
|
||||
?>
|
||||
|
||||
|
||||
<a href="#" class="download-btn">
|
||||
<a href="<?php echo("config/subjects/$subjectData->id/topics/$topicData->id/$fileName")?>" target="_blank" class="download-btn">
|
||||
<i class="fas fa-file-pdf"></i>
|
||||
<?php echo($file); ?>
|
||||
<?php echo($fileName); ?>
|
||||
</a>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<a href="#" class="download-btn">
|
||||
<i class="fas fa-file-pdf"></i>
|
||||
Übung 1
|
||||
</a>
|
||||
<a href="#" class="download-btn">
|
||||
<i class="fas fa-file-pdf"></i>
|
||||
Übung 2
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="progress-bar" data-progress="100">
|
||||
|
||||
@@ -4,8 +4,20 @@
|
||||
require_once ("classes/SubjectData.php");
|
||||
require_once ("classes/TopicData.php");
|
||||
|
||||
if(!isset($_GET["subject"])) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
$subjectData = SubjectData::fromName($_GET["subject"]);
|
||||
if(!isset($subjectData)) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
if(!isset($_GET["topic"])) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
$topicData = TopicData::fromName($_GET["subject"], $_GET["topic"]);
|
||||
if(!isset($topicData)) {
|
||||
die("Ungültige Seite");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -16,6 +28,7 @@ $topicData = TopicData::fromName($_GET["subject"], $_GET["topic"]);
|
||||
<title><?php echo($topicData->displayName); ?> - <?php echo($subjectData->displayName); ?></title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
||||
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
@@ -330,7 +343,7 @@ $topicData = TopicData::fromName($_GET["subject"], $_GET["topic"]);
|
||||
<p class="content-text">
|
||||
<?php echo($topicData->description); ?>
|
||||
</p>
|
||||
<p class="content-text">
|
||||
<p class="content-text article-section">
|
||||
<?php echo($topicData->article); ?>
|
||||
</p>
|
||||
|
||||
@@ -338,12 +351,12 @@ $topicData = TopicData::fromName($_GET["subject"], $_GET["topic"]);
|
||||
<h3 style="margin-bottom: 1rem;">Übungen herunterladen:</h3>
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
||||
<?php
|
||||
foreach ($topicData->files as $file) {
|
||||
foreach ($topicData->files as $fileName) {
|
||||
?>
|
||||
|
||||
<a href="#" class="download-btn">
|
||||
<a href='<?php echo("config/subjects/$subjectData->id/topics/$topicData->id/$fileName")?>' target="_blank" class="download-btn">
|
||||
<i class="fas fa-file-pdf"></i>
|
||||
<?php echo($file); ?>
|
||||
<?php echo($fileName); ?>
|
||||
</a>
|
||||
|
||||
<?php
|
||||
@@ -363,7 +376,9 @@ $topicData = TopicData::fromName($_GET["subject"], $_GET["topic"]);
|
||||
foreach ($topicData->relatedTopics as $relatedTopic) {
|
||||
?>
|
||||
|
||||
<span class="topic-tag"><?php echo($relatedTopic); ?></span>
|
||||
<a href='<?php echo("topic.php?subject=$subjectData->id&topic=$relatedTopic") ?>'>
|
||||
<span class="topic-tag"><?php echo($relatedTopic); ?></span>
|
||||
</a>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user