Dokumentation für TopicData hinzugefügt
This commit is contained in:
@@ -3,26 +3,62 @@ require_once("Util.php");
|
||||
|
||||
class TopicData
|
||||
{
|
||||
/**
|
||||
* @var string Innerhalb des zugehörigen Faches eindeutige ID, darf nur A-Z, a-z, 0-9 sowie - und _ enthalten
|
||||
*/
|
||||
public string $id;
|
||||
|
||||
/**
|
||||
* @var string Die eindeutige ID des zugehörigen Faches
|
||||
*/
|
||||
public string $subjectId;
|
||||
|
||||
/**
|
||||
* @var string Der für User angezeigt Name des Themas, darf nur reinen Text enthalten
|
||||
*/
|
||||
public string $displayName;
|
||||
|
||||
/**
|
||||
* @var string Das Icon des Themas als Font-Awesome CSS-Klasse
|
||||
*/
|
||||
public string $icon;
|
||||
|
||||
/**
|
||||
* @var string Eine kurze Beschreibung des Themas, z.B. für die Fachübersichtsseite, darf HTML enthalten
|
||||
*/
|
||||
public string $description;
|
||||
|
||||
/**
|
||||
* @var array Die IDs aller verwandten Themen als String
|
||||
*/
|
||||
public array $relatedTopics;
|
||||
|
||||
/**
|
||||
* @var array Die Dateinamen (Datei.pdf) aller downloadbarer Dateien zu diesem Thema als String
|
||||
*/
|
||||
public array $files;
|
||||
|
||||
/**
|
||||
* @var string Der gesamte Erklärungstext zum Thema, enthält fertiges HTML
|
||||
*/
|
||||
public string $article;
|
||||
|
||||
public static function getAll($subjectName) : array
|
||||
/**
|
||||
* Gibt alle Themen zu einem gegebenen Fach zurück
|
||||
* @param $subjectId string Die ID des Faches
|
||||
* @return array Alle zugehörigen Themen als TopicData Objekte
|
||||
*/
|
||||
public static function getAll(string $subjectId) : array
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$topicDirectory = "config/subjects/$subjectName/topics";
|
||||
$topicDirectory = "config/subjects/$subjectId/topics";
|
||||
$topicNames = scandir($topicDirectory);
|
||||
foreach ($topicNames as $topicName) {
|
||||
if ($topicName == "." || $topicName == "..") {
|
||||
continue;
|
||||
}
|
||||
$topicData = TopicData::fromName($subjectName, $topicName);
|
||||
$topicData = TopicData::fromName($subjectId, $topicName);
|
||||
if(!isset($topicData)) {
|
||||
continue;
|
||||
}
|
||||
@@ -33,19 +69,25 @@ class TopicData
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function fromName($subjectName, $topicName): TopicData|null
|
||||
/**
|
||||
* Gibt Themendaten zu einem bestimmten Thema eines Faches zurück
|
||||
* @param $subjectId string Die ID des Faches
|
||||
* @param $topicId string Die ID des Themas
|
||||
* @return TopicData|null Die Themendaten oder null, wenn das Thema nicht existiert
|
||||
*/
|
||||
public static function fromName(string $subjectId, string $topicId): TopicData|null
|
||||
{
|
||||
$result = new TopicData();
|
||||
|
||||
$subjectName = Util::removeIllegalCharacters($subjectName);
|
||||
$topicName = Util::removeIllegalCharacters($topicName);
|
||||
$subjectId = Util::removeIllegalCharacters($subjectId);
|
||||
$topicId = Util::removeIllegalCharacters($topicId);
|
||||
|
||||
$topicDirectory = "config/subjects/$subjectName/topics";
|
||||
$filename = "$topicDirectory/$topicName/properties.json";
|
||||
$topicDirectory = "config/subjects/$subjectId/topics";
|
||||
$filename = "$topicDirectory/$topicId/properties.json";
|
||||
$data = Util::parseJsonFromFile($filename);
|
||||
|
||||
$result->id = $topicName;
|
||||
$result->subjectId = $subjectName;
|
||||
$result->id = $topicId;
|
||||
$result->subjectId = $subjectId;
|
||||
|
||||
if(isset($data->displayName)) {
|
||||
$result->displayName = $data->displayName;
|
||||
|
||||
Reference in New Issue
Block a user