From aa56f3010c73578ec54318141a1d2c3d4a27b13d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 20 Oct 2014 13:42:33 +0200 Subject: [PATCH] lib: Add DbUserGroupBackend --- .../Backend/DbUserGroupBackend.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 library/Icinga/Authentication/Backend/DbUserGroupBackend.php diff --git a/library/Icinga/Authentication/Backend/DbUserGroupBackend.php b/library/Icinga/Authentication/Backend/DbUserGroupBackend.php new file mode 100644 index 000000000..15a77d77d --- /dev/null +++ b/library/Icinga/Authentication/Backend/DbUserGroupBackend.php @@ -0,0 +1,63 @@ +conn = $conn; + } + + /** + * (non-PHPDoc) + * @see UserGroupBackend::getMemberships() For the method documentation. + */ + public function getMemberships(User $user) + { + $groups = array(); + $groupsStmt = $this->conn->getDbAdapter() + ->select() + ->from($this->conn->getTablePrefix() . 'group', array('name', 'parent')) + ->query(); + foreach ($groupsStmt as $group) { + $groups[$group->name] = $group->parent; + } + $memberships = array(); + $membershipsStmt = $this->conn->getDbAdapter() + ->select() + ->from($this->conn->getTablePrefix() . 'group_membership', array('group_name')) + ->where('username = ?', $user->getUsername()) + ->query(); + foreach ($membershipsStmt as $membership) { + $memberships[] = $membership->group_name; + $parent = $groups[$membership->group_name]; + while (isset($parent)) { + $memberships[] = $parent; + $parent = $groups[$parent]; + } + } + return $memberships; + } +}