当前位置: 首页>>代码示例>>PHP>>正文


PHP IUserManager::countUsers方法代码示例

本文整理汇总了PHP中OCP\IUserManager::countUsers方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserManager::countUsers方法的具体用法?PHP IUserManager::countUsers怎么用?PHP IUserManager::countUsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCP\IUserManager的用法示例。


在下文中一共展示了IUserManager::countUsers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stats

 /**
  * Count all unique users visible for the current admin/subadmin.
  *
  * @NoAdminRequired
  *
  * @return DataResponse
  */
 public function stats()
 {
     $userCount = 0;
     if ($this->isAdmin) {
         $countByBackend = $this->userManager->countUsers();
         if (!empty($countByBackend)) {
             foreach ($countByBackend as $count) {
                 $userCount += $count;
             }
         }
     } else {
         $groupNames = $this->subAdminFactory->getSubAdminsOfGroups($this->userSession->getUser()->getUID());
         $uniqueUsers = [];
         foreach ($groupNames as $groupName) {
             $group = $this->groupManager->get($groupName);
             if (!is_null($group)) {
                 foreach ($group->getUsers() as $uid => $displayName) {
                     $uniqueUsers[$uid] = true;
                 }
             }
         }
         $userCount = count($uniqueUsers);
     }
     return new DataResponse(['totalUsers' => $userCount]);
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:32,代码来源:userscontroller.php

示例2: countUsers

 /**
  * Count all the users
  *
  * @return int
  */
 private function countUsers()
 {
     $allCount = $this->userManager->countUsers();
     $totalCount = 0;
     foreach ($allCount as $backend => $count) {
         $totalCount += $count;
     }
     return $totalCount;
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:14,代码来源:RepairUnmergedShares.php

示例3: countUsers

 private function countUsers()
 {
     return $this->userManager->countUsers();
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:4,代码来源:report.php

示例4: create

 /**
  * @NoAdminRequired
  *
  * @param string $username
  * @param string $password
  * @param array $groups
  * @param string $email
  * @return DataResponse
  */
 public function create($username, $password, array $groups = array(), $email = '')
 {
     $userCountArray = $this->userManager->countUsers();
     $userCount = 0;
     if (!empty($userCountArray)) {
         foreach ($userCountArray as $classname => $usercount) {
             $userCount += $usercount;
         }
     }
     if ($userCount > 3) {
         return new DataResponse(array('message' => (string) $this->l10n->t('User number exceeds the license!')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if ($email !== '' && !$this->mailer->validateMailAddress($email)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$this->isAdmin) {
         $userId = $this->userSession->getUser()->getUID();
         if (!empty($groups)) {
             foreach ($groups as $key => $group) {
                 if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) {
                     unset($groups[$key]);
                 }
             }
         }
         if (empty($groups)) {
             $groups = $this->subAdminFactory->getSubAdminsOfGroups($userId);
         }
     }
     if ($this->userManager->userExists($username)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
     }
     try {
         $user = $this->userManager->createUser($username, $password);
     } catch (\Exception $exception) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
     }
     if ($user instanceof User) {
         if ($groups !== null) {
             foreach ($groups as $groupName) {
                 $group = $this->groupManager->get($groupName);
                 if (empty($group)) {
                     $group = $this->groupManager->createGroup($groupName);
                 }
                 $group->addUser($user);
             }
         }
         /**
          * Send new user mail only if a mail is set
          */
         if ($email !== '') {
             $this->config->setUserValue($username, 'settings', 'email', $email);
             // data for the mail template
             $mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
             $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
             $mailContent = $mail->render();
             $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
             $plainTextMailContent = $mail->render();
             $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
             try {
                 $message = $this->mailer->createMessage();
                 $message->setTo([$email => $username]);
                 $message->setSubject($subject);
                 $message->setHtmlBody($mailContent);
                 $message->setPlainBody($plainTextMailContent);
                 $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
                 $this->mailer->send($message);
             } catch (\Exception $e) {
                 $this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
             }
         }
         // fetch users groups
         $userGroups = $this->groupManager->getUserGroupIds($user);
         return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
     }
     return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:85,代码来源:userscontroller.php


注:本文中的OCP\IUserManager::countUsers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。