ListController.class.php
2.29 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
<?php
/**
* 获活动列表
* ListController.class.php
* User: daijun
* Date: 2017年09月05日
*/
namespace Rpc\Controller\TaskCenter;
use Common\Model\ActivityModel;
use Common\Service\ActivityService;
class ListController extends AbstractController
{
public function Index()
{
// 获取参数
$params = $this->_params;
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : 1;
$limit = !empty($params['limit']) ? intval($params['limit']) : 10;
list($start, $limit) = page_limit($page, $limit);
// 分页参数
$page_option = array($start, $limit);
// 排序参数
$order_option = array('ac_id' => 'DESC');
// 考试类型为任务类
$conds['activity_type'] = ActivityService::TASK_TYPE;
// 试卷状态为已发布
$conds['activity_status'] = ActivityModel::ACTIVITY_PUBLISH;
if (!empty($params['keyword'])) {
// 如果试卷名称关键字不为空,则模糊查询试卷名称
$conds['subject like ?'] = '%' . trim($params['keyword']) . '%';
}
// 实例化service
$service = new ActivityService();
$field = 'ac_id,subject';
$list = [];
// 获取总记录数
$total = $service->count_by_conds($conds);
if ($total > 0) {
// 查询列表
$list = $service->list_by_conds($conds, $page_option, $order_option, $field);
}
$result = [
'page' => $page,
'limit' => $limit,
'total' => intval($total),
'list' => $this->format_list($list)
];
return $result;
}
/**
* 格式化列表数据
* @param array $list
* @return array
*/
private function format_list($list = [])
{
$res_list = [];
if (empty($list)) {
return $res_list;
}
// 循环格式化数据
foreach ($list as $v) {
$arr = array(
'app_data_id' => intval($v['ac_id']),
'title' => $v['subject'],
'class_name' => '',
'author' => '',
'status' => '进行中'
);
$res_list[] = $arr;
}
return $res_list;
}
}