ListController.class.php
4.38 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
<?php
/**
* 获取考试统计列表
* ListController.class.php
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-23 16:30:05
* @version $Id$
*/
namespace Apicp\Controller\Answer;
use Common\Service\AnswerDetailTempService;
use Common\Service\AnswerService;
use Common\Service\AnswerTempService;
use Common\Service\PaperService;
use Common\Service\RightService;
class ListController extends AbstractController
{
/** @var PaperService 实例化试卷表对象 */
protected $paper_service;
/** @var RightService 实例化答卷表对象 */
protected $right_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->paper_service = new PaperService();
$this->right_service = new RightService();
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 = ['ep_id' => 'DESC'];
$paper_list = [];
// 只查询常规考试
$params['exam_type'] = 1;
// 列表总数
$params['search_type'] = PaperService::EXAM_LIST_STATISTICS; // 考试统计列表
$total = $this->paper_service->count_search_where($params);
if ($total > 0) {
$fields = 'ep_id,paper_type,ep_name,begin_time,end_time,exam_status,is_all,unjoin_count,join_count';
$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)
{
$answer_temp = new AnswerTempService();
$answer_detail_temp = new AnswerDetailTempService();
foreach ($list as &$paper) {
$condition = [
'epc_id' => $paper['ep_id'],
'er_type' => AnswerService::RIGHT_PAPER
];
// 组装权限
if ($paper['is_all'] != PaperService::AUTH_ALL) {
list($db_right, $right) = $this->right_service->get_right_data($condition);
$paper['right'] = !empty($right) ? $right : [];
}
switch ($paper['exam_status']) {
// 已发布
case PaperService::PAPER_PUBLISH:
// 【已开始】
if (
$paper['begin_time'] < MILLI_TIME &&
($paper['end_time'] >= MILLI_TIME || 0 == $paper['end_time'])
) {
$paper['exam_status'] = PaperService::STATUS_ING;
}
// 【已结束】
if ($paper['end_time'] > 0 && $paper['end_time'] < MILLI_TIME) {
$paper['exam_status'] = PaperService::STATUS_END;
}
break;
// 已终止
case PaperService::PAPER_STOP:
$paper['exam_status'] = PaperService::STATUS_STOP;
break;
default:
}
$paper['ep_id'] = (int)$paper['ep_id'];
$paper['is_all'] = (int)$paper['is_all'];
$paper['paper_type'] = (int)$paper['paper_type'];
// 已结束或已终止的考试,删除临时抽题答卷表的答卷
if (PaperService::STATUS_END == $paper['exam_status'] || PaperService::STATUS_STOP == $paper['exam_status']) {
$del_conds = array('ep_id' => $paper['ep_id']);
$answer_temp->delete_by_conds($del_conds);
$answer_detail_temp->delete_by_conds($del_conds);
}
}
return true;
}
}