Speichern und löschen von Themen und Fächern eingebaut

This commit is contained in:
Matthias Grief
2024-12-06 22:12:47 +01:00
committed by Eric Blommel
parent 7a146d8982
commit e09438c6ea
3 changed files with 292 additions and 1 deletions

View File

@@ -134,4 +134,135 @@ class TopicData
return $result;
}
/**
* Schreibt alle Daten in Dateien
* @return bool true, wenn erfolgreich, sonst false
*/
public function save(): bool
{
$data = array();
$data["displayName"] = $this->displayName;
$data["icon"] = $this->icon;
$data["description"] = $this->description;
$data["relatedTopics"] = $this->relatedTopics;
$data["files"] = $this->files;
$json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
if (!$json) {
return false;
}
if (!is_dir(Config::getSubjectDirectory($this->getSubjectId()))) {
return false;
}
$topicDirectory = Config::getTopicDirectory($this->getSubjectId(), $this->getId());
if (!is_dir($topicDirectory)) {
mkdir($topicDirectory, 0777, true);
}
if (!(Util::writeFileContent($topicDirectory . "properties.json", $json)
&& Util::writeFileContent($topicDirectory . "article.html", $json))
) {
return false;
}
return true;
}
/**
* Löscht das Thema inklusive aller zugehörigen Dateien
* @return bool true, wenn erfolgreich gelöscht, sonst false
*/
public function delete(): bool
{
if(!Util::delete(Config::getTopicDirectory($this->getSubjectId(), $this->getId()))) {
return false;
}
return true;
}
public function getId(): string
{
return $this->id;
}
public function setId(string $id): void
{
$this->id = $id;
}
public function getSubjectId(): string
{
return $this->subjectId;
}
public function setSubjectId(string $subjectId): void
{
$this->subjectId = $subjectId;
}
public function getDisplayName(): string
{
return $this->displayName;
}
public function setDisplayName(string $displayName): void
{
$this->displayName = $displayName;
}
public function getIcon(): string
{
return $this->icon;
}
public function setIcon(string $icon): void
{
$this->icon = $icon;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getRelatedTopics(): array
{
return $this->relatedTopics;
}
public function setRelatedTopics(array $relatedTopics): void
{
$this->relatedTopics = $relatedTopics;
}
public function getFiles(): array
{
return $this->files;
}
public function setFiles(array $files): void
{
$this->files = $files;
}
public function getArticle(): string
{
return $this->article;
}
public function setArticle(string $article): void
{
$this->article = $article;
}
}