RightModel.class.php
2.43 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* RightModel.class.php
* $author$
*/
namespace Common\Model;
class RightModel extends AbstractModel
{
// 全部人可见
const IS_ALL = 1;
// 部分人可见
const NOT_IS_ALL = 0;
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 根据用户ID、部门ID、角色ID、岗位ID获取有这些权限的调研ID
*
* @param string $memID 用户ID
* @param array $depIDs 部门ID数组
* @param array $roleIDs 角色ID数组
* @param array $jobIDs 岗位ID数组
* @param array $tagIDs 标签ID数组
* @return array 返回有权限的调研ID数组
*/
public function get_list_id($memID, $depIDs = array(), $roleIDs = array(), $jobIDs = array(), $tagIDs = array())
{
list($where, $params) = $this->_get_list_id_where($memID, $depIDs, $roleIDs, $jobIDs, $tagIDs);
$where = ' WHERE `domain`=? AND status<? ' . $where;
array_unshift($params, self::ST_DELETE);
array_unshift($params, QY_DOMAIN);
$sql = 'SELECT * FROM __TABLE__' . $where;
$right_list = $this->_m->fetch_array($sql, $params);
$ids = array_column($right_list, 'qu_id');
return array_unique($ids);
}
/**
* 根据用户ID、部门ID、角色ID、岗位ID获取有这些权限的调研ID的sql语句where子句
*
* @param string $memID 用户ID
* @param array $depIDs 部门ID数组
* @param array $roleIDs 角色ID数组
* @param array $jobIDs 岗位ID数组
* @param array $tagIDs 标签ID数组
*
* @return string
*/
protected function _get_list_id_where($memID, $depIDs, $roleIDs, $jobIDs, $tagIDs)
{
$where = ' `uid`=?';
$params = [$memID];
if (!empty($depIDs)) {
$where .= ' OR `dp_id` IN (?)';
$params[] = $depIDs;
}
if (!empty($roleIDs)) {
$where .= ' OR `role_id` IN (?)';
$params[] = $roleIDs;
}
if (!empty($jobIDs)) {
$where .= ' OR `job_id` IN (?)';
$params[] = $jobIDs;
}
if (!empty($tagIDs)) {
$where .= ' OR `tag_id` IN (?)';
$params[] = $tagIDs;
}
return [
' AND (' . $where . ')',
$params
];
}
}