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


PHP User::hasRole方法代码示例

本文整理汇总了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];
 }
开发者ID:claroline,项目名称:distribution,代码行数:66,代码来源:MessageController.php

示例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'));
     }
 }
开发者ID:ChMat,项目名称:CoreBundle,代码行数:46,代码来源:WorkspaceController.php

示例3: generateWorkspaceRestrictions

 private function generateWorkspaceRestrictions(User $user)
 {
     $restrictions = [];
     if (!$user->hasRole('ROLE_ADMIN')) {
         $restrictions = $this->workspaceManager->getWorkspacesByUser($user);
     }
     return $restrictions;
 }
开发者ID:claroline,项目名称:distribution,代码行数:8,代码来源:UserManager.php


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