88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?php
|
|
require_once("Util.php");
|
|
|
|
class TopicData
|
|
{
|
|
public string $id;
|
|
public string $subjectId;
|
|
public string $displayName;
|
|
public string $icon;
|
|
public string $description;
|
|
public array $relatedTopics;
|
|
public array $files;
|
|
public string $article;
|
|
|
|
public static function getAll($subjectName) : array
|
|
{
|
|
$result = array();
|
|
|
|
$topicDirectory = "config/subjects/$subjectName/topics";
|
|
$topicNames = scandir($topicDirectory);
|
|
foreach ($topicNames as $topicName) {
|
|
if ($topicName == "." || $topicName == "..") {
|
|
continue;
|
|
}
|
|
$topicData = TopicData::fromName($subjectName, $topicName);
|
|
if(!isset($topicData)) {
|
|
continue;
|
|
}
|
|
|
|
$result[] = $topicData;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function fromName($subjectName, $topicName): TopicData|null
|
|
{
|
|
$result = new TopicData();
|
|
|
|
$subjectName = Util::removeIllegalCharacters($subjectName);
|
|
$topicName = Util::removeIllegalCharacters($topicName);
|
|
|
|
$topicDirectory = "config/subjects/$subjectName/topics";
|
|
$filename = "$topicDirectory/$topicName/properties.json";
|
|
$data = Util::parseJsonFromFile($filename);
|
|
|
|
$result->id = $topicName;
|
|
$result->subjectId = $subjectName;
|
|
|
|
if(isset($data->displayName)) {
|
|
$result->displayName = $data->displayName;
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
if(isset($data->icon)) {
|
|
$result->icon = $data->icon;
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
if(isset($data->description)) {
|
|
$result->description = $data->description;
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
if(isset($data->relatedTopics)) {
|
|
$result->relatedTopics = $data->relatedTopics;
|
|
} else {
|
|
$result->relatedTopics = array();
|
|
}
|
|
if(isset($data->files)) {
|
|
$result->files = $data->files;
|
|
} else {
|
|
$result->files = array();
|
|
}
|
|
|
|
if(isset($data->article)) {
|
|
$result->article = $data->article;
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
} |