diff --git a/webseite/classes/SubjectData.php b/webseite/classes/SubjectData.php index 487326c..49fa157 100644 --- a/webseite/classes/SubjectData.php +++ b/webseite/classes/SubjectData.php @@ -167,6 +167,36 @@ class SubjectData return true; } + /** + * Fügt ein neues Thema zum Fach hinzu + * @param TopicData $topic Das neue Thema + * @return bool true, wenn erfolgreich, sonst false + */ + public function addTopic(TopicData $topic): bool + { + if(isset($this->topics[$topic->getId()])) { + return false; + } + + $this->topics[] = $topic; + return true; + } + + /** + * Entfernt ein Thema vom Fach + * @param TopicData $topic Das zu entfernende Thema + * @return bool true, wenn erfolgreich, sonst false + */ + public function removeTopic(TopicData $topic): bool + { + if(!isset($this->topics[$topic->getId()])) { + return false; + } + + $this->topics = array_diff($this->topics, [$topic]); + return true; + } + public function getId(): string { return $this->id;