Files
OMS/app/ome/model/roles.php
2026-01-04 19:08:31 +08:00

79 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ome_mdl_roles extends dbeav_model{
/**
* 获取当前用户的权限
*
* @return $acts
*/
function getUserroles()
{
//如果是超级管理员,则返回->get_name()
if (kernel::single('desktop_user')->is_super())
{
return array('is_super' => true);
}
$usr_permissions = $this->getPermissions(kernel::single('desktop_user')->has_roles());
$return = array();
foreach ($usr_permissions as $permission)
{
$return = array_merge($return,$this->getactroles($permission));
}
return $return;
}
function get_all_permits()
{
$record_roles = $this->db->select("SELECT * from sdb_ome_roles where disabled='false'");
foreach ($record_roles as $onerole)
{
$return[$onerole['role']][$onerole['permission']] = true;
}
return $return;
}
//通过role获得permission这个函数应该是系统提供的
function getPermissions($roles)
{
//角色与permission的对应关系。
$return = array();
$record_roles = $this->db->select("SELECT * from sdb_ome_roles where disabled='false' and `role` in (".implode(',',$roles).")");
foreach ($record_roles as $onerecord)
{
$return[] = $onerecord['permission'];
}
$return = array_unique($return);
return $return;
}
//返回每一个角色对应本App的可操作权限。
function getactroles($permission)
{
//每个permission与本App的可操作权限对应关系。
//这是每个App自己管理的权限。
$return = array();
$record_roles = $this->db->select("SELECT * from sdb_ome_role_acts where disabled='false' and `permission` = '$permission'");
foreach ($record_roles as $oneact)
{
$return[] = $oneact['act'];
}
return $return;
}
}
?>