TopicListController.class.php
2.6 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
<?php
/**
* TopicListController.class.php
* 获取题库题目列表(闯关用)
* User: 何岳龙
* Date: 2017年06月01日
*/
namespace Rpc\Controller\Breakthrough;
use Common\Service\AnswerDetailService;
use Common\Service\TopicService;
class TopicListController extends AbstractController
{
// 默认分页大小
const DEFAULT_LIMIT = 10;
// 删除状态
const DELETED = 3;
// 已删除
const DELETED_YES = 1;
// 未删除
const DELETED_NO = 0;
// 闯关可以抽题的数组 1:单选,2:判断,3,问答4:多选
const BREAK_TYPE_LIST = [1, 2, 3,4];
public function Index()
{
// 获取题目ID
$params = $this->_params;
if (empty($params['et_ids'])) {
return true;
}
// 拆分题库IDS
$et_id = explode(',', $params['et_ids']);
// 组装条件
$conds = [
'et_id' => $et_id,
'et_type' => self::BREAK_TYPE_LIST
];
// 初始化列表
$list = [];
// 实例化题目表
$service = new TopicService();
// 获取总数
$total = $service->count_topic_contain_del($conds);
if ($total) {
// 获取列表
$list = $service->list_topic_contain_del($conds);
// 格式化
$list = $this->format($list);
}
$result = [
'total' => $total,
'list' => $list
];
return json_encode($result);
}
protected function format($list)
{
$answer_detailServ = new AnswerDetailService();
$list_new = [];
if (!empty($list) && is_array($list)) {
foreach ($list as $k => $v) {
$list_new[$k]['et_id'] = rintval($v['et_id']);
$list_new[$k]['title'] = $v['title'];
$list_new[$k]['title_pic'] = $answer_detailServ->pic_url($v['title_pic']);
$list_new[$k]['et_type'] = rintval($v['et_type']);
$list_new[$k]['deleted'] = $v['status'] == self::DELETED ? self::DELETED_YES : self::DELETED_NO;
$list_new[$k]['answer'] = $v['answer'];
if (!empty($v['options'])) {
// 反序列化选项数据
$et_option = unserialize($v['options']);
// 格式换题目选项数据
$options = $answer_detailServ->format_option($et_option);
} else {
$options = [];
}
$list_new[$k]['options'] = $options;
}
}
return $list_new;
}
}