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

@@ -119,4 +119,106 @@ class SubjectData
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["description"] = $this->description;
$data["color"] = $this->color;
$data["icon"] = $this->icon;
$json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
if (!$json) {
return false;
}
$subjectDirectory = Config::getSubjectDirectory($this->getId());
if (!is_dir($subjectDirectory)) {
mkdir($subjectDirectory, 0777, true);
}
if (!Util::writeFileContent($subjectDirectory . "properties.json", $json)) {
return false;
}
return true;
}
/**
* Löscht das Fach inklusive aller zugehörigen Themen
* @return bool true, wenn erfolgreich, sonst false
*/
public function delete(): bool
{
if(!Util::delete(Config::getSubjectDirectory($this->getId()))) {
return false;
}
return true;
}
public function getId(): string
{
return $this->id;
}
public function setId(string $id): void
{
$this->id = $id;
}
public function getDisplayName(): string
{
return $this->displayName;
}
public function setDisplayName(string $displayName): void
{
$this->displayName = $displayName;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getColor(): string
{
return $this->color;
}
public function setColor(string $color): void
{
$this->color = $color;
}
public function getIcon(): string
{
return $this->icon;
}
public function setIcon(string $icon): void
{
$this->icon = $icon;
}
public function getTopics(): array
{
return $this->topics;
}
public function setTopics(array $topics): void
{
$this->topics = $topics;
}
}