本文整理汇总了PHP中Claroline\CoreBundle\Entity\User::hasRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::hasRole方法的具体用法?PHP User::hasRole怎么用?PHP User::hasRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Entity\User
的用法示例。
在下文中一共展示了User::hasRole方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: contactableGroupsListAction
/**
* @EXT\Route(
* "/contactable/groups/page/{page}",
* name="claro_message_contactable_groups",
* options={"expose"=true},
* defaults={"page"=1, "search"=""}
* )
* @EXT\Route(
* "/contactable/groups/page/{page}/search/{search}",
* name="claro_message_contactable_groups_search",
* options={"expose"=true},
* defaults={"page"=1}
* )
* @EXT\ParamConverter("user", options={"authenticatedUser" = true})
* @EXT\Template()
*
* @param int $page
* @param string $search
* @param User $user
*
* @return Response
*/
public function contactableGroupsListAction(User $user, $page, $search)
{
$trimmedSearch = trim($search);
if ($user->hasRole('ROLE_ADMIN')) {
if ($trimmedSearch === '') {
$groups = $this->groupManager->getAllGroups($page);
} else {
$groups = $this->groupManager->getAllGroupsBySearch($page, $trimmedSearch);
}
} else {
$groups = [];
$workspaces = $this->workspaceManager->getWorkspacesByUserAndRoleNames($user, ['ROLE_WS_MANAGER']);
// retrieve all groups of workspace that user is manager
if (count($workspaces) > 0) {
if ($trimmedSearch === '') {
$groups = $this->groupManager->getGroupsByWorkspaces($workspaces);
} else {
$groups = $this->groupManager->getGroupsByWorkspacesAndSearch($workspaces, $search);
}
}
// get groups in which user is subscribed
$userGroups = $user->getGroups();
$userGroupsFinal = [];
if ($trimmedSearch === '') {
$userGroupsFinal = $userGroups;
} else {
$upperSearch = strtoupper($trimmedSearch);
foreach ($userGroups as $userGroup) {
$upperName = strtoupper($userGroup->getName());
if (strpos($upperName, $upperSearch) !== false) {
$userGroupsFinal[] = $userGroup;
}
}
}
// merge the 2 groups array
foreach ($userGroupsFinal as $userGroupFinal) {
if (!in_array($userGroupFinal, $groups, true)) {
$groups[] = $userGroupFinal;
}
}
$groups = $this->pagerFactory->createPagerFromArray($groups, $page);
}
return ['groups' => $groups, 'search' => $search];
}
示例2: removeUserAction
/**
* @todo Security context verification.
* @EXT\Route(
* "/{workspaceId}/remove/user/{userId}",
* name="claro_workspace_delete_user",
* options={"expose"=true},
* requirements={"workspaceId"="^(?=.*[1-9].*$)\d*$"}
* )
* @EXT\Method({"DELETE", "GET"})
* @EXT\ParamConverter(
* "workspace",
* class="ClarolineCoreBundle:Workspace\Workspace",
* options={"id" = "workspaceId", "strictId" = true}
* )
* @EXT\ParamConverter(
* "user",
* class="ClarolineCoreBundle:User",
* options={"id" = "userId", "strictId" = true}
* )
*
* Removes an user from a workspace.
*
* @param Workspace $workspace
* @param \Claroline\CoreBundle\Entity\User $user
*
* @return Response
*/
public function removeUserAction(Workspace $workspace, User $user)
{
try {
$roles = $this->roleManager->getRolesByWorkspace($workspace);
$this->roleManager->checkWorkspaceRoleEditionIsValid(array($user), $workspace, $roles);
foreach ($roles as $role) {
if ($user->hasRole($role->getName())) {
$this->roleManager->dissociateRole($user, $role);
$this->eventDispatcher->dispatch('log', 'Log\\LogRoleUnsubscribe', array($role, $user, $workspace));
}
}
$this->tagManager->deleteAllRelationsFromWorkspaceAndUser($workspace, $user);
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->tokenStorage->setToken($token);
return new Response('success', 204);
} catch (LastManagerDeleteException $e) {
return new Response('cannot_delete_unique_manager', 200, array('XXX-Claroline-delete-last-manager'));
}
}
示例3: generateWorkspaceRestrictions
private function generateWorkspaceRestrictions(User $user)
{
$restrictions = [];
if (!$user->hasRole('ROLE_ADMIN')) {
$restrictions = $this->workspaceManager->getWorkspacesByUser($user);
}
return $restrictions;
}