本文整理汇总了PHP中Claroline\CoreBundle\Entity\User::getGroups方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getGroups方法的具体用法?PHP User::getGroups怎么用?PHP User::getGroups使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Entity\User
的用法示例。
在下文中一共展示了User::getGroups方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visibleToUser
/**
* @param Portfolio $portfolio
* @param User $user
*
* @return bool
*/
public function visibleToUser(Portfolio $portfolio, User $user)
{
$visibility = $portfolio->getVisibility();
$isVisible = false;
if ($portfolio->getUser() === $user) {
$isVisible = true;
} else {
if (Portfolio::VISIBILITY_EVERYBODY === $visibility || Portfolio::VISIBILITY_PLATFORM_USER === $visibility) {
$isVisible = true;
} elseif (Portfolio::VISIBILITY_USER === $visibility) {
$portfolioUsers = $portfolio->getPortfolioUsers();
foreach ($portfolioUsers as $portfolioUser) {
if ($user === $portfolioUser->getUser()) {
$isVisible = true;
break;
}
}
if (!$isVisible) {
$portfolioGroups = $portfolio->getPortfolioGroups();
$userGroups = $user->getGroups();
foreach ($portfolioGroups as $portfolioGroup) {
foreach ($userGroups as $userGroup) {
if ($userGroup === $portfolioGroup->getGroup()) {
$isVisible = true;
break;
}
}
}
}
if (!$isVisible) {
$portfolioTeams = $portfolio->getPortfolioTeams();
/** @var \Claroline\TeamBundle\Entity\Team[] $userTeams */
$userTeams = $this->teamManager->getTeamsByUser($user);
foreach ($portfolioTeams as $portfolioTeam) {
foreach ($userTeams as $userTeam) {
if ($userTeam === $portfolioTeam->getTeam()) {
$isVisible = true;
break;
}
}
}
}
}
}
return $isVisible;
}
示例2: generateGroupRestrictions
private function generateGroupRestrictions(User $user)
{
$restrictions = [];
if (!$user->hasRole('ROLE_ADMIN')) {
$restrictions = $user->getGroups()->toArray();
}
return $restrictions;
}
示例3: removeUser
public function removeUser(User $user)
{
$user->getGroups()->removeElement($this);
}
示例4: listUserGroupsAction
/**
* Get list of groups a user belongs to.
*
* @param User $user
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @Route(
* "/group/current_user",
* name = "innova_path_criteria_user_groups"
* )
* @Method("GET")
* @ParamConverter("user", converter="current_user", options={"allowAnonymous"=true})
*/
public function listUserGroupsAction(User $user = null)
{
$data = [];
if ($user) {
// Retrieve Groups of the User
$groups = $user->getGroups();
// data needs to be explicitly set because Group does not extends Serializable
foreach ($groups as $group) {
$data[$group->getId()] = $group->getName();
}
}
return new JsonResponse($data);
}