Add new class NodaGroup

This commit is contained in:
Joshua Ramon Enslin 2023-12-07 23:30:24 +01:00
parent 50cb33720b
commit 27e259072c
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

59
src/NodaGroup.php Normal file
View File

@ -0,0 +1,59 @@
<?PHP
/**
* Manages vocabulary groups.
*
* @file
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Manages vocabulary groups.
*/
final class NodaGroup {
private MDMysqli $_mysqli_noda;
/**
* Lists all active groups.
*
* @param integer $limit Limit.
* @param integer $offset Offset.
*
* @return array<array{id: int, name: string}>
*/
public function list(int $limit = 50, int $offset = 0):array {
$output = [];
$result = $this->_mysqli_noda->query_by_stmt("SELECT `group_id`, `group_name`
FROM `group`
ORDER BY `group_id` DESC
LIMIT ?
OFFSET ?", "ii", $limit, $offset);
while ($cur = $result->fetch_row()) {
$output[] = [
'id' => (int)$cur[0],
'name' => $cur[1],
];
}
$result->close();
return $output;
}
/**
* Constructor.
*
* @param MDMysqli $mysqli_noda DB connection.
*
* @return void
*/
public function __construct(MDMysqli $mysqli_noda) {
$this->_mysqli_noda = $mysqli_noda;
}
}