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


PHP IGroupManager::getUserGroups方法代码示例

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


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

示例1: getGroups

 /**
  * @param string $search
  */
 protected function getGroups($search)
 {
     $this->result['groups'] = $this->result['exact']['groups'] = [];
     $groups = $this->groupManager->search($search, $this->limit, $this->offset);
     $groups = array_map(function (IGroup $group) {
         return $group->getGID();
     }, $groups);
     if (sizeof($groups) < $this->limit) {
         $this->reachedEndFor[] = 'groups';
     }
     $userGroups = [];
     if (!empty($groups) && $this->shareWithGroupOnly) {
         // Intersect all the groups that match with the groups this user is a member of
         $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
         $userGroups = array_map(function (IGroup $group) {
             return $group->getGID();
         }, $userGroups);
         $groups = array_intersect($groups, $userGroups);
     }
     foreach ($groups as $gid) {
         if (strtolower($gid) === $search) {
             $this->result['exact']['groups'][] = ['label' => $search, 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $search]];
         } else {
             $this->result['groups'][] = ['label' => $gid, 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $gid]];
         }
     }
     if ($this->offset === 0 && empty($this->result['exact']['groups'])) {
         // On page one we try if the search result has a direct hit on the
         // user id and if so, we add that to the exact match list
         $group = $this->groupManager->get($search);
         if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
             array_push($this->result['exact']['groups'], ['label' => $group->getGID(), 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => $group->getGID()]]);
         }
     }
 }
开发者ID:rosarion,项目名称:core,代码行数:38,代码来源:sharees.php

示例2: getGroupMembership

 /**
  * Returns the list of groups a principal is a member of
  *
  * @param string $principal
  * @param bool $needGroups
  * @return array
  * @throws Exception
  */
 public function getGroupMembership($principal, $needGroups = false)
 {
     list($prefix, $name) = URLUtil::splitPath($principal);
     if ($prefix === $this->principalPrefix) {
         $user = $this->userManager->get($name);
         if (!$user) {
             throw new Exception('Principal not found');
         }
         if ($this->hasGroups || $needGroups) {
             $groups = $this->groupManager->getUserGroups($user);
             $groups = array_map(function ($group) {
                 /** @var IGroup $group */
                 return 'principals/groups/' . $group->getGID();
             }, $groups);
             return $groups;
         }
     }
     return [];
 }
开发者ID:stweil,项目名称:owncloud-core,代码行数:27,代码来源:principal.php

示例3: getGroupMembership

 /**
  * Returns the list of groups a principal is a member of
  *
  * @param string $principal
  * @return array
  * @throws Exception
  */
 public function getGroupMembership($principal)
 {
     list($prefix, $name) = URLUtil::splitPath($principal);
     if ($prefix === 'principals/users') {
         $user = $this->userManager->get($name);
         if (!$user) {
             throw new Exception('Principal not found');
         }
         $groups = $this->groupManager->getUserGroups($user);
         $groups = array_map(function ($group) {
             /** @var IGroup $group */
             return 'principals/groups/' . $group->getGID();
         }, $groups);
         $groups[] = 'principals/users/' . $name . '/calendar-proxy-read';
         $groups[] = 'principals/users/' . $name . '/calendar-proxy-write';
         return $groups;
     }
     return [];
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:26,代码来源:principal.php

示例4: getSharedWith

 /**
  * @inheritdoc
  */
 public function getSharedWith($userId, $shareType, $node, $limit, $offset)
 {
     /** @var Share[] $shares */
     $shares = [];
     if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
         //Get shares directly with this user
         $qb = $this->dbConn->getQueryBuilder();
         $qb->select('*')->from('share');
         // Order by id
         $qb->orderBy('id');
         // Set limit and offset
         if ($limit !== -1) {
             $qb->setMaxResults($limit);
         }
         $qb->setFirstResult($offset);
         $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
         $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
         // Filter by node if provided
         if ($node !== null) {
             $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
         }
         $cursor = $qb->execute();
         while ($data = $cursor->fetch()) {
             $shares[] = $this->createShare($data);
         }
         $cursor->closeCursor();
     } else {
         if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
             $user = $this->userManager->get($userId);
             $allGroups = $this->groupManager->getUserGroups($user);
             /** @var Share[] $shares2 */
             $shares2 = [];
             $start = 0;
             while (true) {
                 $groups = array_slice($allGroups, $start, 100);
                 $start += 100;
                 if ($groups === []) {
                     break;
                 }
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->select('*')->from('share')->orderBy('id')->setFirstResult(0);
                 if ($limit !== -1) {
                     $qb->setMaxResults($limit - count($shares));
                 }
                 // Filter by node if provided
                 if ($node !== null) {
                     $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
                 }
                 $groups = array_map(function (IGroup $group) {
                     return $group->getGID();
                 }, $groups);
                 $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)));
                 $qb->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY)));
                 $cursor = $qb->execute();
                 while ($data = $cursor->fetch()) {
                     if ($offset > 0) {
                         $offset--;
                         continue;
                     }
                     $shares2[] = $this->createShare($data);
                 }
                 $cursor->closeCursor();
             }
             /*
              * Resolve all group shares to user specific shares
              * TODO: Optmize this!
              */
             foreach ($shares2 as $share) {
                 $shares[] = $this->resolveGroupShare($share, $userId);
             }
         } else {
             throw new BackendError('Invalid backend');
         }
     }
     return $shares;
 }
开发者ID:gvde,项目名称:core,代码行数:79,代码来源:defaultshareprovider.php


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