本文整理汇总了PHP中OCP\IUserManager::search方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserManager::search方法的具体用法?PHP IUserManager::search怎么用?PHP IUserManager::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IUserManager
的用法示例。
在下文中一共展示了IUserManager::search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
* @param array $options - for future use. One should always have options!
* @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($pattern, $searchProperties, $options)
{
$users = array();
if ($pattern == '') {
// Fetch all contacts
$users = $this->userManager->search('');
} else {
foreach ($searchProperties as $property) {
$result = array();
if ($property === 'FN') {
$result = $this->userManager->searchDisplayName($pattern);
} else {
if ($property === 'id') {
$result = $this->userManager->search($pattern);
}
}
if (is_array($result)) {
$users = array_merge($users, $result);
}
}
}
$contacts = array();
foreach ($users as $user) {
$contact = array("id" => $user->getUID(), "FN" => $user->getDisplayname(), "EMAIL" => array(), "IMPP" => array("x-owncloud-handle:" . $user->getUID()));
$contacts[] = $contact;
}
return $contacts;
}
示例2: getUsers
/**
* returns a list of users
*
* @return OC_OCS_Result
*/
public function getUsers()
{
$search = !empty($_GET['search']) ? $_GET['search'] : '';
$limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
$offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
// Check if user is logged in
$user = $this->userSession->getUser();
if ($user === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
// Admin? Or SubAdmin?
if ($this->groupManager->isAdmin($user->getUID())) {
$users = $this->userManager->search($search, $limit, $offset);
} else {
if (\OC_SubAdmin::isSubAdmin($user->getUID())) {
$subAdminOfGroups = \OC_SubAdmin::getSubAdminsGroups($user->getUID());
if ($offset === null) {
$offset = 0;
}
$users = [];
foreach ($subAdminOfGroups as $group) {
$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search));
}
$users = array_slice($users, $offset, $limit);
} else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
}
$users = array_keys($users);
return new OC_OCS_Result(['users' => $users]);
}
示例3: testGetUsers
public function testGetUsers()
{
$result = $this->api->getUsers();
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$count = $result->getData();
$count = count($count['users']);
$this->assertEquals(count($this->userManager->search('', null, null)), $count);
$user = $this->generateUsers();
$_GET['search'] = $user->getUID();
$result = $this->api->getUsers();
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($user->getUID(), reset($data['users']));
// Add several users
$this->generateUsers(10);
$this->resetParams();
$_GET['limit'] = 2;
$result = $this->api->getUsers();
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$count = $result->getData();
$count = count($count['users']);
$this->assertEquals(2, $count);
$this->resetParams();
$_GET['limit'] = 1;
$_GET['offset'] = 1;
$result = $this->api->getUsers(array());
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals(array_keys($this->userManager->search('', 1, 1)), $data['users']);
}
示例4: run
/**
* @param $argument
* @throws \Exception
*/
protected function run($argument)
{
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
return;
}
$offset = $this->config->getAppValue('files_trashbin', 'cronjob_user_offset', 0);
$users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
if (!count($users)) {
// No users found, reset offset and retry
$offset = 0;
$users = $this->userManager->search('', self::USERS_PER_SESSION);
}
$offset += self::USERS_PER_SESSION;
$this->config->setAppValue('files_trashbin', 'cronjob_user_offset', $offset);
foreach ($users as $user) {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
continue;
}
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
Trashbin::deleteExpiredFiles($dirContent, $uid);
}
\OC_Util::tearDownFS();
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('debug')) {
$this->scanner->listen('\\OCA\\Music\\Utility\\Scanner', 'update', function ($path) use($output) {
$output->writeln("Scanning <info>{$path}</info>");
});
}
$inputPath = $input->getOption('path');
$path = false;
if ($inputPath) {
$path = '/' . trim($inputPath, '/');
list(, $user, ) = explode('/', $path, 3);
$users = array($user);
} else {
if ($input->getOption('all')) {
$users = $this->userManager->search('');
} else {
$users = $input->getArgument('user_id');
}
}
foreach ($users as $user) {
if (is_object($user)) {
$user = $user->getUID();
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);
$output->writeln("Start scan for <info>{$user}</info>");
$this->scanner->rescan($user, true, $path ? $path : $this->resolveUserFolder($user), $input->getOption('debug'), $output);
}
}
示例6: getUsers
/**
* returns a list of users
*
* @return OC_OCS_Result
*/
public function getUsers()
{
$search = !empty($_GET['search']) ? $_GET['search'] : '';
$limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
$offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
$users = $this->userManager->search($search, $limit, $offset);
$users = array_keys($users);
return new OC_OCS_Result(['users' => $users]);
}
示例7: getPrincipalsByPrefix
/**
* Returns a list of principals based on a prefix.
*
* This prefix will often contain something like 'principals'. You are only
* expected to return principals that are in this base path.
*
* You are expected to return at least a 'uri' for every user, you can
* return any additional properties if you wish so. Common properties are:
* {DAV:}displayname
*
* @param string $prefixPath
* @return string[]
*/
public function getPrincipalsByPrefix($prefixPath)
{
$principals = [];
if ($prefixPath === $this->principalPrefix) {
foreach ($this->userManager->search('') as $user) {
$principals[] = $this->userToPrincipal($user);
}
}
return $principals;
}
示例8: impersonate
/**
* become another user
* @UseSession
*/
public function impersonate($userid)
{
$users = $this->userManager->search($userid, 1, 0);
if (count($users) > 0) {
$user = array_shift($users);
if (strcasecmp($user->getUID(), $userid) === 0) {
$this->userSession->setUser($user);
}
}
return new JSONResponse();
}
示例9: initFS
/**
* A hack to access files and views. Better than before.
*
* @return bool
*/
protected function initFS()
{
//Need any valid user to mount FS
$results = $this->userManager->search('', 2, 0);
$anyUser = array_pop($results);
if (is_null($anyUser)) {
\OC::$server->getLogger()->error("Failed to setup file system", ['app' => 'files_antivirus']);
return false;
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($anyUser->getUID());
return true;
}
示例10: initFS
/**
* A hack to access files and views. Better than before.
*/
protected function initFS()
{
//Need any valid user to mount FS
$results = $this->userManager->search('', 2, 0);
$anyUser = array_pop($results);
if (is_null($anyUser)) {
\OCP\Util::writeLog('files_antivirus', "Failed to setup file system", \OCP\Util::ERROR);
return false;
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($anyUser->getUID());
return true;
}
示例11: getPrincipalsByPrefix
/**
* Returns a list of principals based on a prefix.
*
* This prefix will often contain something like 'principals'. You are only
* expected to return principals that are in this base path.
*
* You are expected to return at least a 'uri' for every user, you can
* return any additional properties if you wish so. Common properties are:
* {DAV:}displayname
*
* @param string $prefixPath
* @return string[]
*/
public function getPrincipalsByPrefix($prefixPath)
{
$principals = [];
if ($prefixPath === 'principals') {
foreach ($this->userManager->search('') as $user) {
$principal = ['uri' => 'principals/' . $user->getUID(), '{DAV:}displayname' => $user->getUID()];
$email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
if (!empty($email)) {
$principal['{http://sabredav.org/ns}email-address'] = $email;
}
$principals[] = $principal;
}
}
return $principals;
}
示例12: index
/**
* @NoAdminRequired
*
* @param int $offset
* @param int $limit
* @param string $gid GID to filter for
* @param string $pattern Pattern to search for in the username
* @param string $backend Backend to filter for (class-name)
* @return DataResponse
*
* TODO: Tidy up and write unit tests - code is mainly static method calls
*/
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '')
{
// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
if ($gid === '_everyone') {
$gid = '';
}
// Remove backends
if (!empty($backend)) {
$activeBackends = $this->userManager->getBackends();
$this->userManager->clearBackends();
foreach ($activeBackends as $singleActiveBackend) {
if ($backend === get_class($singleActiveBackend)) {
$this->userManager->registerBackend($singleActiveBackend);
break;
}
}
}
$users = [];
if ($this->isAdmin) {
if ($gid !== '') {
$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
} else {
$batch = $this->userManager->search($pattern, $limit, $offset);
}
foreach ($batch as $user) {
$users[] = $this->formatUserForIndex($user);
}
} else {
$subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
// New class returns IGroup[] so convert back
$gids = [];
foreach ($subAdminOfGroups as $group) {
$gids[] = $group->getGID();
}
$subAdminOfGroups = $gids;
// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
$gid = '';
}
// Batch all groups the user is subadmin of when a group is specified
$batch = [];
if ($gid === '') {
foreach ($subAdminOfGroups as $group) {
$groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
foreach ($groupUsers as $uid => $displayName) {
$batch[$uid] = $displayName;
}
}
} else {
$batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
}
$batch = $this->getUsersForUID($batch);
foreach ($batch as $user) {
// Only add the groups, this user is a subadmin of
$userGroups = array_values(array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOfGroups));
$users[] = $this->formatUserForIndex($user, $userGroups);
}
}
return new DataResponse($users);
}
示例13: run
protected function run($argument)
{
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
return;
}
$users = $this->userManager->search('');
$isFSready = false;
foreach ($users as $user) {
$uid = $user->getUID();
if (!$isFSready) {
if (!$this->setupFS($uid)) {
continue;
}
$isFSready = true;
}
Storage::expireOlderThanMaxForUser($uid);
}
\OC_Util::tearDownFS();
}
示例14: run
/**
* @param $argument
* @throws \Exception
*/
protected function run($argument)
{
$offset = $this->config->getAppValue('files', 'cronjob_scan_files', 0);
$users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
if (!count($users)) {
// No users found, reset offset and retry
$offset = 0;
$users = $this->userManager->search('', self::USERS_PER_SESSION);
}
$offset += self::USERS_PER_SESSION;
$this->config->setAppValue('files', 'cronjob_scan_files', $offset);
foreach ($users as $user) {
$this->runScanner($user);
}
}
示例15: createPublicity
/**
* @param int $id
* @param string $authorId
* @param int $timeStamp
*/
protected function createPublicity($id, $authorId, $timeStamp)
{
$users = $this->userManager->search('');
$event = $this->activityManager->generateEvent();
$event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id);
$dateTime = new \DateTime();
$dateTime->setTimestamp($timeStamp);
$notification = $this->notificationManager->createNotification();
$notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index'));
foreach ($users as $user) {
$event->setAffectedUser($user->getUID());
$this->activityManager->publish($event);
if ($authorId !== $user->getUID()) {
$notification->setUser($user->getUID());
$this->notificationManager->notify($notification);
}
}
}