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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user