RuleDetailController.class.php
2.21 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
<?php
/**
* 【考试中心-后台】 获取试卷规则
* RuleDetailController.class.php
* User: daijun
* Date: 2017-05-23
*/
namespace Apicp\Controller\Paper;
use Common\Service\PaperService;
use Common\Service\TopicAttrService;
class RuleDetailController extends AbstractController
{
/** @var PaperService */
protected $paper_service;
/** @var TopicAttrService */
protected $topic_attr_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化试卷信息表
$this->paper_service = new PaperService();
// 实例化试题属性关联关系表
$this->topic_attr_service = new TopicAttrService();
return true;
}
public function Index_post()
{
$ep_id = I('post.ep_id', 0, 'intval');
// 验证参数
if (empty($ep_id)) {
E('_EMPTY_PAPER_ID');
}
// 获取试卷信息
$data = $this->paper_service->get($ep_id);
if (!$data) {
E('_EMPTY_PAPER_DATA');
}
// 组装请求参数
$bank_ids = explode(',', $data['bank_data']);
$attr_ids = [];
if (!empty($data['tag_data'])) {
$tag_data = unserialize($data['tag_data']);
foreach ($tag_data as $v) {
$attr_ids_arr = [];
if (is_array($v['attr_data'])) {
$attr_ids_arr = array_column($v['attr_data'], 'attr_id');
}
if (!empty($attr_ids_arr) && is_array($attr_ids_arr)) {
$attr_ids = array_merge($attr_ids, $attr_ids_arr);
}
}
}
// 获取根据题库和标签计算题库对应题目数量
$bank_data = $this->topic_attr_service->get_bank_data($bank_ids, $attr_ids, $data['search_type']);
// 非高级标签对应题目数
$tag_total_list= $this->topic_attr_service->tag_count($bank_ids, $attr_ids, $data['search_type']);
// 格式化返回数据
$result = $this->paper_service->format_rule_data($data, $bank_data,$tag_total_list);
$this->_result = $result;
return true;
}
}