ListController.class.php
6.63 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
* 【手机端】03-培训安排接口
* Created by PhpStorm.
* @author:wanghuan
* @date:2017-08-29
*/
namespace Api\Controller\Plan;
use Common\Service\StageService;
use Common\Service\PlanService;
use Common\Service\PlanDoService;
class ListController extends \Api\Controller\AbstractController
{
/** @var StageService */
protected $stage_serv;
/** @var PlanService */
protected $plan_s;
/** @var PlanDoService */
protected $plan_do_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->stage_serv = new StageService();
// 实例化培训计划service
$this->plan_s = new PlanService();
// 实例化培训计划执行状态service
$this->plan_do_s = new PlanDoService();
return true;
}
/**
* 培训安排列表
*/
public function Index_post()
{
// 培训id
$ed_id = I('post.ed_id', 0, 'intval');
// 培训id为空
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 培训详情
$this->get_education($ed_id);
// 培训安排查询条件
$cond['ed_id'] = $ed_id;
// 分页
$page_option = null;
// 排序
$order_option['plan_order'] = 'ASC';
// 培训安排列表
$plans = $this->plan_s->list_by_conds($cond, $page_option, $order_option);
if (!empty($plans)) {
// 数据格式化
$plans = $this->format_data($ed_id, $plans);
}
$result = [
'ed_id' => $ed_id,
'plans' => $plans
];
// 返回结果
$this->_result = $result;
}
/**
* 格式化培训计划数据
*
* @param int $ed_id 培训id
* @param array $data 待格式化数据
*
* @return array 格式化后数据
*/
protected function format_data($ed_id, $data)
{
$stage_field = 'stage_id, stage_name, stage_order';
$list = $this->stage_serv->list_by_conds(['ed_id' => $ed_id], null, ['stage_order' => 'ASC'], $stage_field);
// 培训计划执行状态查询条件
$cond = [
'pd_uid' => $this->uid,
'ed_id' => $ed_id
];
// 培训计划执行状态列表
$plan_do_list = $this->plan_do_s->list_by_conds($cond);
// 格式化培训阶段
$stage_list = [];
foreach ($list as $stage) {
$stage_id = $stage['stage_id'];
// 格式化后数据
$stage_list[$stage_id] = [
'stage_id' => $stage_id,
'stage_name' => $stage['stage_name'],
'stage_order' => $stage['stage_order'],
'content_list' => [],
];
foreach ($data as $key => $val) {
if ($stage_id != $val['stage_id']) {
continue;
}
unset($val['stage_id']);
// 获取培训状态
$plan_status = $this->get_plan_status($val, $plan_do_list);
$plan = [
'plan_id' => intval($val['plan_id']),
'plan_name' => $val['plan_name'],
'plan_type' => intval($val['plan_type']),
'plan_obj_id' => intval($val['plan_obj_id']),
'plan_use_time' => $val['plan_use_time'],
'plan_status' => $plan_status,
'plan_sign_begin' => $val['plan_sign_begin'],
'plan_sign_end' => $val['plan_sign_end'],
'plan_sign_comments' => $val['plan_sign_comments'],
'link' => ''
];
// 课程、调研、考试RPC所需参数
$params = [
'ed_id' => $ed_id,
'plan_id' => intval($val['plan_id']),
'app_data_id' => intval($val['plan_obj_id'])
];
// 初始化应用名
$app_dir = '';
switch ($val['plan_type']) {
case PlanService::PLAN_TYPE_SOURCE:
// 课程素材
$app_dir = 'Course';
break;
case PlanService::PLAN_TYPE_QUESTION:
// 调研
$app_dir = 'Questionnaire';
break;
case PlanService::PLAN_TYPE_EXAM:
// 考试
$app_dir = 'Exam';
break;
default:
break;
}
// 应用名不为空
if (!empty($app_dir)) {
// link重新赋值
$plan['link'] = oaUrl('Frontend/Index/Train/Index', $params, '', $app_dir);
}
$stage_list[$stage_id]['content_list'][] = $plan;
}
}
return array_values($stage_list);
}
/**
* 获取培训计划执行状态
*
* @param array $plan 培训计划详情
* @param array $plan_do_list 当前登录用户培训计划完成状态列表
*
* @return int 培训计划执行状态
*/
protected function get_plan_status($plan, $plan_do_list)
{
// 培训计划操作状态:锁定
$plan_status = PlanService::PLAN_OPERATE_LOCK;
// 培训计划启用状态
$plan_use_status = $plan['plan_use_status'];
// 培训计划启用状态:失效
if (PlanService::PLAN_STATUS_CLOSE == $plan_use_status) {
// 锁定
$plan_status = PlanService::PLAN_OPERATE_LOCK;
} elseif (PlanService::PLAN_STATUS_OPEN == $plan_use_status) { // 启用
$plan_do_list = array_combine_by_key($plan_do_list, 'plan_id');
// 培训计划执行状态详情
$plan_do = $plan_do_list[$plan['plan_id']];
// 执行状态不为空为已完成状态
if (!empty($plan_do)) {
// 已完成
$plan_status = PlanService::PLAN_OPERATE_DONE;
} else {
// 培训计划启用时间
$plan_use_time = $plan['plan_use_time'];
// 当前时间小于启用时间
if (MILLI_TIME < $plan_use_time) {
// 锁定
$plan_status = PlanService::PLAN_OPERATE_LOCK;
} else {
// 开启
$plan_status = PlanService::PLAN_OPERATE_OPEN;
}
}
}
return $plan_status;
}
}