diff options
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/Group/Backend/ABackend.php | 15 | ||||
-rw-r--r-- | lib/public/GroupInterface.php | 24 | ||||
-rw-r--r-- | lib/public/IGroup.php | 2 |
3 files changed, 39 insertions, 2 deletions
diff --git a/lib/public/Group/Backend/ABackend.php b/lib/public/Group/Backend/ABackend.php index 7f5cf732335..e76285dfda9 100644 --- a/lib/public/Group/Backend/ABackend.php +++ b/lib/public/Group/Backend/ABackend.php @@ -26,6 +26,10 @@ declare(strict_types=1); namespace OCP\Group\Backend; use OCP\GroupInterface; +use OCP\IUserManager; +use OCP\Server; +use OC\User\LazyUser; +use OC\User\DisplayNameCache; /** * @since 14.0.0 @@ -65,4 +69,15 @@ abstract class ABackend implements GroupInterface { return (bool)($actions & $implements); } + + public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array { + // Default implementation for compatibility reasons + $displayNameCache = Server::get(DisplayNameCache::class); + $userManager = Server::get(IUserManager::class); + $users = []; + foreach ($this->usersInGroup($gid, $search, $limit, $offset) as $userId) { + $users[$userId] = new LazyUser($userId, $displayNameCache, $userManager); + } + return $users; + } } diff --git a/lib/public/GroupInterface.php b/lib/public/GroupInterface.php index b7c07136126..07fd5cb50c4 100644 --- a/lib/public/GroupInterface.php +++ b/lib/public/GroupInterface.php @@ -106,13 +106,35 @@ interface GroupInterface { public function groupExists($gid); /** - * get a list of all users in a group + * @brief Get a list of user ids in a group matching the given search parameters. + * * @param string $gid * @param string $search * @param int $limit * @param int $offset * @return array an array of user ids * @since 4.5.0 + * @deprecated 25.0.0 Use searchInGroup instead, for performance reasons */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0); + + /** + * @brief Get a list of users matching the given search parameters. + * + * Implementations of this method should return lazy evaluated user objects and + * preload if possible the display name. + * + * <code> + * $users = $groupBackend->searchInGroup('admin', 'John', 10, 0); + * </code> + * + * @param string $gid The group id of the user we want to search + * @param string $search The part of the display name or user id of the users we + * want to search. This can be empty to get all the users. + * @param int $limit The limit of results + * @param int $offset The offset of the results + * @return IUser[] + * @since 25.0.0 + */ + public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array; } diff --git a/lib/public/IGroup.php b/lib/public/IGroup.php index ba13359c472..ec26cc55b69 100644 --- a/lib/public/IGroup.php +++ b/lib/public/IGroup.php @@ -99,7 +99,7 @@ interface IGroup { * @return \OCP\IUser[] * @since 8.0.0 */ - public function searchUsers($search, $limit = null, $offset = null); + public function searchUsers(string $search, ?int $limit = null, ?int $offset = null): array; /** * returns the number of users matching the search string |