當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。