ListController.class.php
5.73 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
183
184
185
186
187
188
189
190
191
<?php
/**
* 【考试中心-后台】 获取试卷管理列表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-23 16:28:26
* @version $Id$
*/
namespace Apicp\Controller\Paper;
use Common\Common\Constant;
use Common\Common\TaskCenter;
use Common\Common\Train;
use Common\Service\CategoryService;
use Common\Service\PaperService;
class ListController extends AbstractController
{
/** @var PaperService 实例化试卷表对象 */
protected $paper_service;
/** @var CategoryService 实例化试卷分类表对象 */
protected $cate_service;
// 试卷被使用
const PAPER_USED = 2;
// 试卷未被使用
const PAPER_NO_USE = 1;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->paper_service = new PaperService();
$this->cate_service = new CategoryService();
return true;
}
public function Index_post()
{
$params = I('post.');
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : 1;
$limit = !empty($params['limit']) ? intval($params['limit']) : PaperService::DEFAULT_LIMIT_ADMIN;
list($start, $limit) = page_limit($page, $limit);
$page_option = [$start, $limit];
// 最后更新时间倒叙
$order_option = ['last_time' => 'desc'];
// 列表总数
$total = $this->paper_service->count_search_where($params);
if ($total > 0) {
$fields = 'ep_id,exam_type,ep_type,paper_type,ec_id,ep_name,begin_time,end_time,exam_status,cate_status,is_open_makeup,topic_count,join_count,unjoin_count,total_score,last_time,marking_type';
$paper_list = $this->paper_service->list_search_where($params, $page_option, $order_option, $fields);
}
// 组装返回数据
$this->format_paper_list($paper_list);
$this->_result = [
'total' => (int)$total,
'limit' => (int)$limit,
'page' => (int)$page,
'list' => !empty($paper_list) ? $paper_list : []
];
return true;
}
/**
* 组装返回数据
* @param array $list 试卷列表
* @return bool
*/
protected function format_paper_list(&$list)
{
// 【任务对接】 0907新增任务中心使用判断
$app_data_ids = [];
if (!empty($list) && is_array($list)) {
$app_data_ids = array_column($list, 'ep_id');
}
$taskCenter = &TaskCenter::instance();
// 查询任务模块使用情况
$task_used_ids = $taskCenter->checkAppDataUsed($app_data_ids);
$train = &Train::instance();
// 查询培训模块使用情况
$train_used_ids = $train->checkUsing($app_data_ids);
// 获取被占用的试卷ID的集合
if (!empty($task_used_ids)) {
$used_ids = array_merge($task_used_ids, $train_used_ids);
} else {
$used_ids = $train_used_ids;
}
foreach ($list as &$val) {
switch ($val['exam_status']) {
// 草稿
case PaperService::PAPER_DRAFT:
$val['exam_status'] = PaperService::STATUS_DRAFT;
break;
// 已终止
case PaperService::PAPER_STOP:
$val['exam_status'] = PaperService::STATUS_STOP;
break;
// 已发布
case PaperService::PAPER_PUBLISH:
// 如果是任务类考试或者线下培训类考试或者其他类考试
if (in_array($val['exam_type'], [Constant::EXAM_TYPE_TASK, Constant::EXAM_TYPE_TRAIN, Constant::EXAM_TYPE_OTHER])) {
// 默认已开始
$val['exam_status'] = PaperService::STATUS_ING;
break;
}
// 【未开始】
if ($val['begin_time'] > MILLI_TIME) {
$val['exam_status'] = PaperService::STATUS_NOT_START;
}
// 【已开始】
if (
$val['begin_time'] < MILLI_TIME &&
($val['end_time'] >= MILLI_TIME || $val['end_time'] == 0)
) {
$val['exam_status'] = PaperService::STATUS_ING;
}
// 【已结束】
if ($val['end_time'] > 0 && $val['end_time'] < MILLI_TIME && $val['exam_type'] == Constant::EXAM_TYPE_NORMAL) {
$val['exam_status'] = PaperService::STATUS_END;
}
break;
default:
}
unset($val['last_time']);
// 获取分类
if ($val['ec_id']) {
$category = $this->cate_service->get($val['ec_id']);
$val['ec_name'] = $category['ec_name'];
unset($val['ec_id']);
}
$val['ep_id'] = (int)$val['ep_id'];
$val['ep_type'] = (int)$val['ep_type'];
$val['paper_type'] = (int)$val['paper_type'];
$val['exam_type'] = intval($val['exam_type']);
$val['exam_status'] = (int)$val['exam_status'];
$val['cate_status'] = (int)$val['cate_status'];
// 【任务对接】
if (!empty($used_ids) && is_array($used_ids)) {
// 组装使用情况:1:未使用,2:已使用
$val['is_used'] = in_array($val['ep_id'], $used_ids) ? self::PAPER_USED : self::PAPER_NO_USE;
} else {
$val['is_used'] = self::PAPER_NO_USE;
}
}
return true;
}
}