diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-16 12:32:56 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-24 17:52:15 +0200 |
commit | 10c135ca3414544a92febbc45b39d358c8383757 (patch) | |
tree | 17137dc89af559ed083dd36824ba78803a8e58d1 /lib/private/User | |
parent | 6689a3e37b5bc71a66462c547072ad7555958c05 (diff) | |
download | nextcloud-server-10c135ca3414544a92febbc45b39d358c8383757.tar.gz nextcloud-server-10c135ca3414544a92febbc45b39d358c8383757.zip |
Added disabled count per groups
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib/private/User')
-rw-r--r-- | lib/private/User/Manager.php | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index b5054bd1851..17712321933 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -420,12 +420,12 @@ class Manager extends PublicEmitter implements IUserManager { } /** - * returns how many users have logged in once + * returns how many users are disabled * * @return int * @since 12.0.0 */ - public function countDisabledUsers() { + public function countDisabledUsers(): int { $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $queryBuilder->select($queryBuilder->createFunction('COUNT(*)')) ->from('preferences') @@ -433,12 +433,48 @@ class Manager extends PublicEmitter implements IUserManager { ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)); - $query = $queryBuilder->execute(); + + $result = $queryBuilder->execute(); + $count = $result->fetchColumn(); + $result->closeCursor(); + + if ($count !== false) { + $count = (int)$count; + } else { + $count = 0; + } - $result = (int)$query->fetchColumn(); - $query->closeCursor(); + return $count; + } - return $result; + /** + * returns how many users are disabled in the requested groups + * + * @param array $groups groupids to search + * @return int + * @since 14.0.0 + */ + public function countDisabledUsersOfGroups(array $groups): int { + $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)')) + ->from('preferences', 'p') + ->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid') + ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) + ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) + ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY))); + + $result = $queryBuilder->execute(); + $count = $result->fetchColumn(); + $result->closeCursor(); + + if ($count !== false) { + $count = (int)$count; + } else { + $count = 0; + } + + return $count; } /** |