Dokumentation für SubjectData hinzugefügt

This commit is contained in:
Matthias Grief
2024-11-06 13:31:11 +01:00
parent 26266096ee
commit 0deda3ddb1

View File

@@ -2,16 +2,52 @@
require_once("Util.php");
require_once("TopicData.php");
/**
* Stellt alle relevanten Daten für ein einzeles Fach bereit
*
*/
class SubjectData
{
/**
* @var string Ein eindeutiger Bezeichner für das Fach, darf nur A-Z, a-Z, 0-9 sowie _ und - enthalten
*/
public string $id;
/**
* @var string Der für User angezeigte Name des Faches, nur reiner Text
*/
public string $displayName;
/**
* @var string Eine kurze Beschreibung des Faches, z.B. für den Text auf der Startseite, kann HTML enthalten
*/
public string $description;
/**
* @var string Themenfarbe des Faches, entweder als hexcode oder CSS-Klasse, noch nicht spezifiziert
*/
public string $color;
/**
* @var string Text des Knopfes der auf die Fachseite weiterführt, nur reiner Text
*/
public string $buttonText;
/**
* @var string Icon des Faches als Font-Awesome CSS-Klasse
*/
public string $icon;
/**
* @var array Alle Themen des Faches als TopicData Objekt
* @see TopicData
*/
public array $topics;
/**
* Gibt alle Fächer als SubjectData Objekt zurück
* @return array Alle Fächer als SubjectData
*/
public static function getAll() : array
{
$result = array();
@@ -34,17 +70,22 @@ class SubjectData
return $result;
}
public static function fromName($subjectName) : SubjectData|null
/**
* Lädt ein Fach über eine gegebene ID
* @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
{
$result = new SubjectData();
$subjectName = Util::removeIllegalCharacters($subjectName);
$subjectId = Util::removeIllegalCharacters($subjectId);
$subjectDirectory = "config/subjects/$subjectName";
$subjectDirectory = "config/subjects/$subjectId";
$filename = "$subjectDirectory/properties.json";
$data = Util::parseJsonFromFile($filename);
$result->id = $subjectName;
$result->id = $subjectId;
if(isset($data->displayName)) {
$result->displayName = $data->displayName;
@@ -76,7 +117,7 @@ class SubjectData
return null;
}
$result->topics = TopicData::getAll($subjectName);
$result->topics = TopicData::getAll($subjectId);
return $result;
}