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


PHP User::getGroups方法代码示例

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

示例2: generateGroupRestrictions

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

示例3: removeUser

 public function removeUser(User $user)
 {
     $user->getGroups()->removeElement($this);
 }
开发者ID:claroline,项目名称:distribution,代码行数:4,代码来源:Group.php

示例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);
 }
开发者ID:claroline,项目名称:distribution,代码行数:27,代码来源:StepConditionController.php


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