TitleListController.class.php
3.28 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
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/6/5
* Time: 10:30
*/
namespace Apicp\Controller\Exam;
use Com\PackageValidate;
use Com\Rpc;
use Common\Common\Constant;
class TitleListController extends \Apicp\Controller\AbstractController
{
/**
* TitleList
* @author tangxingguo
* @desc 题库题目列表
* @param Int page:1 当前页
* @param Int limit:20 每页数据总数
* @param String title 题目名称
* @param Array type_list 题目类型(1:单选题 2:判断题 3:问答题 4:多选题 5:语音题)
* @param Int attr_id 属性ID
* @param Int eb_id 题库ID
* @return array 题目列表
array(
'total' => 22, // 数据总数
'limit' => 20, // 每页条数
'page' => 1, // 当前页码
'list' => array( // 题库列表
array(
'et_id' => 13, // 题目ID
'title' => '送分题', // 题目名称
'et_type' => '单选题', // 题目类型
'score' => 3.00, // 题目分数
'order_num' => 3, // 题目序号(越小越靠前)
'use_num' => 31, // 使用次数
)
),
);
*/
public function Index_post()
{
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'title' => 'max:1024',
'type_list' => 'array',
'attr_id' => 'integer',
'eb_id' => 'integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 分页默认值
$postData['page'] = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$postData['limit'] = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
// 参数(默认单选题、判断题、多选题)
$param_arr = [
'page' => $postData['page'],
'limit' => $postData['limit'],
'type_list' => isset($postData['type_list']) ? $postData['type_list'] : [['type' => 1], ['type' => 2],['type' => 3], ['type' => 4]],
];
if (isset($postData['title'])) {
$param_arr['title'] = $postData['title'];
}
if (isset($postData['attr_id'])) {
$param_arr['attr_id'] = $postData['attr_id'];
}
if (isset($postData['eb_id'])) {
$param_arr['eb_id'] = $postData['eb_id'];
}
// RPC请求
$url = rpcUrl('/Exam/Rpc/Breakthrough/TitleList');
$res = Rpc::phprpc($url)->invoke('Index', $param_arr);
$res = json_decode($res, true);
if (isset($res['list']) && !empty($res['list'])) {
// 转化题目类型
$etTypeList = Constant::EXAM_TYPE_LIST;
foreach ($res['list'] as $k => $v) {
$res['list'][$k]['et_type'] = isset($etTypeList[$v['et_type']]) ? $etTypeList[$v['et_type']] : '';
}
}
$this->_result = $res;
}
}