From f36938b8dddff661341a4279439c67a22ee1472c Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 27 May 2024 02:44:28 +0200 Subject: [PATCH] Add functions for updating / deleting groups --- src/NodaGroup.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/NodaGroup.php b/src/NodaGroup.php index 33f493e..9feb6c0 100644 --- a/src/NodaGroup.php +++ b/src/NodaGroup.php @@ -44,6 +44,32 @@ final class NodaGroup { } + /** + * Returns basic description of a group. + * + * @param integer $group_id Group ID. + * + * @return array{name: string, comment: string} + */ + public function getDescription(int $group_id):array { + + $result = $this->_mysqli_noda->query_by_stmt("SELECT `group_name`, `comment` + FROM `group` + WHERE `group_id` = ?", "i", $group_id); + + if (!($cur = $result->fetch_row())) { + $result->close(); + throw new MDmainEntityNotExistentException("This group does not seem to exist"); + } + $result->close(); + + return [ + 'name' => $cur[0], + 'comment' => $cur[1], + ]; + + } + /** * Adds a group. * @@ -54,6 +80,10 @@ final class NodaGroup { */ public function insert(string $name, string $comment = ''):int { + if (empty($name)) { + throw new MDpageParameterMissingException("Name cannot be empty when adding groups."); + } + $insertStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `group` (`group_name`, `comment`) VALUES @@ -68,6 +98,40 @@ final class NodaGroup { } + /** + * Updates a group. + * + * @retun void + */ + public function update(int $group_id, string $name, string $comment = ''):void { + + if (empty($name)) { + throw new MDpageParameterMissingException("Name cannot be empty when adding groups."); + } + + $insertStmt = $this->_mysqli_noda->do_prepare("UPDATE `group` + SET `group_name` = ?, + `comment` = ? + WHERE `group_id` = ?"); + + $insertStmt->bind_param("ssi", $name, $comment, $group_id); + $insertStmt->execute(); + $insertStmt->close(); + + } + + /** + * Deletes a group. + * + * @retun void + */ + public function delete(int $group_id):void { + + $this->_mysqli_noda->update_query_by_stmt("DELETE FROM `group` + WHERE `group_id` = ?", "i", $group_id); + + } + /** * Adds actors to a nodac group. *