From 51d8b1230163d629aac55456b017ab58f87e91ac Mon Sep 17 00:00:00 2001 From: pebosi Date: Thu, 11 Apr 2013 09:05:02 +0200 Subject: [PATCH 1/2] add api function to get users with given access to only the given site --- plugins/UsersManager/API.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 7937c90ec47..fb8920ea982 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -238,6 +238,30 @@ public function getUsersWithSiteAccess($idSite, $access) return $this->getUsers($logins); } + /** + * Returns users that have given access to given site, + * but now access to other sites. + */ + public function getUsersWithDistinctSiteAccess($idSite, $access) + { + Piwik::checkUserIsSuperUser(); + + $db = Zend_Registry::get('db'); + $users = $db->fetchAll("SELECT login + FROM " . Piwik_Common::prefixTable("access") + . " as access1 WHERE idsite = ? AND access = ? AND (SELECT COUNT(login) FROM " . Piwik_Common::prefixTable("access") + . " as access2 WHERE access2.login = access1.login GROUP BY access2.login) = 1 ", array($idSite, $access)); + $logins = array(); + foreach ($users as $user) { + $logins[] = $user['login']; + } + if (empty($logins)) { + return array(); + } + $logins = implode(',', $logins); + return $this->getUsers($logins); + } + /** * For each website ID, returns the access level of the given $userLogin. * If the user doesn't have any access to a website ('noaccess'), From cd3d35ac82f577933585b1b7ed89d9e05e1afcae Mon Sep 17 00:00:00 2001 From: pebosi Date: Thu, 11 Apr 2013 09:10:14 +0200 Subject: [PATCH 2/2] fix typo in comment --- plugins/UsersManager/API.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index fb8920ea982..ae5ef7dc282 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -240,7 +240,7 @@ public function getUsersWithSiteAccess($idSite, $access) /** * Returns users that have given access to given site, - * but now access to other sites. + * but no access to other sites. */ public function getUsersWithDistinctSiteAccess($idSite, $access) {