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


PHP User::getRoles方法代码示例

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


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

示例1: getAvailablePerspectives

 /** Returns a list of available perspectives for the given user
  * @param Model\User $user
  * @return array
  */
 public static function getAvailablePerspectives($user)
 {
     $currentConfigName = null;
     $masterConfig = self::getPerspectivesConfig()->toArray();
     if ($user instanceof Model\User) {
         if ($user->isAdmin()) {
             $config = self::getPerspectivesConfig()->toArray();
         } else {
             $config = [];
             $roleIds = $user->getRoles();
             $userIds = [$user->getId()];
             $userIds = array_merge($userIds, $roleIds);
             foreach ($userIds as $userId) {
                 if (in_array($userId, $roleIds)) {
                     $userOrRoleToCheck = Model\User\Role::getById($userId);
                 } else {
                     $userOrRoleToCheck = Model\User::getById($userId);
                 }
                 $perspectives = $userOrRoleToCheck->getPerspectives();
                 if ($perspectives) {
                     foreach ($perspectives as $perspectiveName) {
                         $masterDef = $masterConfig[$perspectiveName];
                         if ($masterDef) {
                             $config[$perspectiveName] = $masterDef;
                         }
                     }
                 }
             }
             if (!$config) {
                 $config = self::getPerspectivesConfig()->toArray();
             }
         }
         if ($config) {
             $tmpConfig = [];
             $validPerspectiveNames = array_keys($config);
             // sort the stuff
             foreach ($masterConfig as $masterConfigName => $masterConfiguration) {
                 if (in_array($masterConfigName, $validPerspectiveNames)) {
                     $tmpConfig[$masterConfigName] = $masterConfiguration;
                 }
             }
             $config = $tmpConfig;
         }
         $currentConfigName = $user->getActivePerspective();
         if ($config && !in_array($currentConfigName, array_keys($config))) {
             $currentConfigName = reset(array_keys($config));
         }
     } else {
         $config = self::getPerspectivesConfig()->toArray();
     }
     $result = [];
     foreach ($config as $configName => $configItem) {
         $item = ["name" => $configName, "icon" => isset($configItem["icon"]) ? $configItem["icon"] : null, "iconCls" => isset($configItem["iconCls"]) ? $configItem["iconCls"] : null];
         if ($user) {
             $item["active"] = $configName == $currentConfigName;
         }
         $result[] = $item;
     }
     return $result;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:64,代码来源:Config.php

示例2: initUserIds

 private function initUserIds()
 {
     $this->userIds = array_merge([$this->user->getId()], $this->user->getRoles());
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:4,代码来源:Manager.php


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