本文整理匯總了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);
}