當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserRole::findByRoleId方法代碼示例

本文整理匯總了PHP中UserRole::findByRoleId方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserRole::findByRoleId方法的具體用法?PHP UserRole::findByRoleId怎麽用?PHP UserRole::findByRoleId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserRole的用法示例。


在下文中一共展示了UserRole::findByRoleId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executePermissions

 public function executePermissions()
 {
     if (!$this->isAllowed(PERMISSION_ROLE_PERMISSION_MANAGE)) {
         return $this->raise403(t("You don't have permission"));
     }
     $id = $this->get('id');
     if (!$id || !($role = \Roles::retrieveById($id))) {
         return $this->raise404(t('Role not found!'));
     }
     //get role's members id
     /** @var \UserRole[] $userRoles */
     $userRoles = (array) \UserRole::findByRoleId($id);
     $staffs = \Users::findBySection(\Users::SECTION_STAFF);
     $members = [];
     $others = [];
     $t = [];
     foreach ($userRoles as $ur) {
         $t[$ur->getUserId()] = true;
     }
     foreach ($staffs as $staff) {
         if (isset($t[$staff->getId()])) {
             $members[$staff->getId()] = $staff;
         } else {
             if ($staff->isActive()) {
                 $others[$staff->getId()] = $staff;
             }
         }
     }
     unset($members[1]);
     unset($others[1]);
     $assigned = \Permissions::findByRoleId($role->getId(), true);
     $permissions = \Permissions::getPermissionsList();
     foreach ($permissions as $group => &$pg) {
         foreach ($pg['permissions'] as $permission => &$detail) {
             if (isset($assigned[$permission])) {
                 $detail['assigned'] = true;
             } else {
                 $detail['assigned'] = false;
             }
         }
     }
     $this->setView('Role/detail');
     $this->view()->assign(array('permissions' => $permissions, 'role' => $role, 'members' => $members, 'otherGuys' => $others));
     return $this->renderComponent();
 }
開發者ID:hosivan90,項目名稱:toxotes,代碼行數:45,代碼來源:Role.php


注:本文中的UserRole::findByRoleId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。