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