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


PHP User::getRoles方法代码示例

本文整理汇总了PHP中Claroline\CoreBundle\Entity\User::getRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getRoles方法的具体用法?PHP User::getRoles怎么用?PHP User::getRoles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Claroline\CoreBundle\Entity\User的用法示例。


在下文中一共展示了User::getRoles方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRemoveUserRoleAction

 public function testRemoveUserRoleAction()
 {
     $preCount = count($this->userOrga->getRoles());
     $this->logIn($this->adminOrga);
     $this->client->request('GET', "/api/users/{$this->userOrga->getId()}/roles/{$this->baseRole->getId()}/remove.json");
     $data = $this->client->getResponse()->getContent();
     $data = json_decode($data, true);
     $this->assertEquals($preCount - 1, count($data['roles']));
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:9,代码来源:UserControllerTest.php

示例2: logClient

 private function logClient(User $user, Client $client, $firewall = 'main')
 {
     $tokenStorage = $client->getContainer()->get('security.token_storage');
     $token = new UsernamePasswordToken($user, $user->getPlainPassword(), $firewall, $user->getRoles());
     $tokenStorage->setToken($token);
     //now we generate the cookie !
     //@see http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html
     $session = $client->getContainer()->get('session');
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
     return $client;
 }
开发者ID:claroline,项目名称:distribution,代码行数:14,代码来源:TransactionalTestCase.php

示例3: findByUser

 public function findByUser(User $user)
 {
     $dql = '
         SELECT pf
         FROM Claroline\\CoreBundle\\Entity\\Facet\\PanelFacet pf
         JOIN pf.panelFacetsRole pfr
         JOIN pfr.role r
         JOIN pf.facet f
         JOIN f.frole
         WHERE (r.name in (:roles) AND pfr.isVisible = true)
         AND frole.name : (:roles)
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('roles', $user->getRoles());
     return $query->getResult();
 }
开发者ID:claroline,项目名称:distribution,代码行数:16,代码来源:PanelFacetRepository.php

示例4: userWorkspaceListAction

 /**
  * @EXT\Route(
  *     "/user/{user}/workspaces/page/{page}/max/{max}",
  *     name="claro_admin_user_workspaces",
  *     defaults={"page"=1, "max"=50},
  *     options={"expose"=true}
  * )
  * @EXT\Template
  *
  * @param User $user
  * @param int  $page
  * @param int  $max
  *
  * @return array
  */
 public function userWorkspaceListAction(User $user, $page, $max)
 {
     $pager = $this->workspaceManager->getOpenableWorkspacesByRolesPager($user->getRoles(), $page, $max);
     return ['user' => $user, 'pager' => $pager, 'page' => $page, 'max' => $max];
 }
开发者ID:claroline,项目名称:distribution,代码行数:20,代码来源:UsersController.php

示例5: workspaceManagerActivityEvaluationsShowAction

 /**
  * @EXT\Route(
  *     "/workspace/manager/activity/{activityId}/evaluations/page/{page}",
  *     name="claro_workspace_manager_activity_evaluations_show",
  *     defaults={"page"=1}
  * )
  * @EXT\ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @EXT\ParamConverter(
  *      "activity",
  *      class="ClarolineCoreBundle:Resource\Activity",
  *      options={"id" = "activityId", "strictId" = true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Tool/workspace/analytics:workspaceManagerActivityEvaluations.html.twig")
  *
  * Displays evaluations of an activity for each user of the workspace
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function workspaceManagerActivityEvaluationsShowAction(User $currentUser, Activity $activity, $page)
 {
     $roleNames = $currentUser->getRoles();
     $workspace = $activity->getResourceNode()->getWorkspace();
     $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     if (!$isWorkspaceManager) {
         throw new AccessDeniedException();
     }
     $resourceNode = $activity->getResourceNode();
     $activityParams = $activity->getParameters();
     $roles = $this->roleManager->getRolesWithRightsByResourceNode($resourceNode);
     $usersPager = $this->userManager->getUsersByRolesIncludingGroups($roles, $page);
     $users = array();
     foreach ($usersPager as $user) {
         $users[] = $user;
     }
     $allEvaluations = $this->activityManager->getEvaluationsByUsersAndActivityParams($users, $activityParams);
     $evaluations = array();
     foreach ($allEvaluations as $evaluation) {
         $user = $evaluation->getUser();
         $evaluations[$user->getId()] = $evaluation;
     }
     $nbSuccess = 0;
     foreach ($users as $user) {
         if (!isset($evaluations[$user->getId()])) {
             $evaluations[$user->getId()] = $this->activityManager->createBlankEvaluation($user, $activityParams);
         }
         $status = $evaluations[$user->getId()]->getStatus();
         if ($status === AbstractEvaluation::STATUS_COMPLETED || $status === AbstractEvaluation::STATUS_PASSED) {
             $nbSuccess++;
         }
     }
     $progress = count($users) > 0 ? round($nbSuccess / count($users), 2) * 100 : 0;
     $ruleScore = null;
     if ($activityParams->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParams->getRules()) > 0) {
         $rule = $activityParams->getRules()->first();
         $score = $rule->getResult();
         $scoreMax = $rule->getResultMax();
         if (!is_null($score)) {
             $ruleScore = $score;
             if (!is_null($scoreMax)) {
                 $ruleScore .= ' / ' . $scoreMax;
             }
         }
     }
     return array('analyticsTab' => 'activities', 'activity' => $activity, 'activityParams' => $activityParams, 'workspace' => $workspace, 'users' => $usersPager, 'page' => $page, 'evaluations' => $evaluations, 'ruleScore' => $ruleScore, 'progress' => $progress);
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:67,代码来源:WorkspaceAnalyticsController.php

示例6: logUser

 /**
  * Logs the current user
  */
 public function logUser(User $user)
 {
     $this->strictEventDispatcher->dispatch('log', 'Log\\LogUserLogin', array($user));
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:9,代码来源:UserManager.php

示例7: findWorkspacesByManager

 public function findWorkspacesByManager(User $user, $executeQuery = true)
 {
     $roles = $user->getRoles();
     $managerRoles = [];
     foreach ($roles as $role) {
         if (strpos('_' . $role, 'ROLE_WS_MANAGER')) {
             $managerRoles[] = $role;
         }
     }
     $dql = "\n            SELECT w\n            FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w\n            JOIN w.roles r\n            WHERE r.name IN (:roleNames)\n\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('roleNames', $managerRoles);
     return $executeQuery ? $query->getResult() : $query;
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:14,代码来源:WorkspaceRepository.php

示例8: logUser

 /**
  * Logs the current user.
  */
 public function logUser(User $user)
 {
     $this->strictEventDispatcher->dispatch('log', 'Log\\LogUserLogin', [$user]);
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->tokenStorage->setToken($token);
 }
开发者ID:claroline,项目名称:distribution,代码行数:9,代码来源:UserManager.php

示例9: isWorkspaceManager

 private function isWorkspaceManager(Workspace $workspace, User $user)
 {
     $isWorkspaceManager = false;
     $managerRole = 'ROLE_WS_MANAGER_' . $workspace->getGuid();
     $roleNames = $user->getRoles();
     if (in_array('ROLE_ADMIN', $roleNames) || in_array($managerRole, $roleNames)) {
         $isWorkspaceManager = true;
     }
     return $isWorkspaceManager;
 }
开发者ID:claroline,项目名称:distribution,代码行数:10,代码来源:TeamController.php

示例10: editActivityPastEvaluationAction

 /**
  * @Route(
  *     "edit/activity/past/evaluation/{pastEvaluationId}",
  *     name="claro_activity_past_evaluation_edit",
  *     options={"expose"=true}
  * )
  * @ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @ParamConverter(
  *      "pastEvaluation",
  *      class="ClarolineCoreBundle:Activity\PastEvaluation",
  *      options={"id" = "pastEvaluationId", "strictId" = true}
  * )
  * @Template()
  */
 public function editActivityPastEvaluationAction(User $currentUser, PastEvaluation $pastEvaluation)
 {
     $isWorkspaceManager = false;
     $activityParams = $pastEvaluation->getActivityParameters();
     $activity = $activityParams->getActivity();
     if (!is_null($activity)) {
         $workspace = $activity->getResourceNode()->getWorkspace();
         $roleNames = $currentUser->getRoles();
         $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     }
     if (!$isWorkspaceManager) {
         throw new AccessDeniedException();
     }
     $form = $this->formFactory->create(new ActivityPastEvaluationType(), $pastEvaluation);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $this->activityManager->editPastEvaluation($pastEvaluation);
         return new Response('success', 204);
     }
     return array('form' => $form->createView(), 'pastEvaluation' => $pastEvaluation);
 }
开发者ID:claroline,项目名称:distribution,代码行数:35,代码来源:ActivityController.php


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