summaryrefslogtreecommitdiffstats
path: root/inc/database.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2021-06-25 16:21:17 +0200
committerSimon Rettberg2021-06-25 16:21:17 +0200
commit32f0677dbca9e3347b931c1d0105eb37aa57e90d (patch)
treeddad4562e7ee8439a24e2462d44614692bb71d14 /inc/database.inc.php
parentUpdate .idea (diff)
downloadslx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.gz
slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.xz
slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.zip
[eventlog] Add event filtering and notification system
Diffstat (limited to 'inc/database.inc.php')
-rw-r--r--inc/database.inc.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/inc/database.inc.php b/inc/database.inc.php
index a55555b4..09006f3e 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -100,6 +100,41 @@ class Database
}
/**
+ * Fetch and group by first column. First column is key, value is a list of rows with remaining columns.
+ * [
+ * col1 => [
+ * [col2, col3],
+ * [col2, col3],
+ * ],
+ * ...,
+ * ]
+ *
+ * @return array|bool Associative array, first column is key, remaining columns are array values
+ */
+ public static function queryGroupList($query, $args = array(), $ignoreError = null)
+ {
+ $res = self::simpleQuery($query, $args, $ignoreError);
+ if ($res === false)
+ return false;
+ return $res->fetchAll(PDO::FETCH_GROUP);
+ }
+
+ /**
+ * Fetch and use first column as key of returned array.
+ * This is like queryGroup list, but it is assumed that the first column is unique, so
+ * the remaining columns won't be wrapped in another array.
+ *
+ * @return array|bool Associative array, first column is key, remaining columns are array values
+ */
+ public static function queryIndexedList($query, $args = array(), $ignoreError = null)
+ {
+ $res = self::simpleQuery($query, $args, $ignoreError);
+ if ($res === false)
+ return false;
+ return $res->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_UNIQUE);
+ }
+
+ /**
* Execute the given query and return the number of rows affected.
* Mostly useful for UPDATEs or INSERTs
*