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