CourseRightModel.class.php
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/10/12
* Time: 17:22
*/
namespace Common\Model;
use Common\Common\Constant;
use Common\Common\Department;
use Common\Common\Tag;
use Common\Common\User;
use Common\Common\Job;
use Common\Common\Role;
class CourseRightModel extends \Com\Model
{
// 构造方法
public function __construct()
{
parent::__construct('Right', 'oa_course_');
}
/**
* 格式化数据库中的权限数据
* @author zhonglei
* @param array $rights 权限数据
* @return array
*/
public function formatDBData($rights)
{
$data = [];
// 数据分组、去重
foreach ($rights as $right) {
if (!isset($data[$right['obj_type']]) || (isset($data[$right['obj_type']]) && !in_array($right['obj_id'], $data[$right['obj_type']]))) {
$data[$right['obj_type']][] = $right['obj_id'];
}
}
return $data;
}
/**
* 合并人员搜索条件和课程可见范围(请求UC人员列表时使用)
* @author liyifei
* @param array $userConds 人员搜索条件
* @param array $rights 课程可见范围
* @return array
*/
public function mergeRightData($userConds, $rights)
{
// 课程权限:部门
if (isset($rights[Constant::RIGHT_TYPE_DEPARTMENT])) {
$userConds['dpIdList'] = isset($userConds['dpIdList']) ? array_values(array_unique(array_merge($userConds['dpIdList'], $rights[Constant::RIGHT_TYPE_DEPARTMENT]))) : [];
// 按部门条件查询时,表示部门是否递归查询人员 【0:不递归(默认值)、1:递归】
if (!empty($userConds['dpIdList'])) {
$userConds['departmentChildrenFlag'] = 1;
}
}
// 课程权限:职位
if (isset($rights[Constant::RIGHT_TYPE_JOB])) {
$userConds['jobIdList'] = isset($userConds['jobIdList']) ? array_values(array_unique(array_merge($userConds['jobIdList'], $rights[Constant::RIGHT_TYPE_JOB]))) : [];
}
// 课程权限:角色
if (isset($rights[Constant::RIGHT_TYPE_ROLE])) {
$userConds['roleIdList'] = isset($userConds['roleIdList']) ? array_values(array_unique(array_merge($userConds['roleIdList'], $rights[Constant::RIGHT_TYPE_ROLE]))) : [];
}
// 课程权限:人员
if (isset($rights[Constant::RIGHT_TYPE_USER])) {
$userConds['memUids'] = isset($userConds['memUids']) ? array_values(array_unique(array_merge($userConds['memUids'], $rights[Constant::RIGHT_TYPE_USER]))) : [];
}
return $userConds;
}
}