QuestionListController.class.php
5.26 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
180
181
182
<?php
/**
* 【考试中心-手机端】阅卷获取试题接口
* QuestionListController.class.php
* @author: 蔡建华
* @date: 2017-06-19
*/
namespace Api\Controller\Marking;
use Common\Common\User;
use Common\Service\AnswerDetailService;
use Common\Service\AnswerService;
use Common\Service\PaperService;
use Common\Service\RightService;
class QuestionListController extends AbstractController
{
public function Index_post()
{
$params = I('post.');
$ep_id = intval($params['ep_id']);
if (!$ep_id) {
// ep_id 不能为空
E('_EMPTY_EP_ID');
}
$paper_serv = new PaperService();
$paper = $paper_serv->get($ep_id);
if (empty($paper)) {
// 试卷信息不存在
E('_EMPTY_PAPER_DATA');
}
// 判断试卷类型
if ($paper['paper_type'] != PaperService::EVALUATION_PAPER_TYPE) {
// 不是测评试卷,则抛错
E('_ERR_EVALUATION_PAPER_TYPE');
}
// 判断用户是否有权进行批阅
$right_serv = new RightService();
$is_marking_right = $right_serv->count_by_conds([
'epc_id' => $ep_id,
'er_type' => RightService::RIGHT_MARKING,
'uid' => $this->uid
]);
if (!$is_marking_right) {
// 不是阅卷人
E('_ERR_MARKING_NO_QUIT');
}
$answer_serv = new AnswerService();
// 获取待批阅的答卷列表
$answer_list = $answer_serv->list_by_conds(
[
'ep_id' => $ep_id,
'answer_status' => AnswerService::READ_WAITING,
],
[],
[],
'ea_id'
);
$ea_ids = array_column($answer_list, 'ea_id');
// 待批阅总数
$total = count($ea_ids);
$ea_id = intval($params['ea_id']);
// 该试卷已经全部阅卷完毕
if (!$total && !$ea_id) {
E('_ERR_NOT_WAITING_ANSWER');
}
$waiting_total = 0;
if (!$ea_id) {
// ---首次批阅---,则需返回本次需要批阅的答卷ea_id和下一个答卷ea_id
// 如果待批阅答卷总数大于等于2,随机获取ea_id 和 next_ea_id
if ($total >= 2) {
$ea_id_key = array_rand($ea_ids, 2);
$ea_id = $ea_ids[$ea_id_key[0]];
$next_ea_id = $ea_ids[$ea_id_key[1]];
} else {
$ea_id = $ea_ids[0];
$next_ea_id = 0;
}
$waiting_total = $total;
} else {
// ---不是首次批阅---,则只需返回下一个答卷的ea_id
// 如果待批阅答卷总数大于等于2,随机获取2个next_ea_id
if ($total >= 2) {
$ea_id_key = array_rand($ea_ids, 2);
$next_ea_id = $ea_ids[$ea_id_key[0]];
// 如果获取的next_ea_id 等于当前批阅答卷的ea_id
if ($next_ea_id == $ea_id) {
$next_ea_id = $ea_ids[$ea_id_key[1]];
}
} else {
$next_ea_id = 0;
}
}
$page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
// 分页
list($start, $limit) = page_limit($page, $limit);
$conds = [
'et_type' => [
PaperService::TOPIC_TYPE_QUESTION,
PaperService::TOPIC_TYPE_VOICE
],
'ea_id' => $ea_id,
'is_status' => PaperService::DO_STATE,
];
// 实例化答卷详情service
$answer_detail_s = new AnswerDetailService();
$total = $answer_detail_s->count_by_conds($conds);
$data = [];
if ($total) {
// 获取待批阅题目列表
$order_option['order_num'] = 'ASC';
$data = $answer_detail_s->list_by_conds($conds, [$start, $limit], $order_option);
} else {
// 没有获取到可阅试题
E('_EMPTY_TOP_PAPER_DATA');
}
// 获取答卷信息
$waiting_answer = $answer_serv->get($ea_id);
// 获取考生信息
$user_serv = User::instance();
$user = $user_serv->getByUid($waiting_answer['uid']);
// 格式化题目列表(阅卷解析)
$list = $answer_detail_s->question_list_format(
$data,
$paper['marking_type'],
AnswerService::ANSWER_MARKING_ANALYSIS
);
$result = [
'username' => $user['memUsername'],
'my_end_time' => $waiting_answer['my_end_time'],
'ea_id' => $ea_id,
'next_ea_id' => $next_ea_id,
'list' => $list,
];
// 待批阅答卷总数(只有第一次进入批阅时会返回)
if ($waiting_total) {
// 待批阅试卷总数
$result['waiting_total'] = $waiting_total;
}
// 是否开启匿名批阅
if (AnswerService::OPEN_ANONYMOUS_MARKING == $paper['is_open_anonymous_marking']) {
unset($result['username']);
}
// 返回结果
$this->_result = $result;
return true;
}
}