Add functions for updating / deleting groups

This commit is contained in:
Joshua Ramon Enslin 2024-05-27 02:44:28 +02:00
parent cfa9cee60d
commit f36938b8dd
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -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. * Adds a group.
* *
@ -54,6 +80,10 @@ final class NodaGroup {
*/ */
public function insert(string $name, string $comment = ''):int { 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` $insertStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `group`
(`group_name`, `comment`) (`group_name`, `comment`)
VALUES 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. * Adds actors to a nodac group.
* *