本文整理汇总了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()]]);
}
}
}
示例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 [];
}
示例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 [];
}
示例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;
}