Add functions for updating / deleting groups
This commit is contained in:
parent
cfa9cee60d
commit
f36938b8dd
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user