ExamPaperModel.class.php
4.75 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* Created by PhpStorm.
* User: yingcai
* Date: 2017/10/10
* Time: 下午4:00
*/
namespace Common\Model;
use Common\Common\Constant;
use Common\Common\Department;
class ExamPaperModel extends \Com\Model
{
// 构造方法
public function __construct()
{
parent::__construct('Paper', 'oa_exam_');
}
/**
* 获取用户所在部门以及父级部门的ID集合
* @param array $user
* @return array
*/
private function get_user_dp_list($user = array())
{
$dpIds = array();
// 部门ID
if (isset($user['dpName']) && !empty($user['dpName'])) {
$myDpIds = array_column($user['dpName'], 'dpId');
$dpServ = &Department::instance();
$parentDpIds = [];
// 取父级部门ID
foreach ($myDpIds as $myDpId) {
$dpServ->list_parent_cdids($myDpId, $parentDpIds);
}
$dpIds = array_unique(array_merge($myDpIds, array_values($parentDpIds)));
}
return $dpIds;
}
/**
* 获取当前用户的标签,部门,岗位,用户ID
*
* @author 英才
* @param array $user 传入当前用户信息
*
* @return array
*/
private function get_by_right($user = array())
{
// 获取用户所在部门ID以及上级部门ID
$dpIds = $this->get_user_dp_list($user);
// 职位
if (isset($user['job']['jobId'])) {
$job_ids = [$user['job']['jobId']];
// 兼容UC人员列表接口返回的职位数据
} elseif (isset($user['jobList']) && !empty($user['jobList'])) {
$job_ids = array_column($user['jobList'], 'jobId');
}
// 角色
if (isset($user['role']['roleId'])) {
$role_ids = [$user['role']['roleId']];
// 兼容UC人员列表接口返回的角色数据
} elseif (isset($user['roleList']) && !empty($user['roleList'])) {
$role_ids = array_column($user['roleList'], 'roleId');
}
return array(
'memID' => $user['memUid'],
'dpIds' => $dpIds,
'jobIds' => $job_ids,
'roleIds' => $role_ids
);
}
/**
* 根据权限获取用户有权限
* @param $user 用户信息
* @return bool
*/
public function list_paper_by_user($user)
{
$right = $this->get_by_right($user);
// 获取权限查询权限试卷列表
list($sql_right, $params_right) = $this->get_right_paper_sql($right);
if (!empty($sql_right)) {
return $this->_m->fetch_array($sql_right, $params_right);
}
return [];
}
/**
* 组装可见范围不为全公司的试卷-权限sql
* @param $cond 查询条件
* @return array sql语句、参数
*/
protected function get_right_paper_sql($right)
{
$where_right = '';
$right_params = array();
// 用户
if (!empty($right['memID'])) {
$where_right .= empty($where_right) ? " uid =? " : " OR uid =? ";
$right_params[] = $right['memID'];
}
// 部门
if (!empty($right['dpIds'])) {
$where_right .= empty($where_right) ? " `cd_id` IN (?) " : " OR `cd_id` IN (?) ";
$right_params[] = $right['dpIds'];
}
// 岗位
if (!empty($right['jobIds'])) {
$where_right .= empty($where_right) ? " `job_id` IN (?) " : " OR `job_id` IN (?) ";
$right_params[] = $right['jobIds'];
}
// 角色
if (!empty($right['roleIds'])) {
$where_right .= empty($where_right) ? " `role_id` IN (?) " : " OR `role_id` IN (?) ";
$right_params[] = $right['roleIds'];
}
if (empty($where_right)) {
return array('', []);
}
$params[] = Constant::EC_OPEN_STATES;
$params[] = Constant::PAPER_DRAFT;
$params[] = QY_DOMAIN;
$params[] = self::ST_DELETE;
$params[] = Constant::EXAM_RIGHT_PAPER;
$sql = 'SELECT `ep`.ep_id,`ep`.ep_name FROM __TABLE__ AS `ep`
LEFT JOIN `oa_exam_right` AS `r`
ON `ep`.`ep_id`=`r`.epc_id
WHERE `ep`.`cate_status`=?
AND `ep`.`exam_type`=1
AND `ep`.`exam_status`>?
AND ep.`domain`=?
AND ep.`status`<?
AND r.`er_type`=?
AND (' . $where_right . ')
AND r.`domain`=?
AND r.`status`<?';
// 合并权限where参数
$params = array_merge($params, $right_params);
$params[] = QY_DOMAIN;
$params[] = self::ST_DELETE;
return array($sql, $params);
}
}