From 45010810f72e38ae50fb64270044fa16beb09c0b Mon Sep 17 00:00:00 2001 From: Matthias Grief Date: Mon, 9 Dec 2024 12:37:47 +0100 Subject: [PATCH] =?UTF-8?q?Themen=20entfern-=20und=20hinzuf=C3=BCgbar=20ge?= =?UTF-8?q?macht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webseite/classes/SubjectData.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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;