summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-03-26 22:52:30 -0400
committerMalf Furious <m@lfurio.us>2017-03-26 22:52:30 -0400
commit1ae7eab4711353b2144d0da40ac33270bc79a081 (patch)
tree70587fefffcb21ed66e23c9e438a8abbc8dd3e64 /app
parent5e8f3fb2adb74a9eb5c841848cfaae6502c9e91a (diff)
downloadscrott-1ae7eab4711353b2144d0da40ac33270bc79a081.tar.gz
scrott-1ae7eab4711353b2144d0da40ac33270bc79a081.zip
Add function user::getGroups_ordByOwnByName()
Lookup all groups a user owns or is a member of.
Diffstat (limited to 'app')
-rw-r--r--app/class/user.class.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/class/user.class.php b/app/class/user.class.php
index 9892277..97309f8 100644
--- a/app/class/user.class.php
+++ b/app/class/user.class.php
@@ -250,6 +250,34 @@ class user extends agent
$this->emailVer = substr(self::getBlob(), 0, 8);
$this->emailConf = 0;
}
+
+ /*
+ * Get all groups this user owns or is a member of. This isn't necessarily
+ * all groups this user cas access permissions for. Results are sorted by
+ * ownership, then by name.
+ */
+ public function getGroups_ordByOwnByName() : array
+ {
+ $groups = array();
+
+ /* owner */
+ $query = "SELECT guid FROM objects WHERE objtype = 'group' AND owner = '" . database::esc($this->guid) . "' " .
+ "ORDER BY name";
+ $res = database::query($query);
+
+ foreach ($res as $g)
+ $groups[] = new group($g['guid']);
+
+ /* member */
+ $query = "SELECT o.guid FROM objects o JOIN members m ON o.guid = m.guid WHERE o.objtype = 'group' AND " .
+ "m.member = '" . database::esc($this->guid) . "' ORDER BY o.name";
+ $res = database::query($query);
+
+ foreach ($res as $g)
+ $groups[] = new group($g['guid']);
+
+ return $groups;
+ }
}
?>