RecordController.class.php
3.14 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
<?php
/**
* 【考试中心-后台】获取考试统计详情
* RecordController.class.php
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-23 16:33:46
* @version $Id$
*/
namespace Apicp\Controller\Answer;
use Common\Service\CategoryService;
use Common\Service\PaperService;
use Common\Service\RightService;
use Common\Service\AnswerService;
class RecordController extends AbstractController
{
// 旧数据
const OLD_DATA = 1;
// 新数据
const NEW_DATA = 2;
/** @var CategoryService */
protected $cate_service;
/** @var PaperService */
protected $paper_service;
/** @var RightService */
protected $right_service;
/** @var AnswerService */
protected $answer_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化试卷分类service
$this->cate_service = new CategoryService();
// 实例化试卷service
$this->paper_service = new PaperService();
// 实例化权限service
$this->right_service = new RightService();
// 实例化答卷service
$this->answer_service = new AnswerService();
return true;
}
public function Index_post()
{
$ep_id = I('ep_id', 0, 'intval');
//获取试卷ID
if (!$ep_id) {
E('_EMPTY_EP_ID');
}
// 获取试卷详情
$paper = $this->paper_service->get($ep_id);
// 试卷不存在
if (empty($paper)) {
E('_ERR_PAPER_NOT_FOUND');
}
// 新老数据标识
$is_old = $paper['is_old'];
// 试卷类型:1=自主,2=规则,3=随机
$ep_type = $paper['ep_type'];
// 是否显示试题分析:默认新数据显示
$show_analysis = self::NEW_DATA;
// 随机抽题
if (PaperService::TOPIC_RANDOM == $ep_type) {
// 老数据
if (self::OLD_DATA == $is_old) {
// 随机老数据不显示
$show_analysis = self::OLD_DATA;
}
}
$conds = [
'epc_id' => $ep_id,
'er_type' => PaperService::RIGHT_PAPER
];
// 权限范围
$right = [];
if ($paper['is_all'] != PaperService::AUTH_ALL) {
list($db_right, $right) = $this->right_service->get_right_data($conds);
}
// 获取分类名称
$category = $this->cate_service->get($paper['ec_id']);
// 组装返回数据
$data = array(
'paper_type' => (int)$paper['paper_type'],
'ep_name' => $paper['ep_name'],
'begin_time' => $paper['begin_time'],
'end_time' => $paper['end_time'],
'paper_time' => $paper['paper_time'],
'total_score' => (int)$paper['total_score'],
'pass_score' => (int)$paper['pass_score'],
'ec_name' => $category['ec_name'],
'is_all' => (int)$paper['is_all'],
'right' => $right ? $right : [],
'show_analysis' => $show_analysis
);
$this->_result = $data;
}
}