Dynamische Daten in Seitentemplates eingefügt
This commit is contained in:
83
webseite/classes/SubjectData.php
Normal file
83
webseite/classes/SubjectData.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
require_once("Util.php");
|
||||
require_once("TopicData.php");
|
||||
|
||||
class SubjectData
|
||||
{
|
||||
public string $id;
|
||||
public string $displayName;
|
||||
public string $description;
|
||||
public string $color;
|
||||
public string $buttonText;
|
||||
public string $icon;
|
||||
public array $topics;
|
||||
|
||||
public static function getAll() : array
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$subjectDirectory = "config/subjects";
|
||||
$subjectNames = scandir($subjectDirectory);
|
||||
foreach ($subjectNames as $subjectName) {
|
||||
if ($subjectName == "." || $subjectName == "..") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subjectData = SubjectData::fromName($subjectName);
|
||||
if(!isset($subjectData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $subjectData;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function fromName($subjectName) : SubjectData|null
|
||||
{
|
||||
$result = new SubjectData();
|
||||
|
||||
$subjectName = Util::removeIllegalCharacters($subjectName);
|
||||
|
||||
$subjectDirectory = "config/subjects/$subjectName";
|
||||
$filename = "$subjectDirectory/properties.json";
|
||||
$data = Util::parseJsonFromFile($filename);
|
||||
|
||||
$result->id = $subjectName;
|
||||
|
||||
if(isset($data->displayName)) {
|
||||
$result->displayName = $data->displayName;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->description)) {
|
||||
$result->description = $data->description;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->color)) {
|
||||
$result->color = $data->color;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->buttonText)) {
|
||||
$result->buttonText = $data->buttonText;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($data->icon)) {
|
||||
$result->icon = $data->icon;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result->topics = TopicData::getAll($subjectName);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user