CustomtaskContentService.class.php
7.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
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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/5/18
* Time: 11:36
*/
namespace Common\Service;
use Com\Rpc;
use Common\Common\Constant;
use Common\Model\CustomtaskContentModel;
class CustomtaskContentService extends AbstractService
{
// 构造方法
public function __construct()
{
parent::__construct();
$this->_d = new CustomtaskContentModel();
}
/**
* 获取格式化后的任务内容(追加任务内容详情页url)
* @author liyifei
* @param array $customtask_id 常规任务ID
* @return array
*/
public function getData($customtask_id)
{
$contents = $this->list_by_conds(['customtask_id' => $customtask_id], null, ['`order`' => 'ASC']);
if (empty($contents)) {
return [];
}
// FIXME zhonglei 2017年09月20日14:45:17 久哥要求管理后台常规任务详情页任务内容列表,如果是考试,要能点击图标跳转到考试统计
$exam_datas = [];
$exam_contents = array_filter($contents, function ($v) {
return $v['app'] == Constant::APP_EXAM;
});
// 课程数据
$course_datas = [];
$course_contents = array_filter($contents, function ($v) {
return $v['app'] == Constant::APP_COURSE;
});
// 如果包含考试内容,则根据应用数据ID,查找oa_exam_paper表对应数据
if (!empty($exam_contents)) {
$ep_ids = array_column($exam_contents, 'app_data_id');
$model = new \Common\Model\CommonModel('Paper', 'oa_exam_');
$list = $model->list_by_conds(['ep_id' => $ep_ids]);
if (!empty($list)) {
$exam_datas = array_combine_by_key($list, 'ep_id');
}
}
// 如果包含课程内容,则根据应用数据ID,查找oa_course_article表对应数据
if (!empty($course_contents)) {
$article_ids = array_column($course_contents, 'app_data_id');
$model = new \Common\Model\CommonModel('Article', 'oa_course_');
$course_list = $model->list_by_conds(['article_id' => $article_ids]);
if (!empty($course_list)) {
$course_datas = array_combine_by_key($course_list, 'article_id');
}
}
$urlConf = $this->getUrlConfig();
foreach ($contents as &$content) {
$app_data_id = $content['app_data_id'];
$content['url'] = $urlConf[$content['app']] . $app_data_id;
// 考试内容,补全考试数据
if ($content['app'] == Constant::APP_EXAM && isset($exam_datas[$app_data_id])) {
$content['ep_type'] = $exam_datas[$app_data_id]['exam_type'];
$content['exam_type'] = $exam_datas[$app_data_id]['exam_type'];
$content['paper_type'] = $exam_datas[$app_data_id]['paper_type'];
$content['exam_status'] = $exam_datas[$app_data_id]['exam_status'];
$content['url'] .= '&ep_type='.$content['ep_type'].'&paper_type='.$content['paper_type'].'&exam_type='.$content['exam_type'].'&exam_status='.$content['exam_status'];
}
// 课程内容,补全课程数据
if ($content['app'] == Constant::APP_COURSE && isset($course_datas[$app_data_id])) {
$content['data_id'] = $course_datas[$app_data_id]['data_id'];
$content['url'] .= '&data_id='.$content['data_id'];
}
}
return $contents;
}
/**
* 获取任务内容在各自app中的详情url
* @author liyifei
* @return array
*/
public function getUrlConfig()
{
$domain = SCHEME . '://' . $_SERVER['HTTP_HOST'] . '/admincp/#/c/my-app/';
return [
Constant::APP_NEWS => $domain . 'news-information/news-detail?article_id=',
Constant::APP_COURSE => $domain . 'course-center/course-detail?article_id=',
Constant::APP_EXAM => $domain . 'exam/exam-paper-detail?ep_id=',
Constant::APP_ACTIVITY => $domain . 'studyactivity/studyactivity-detail?ac_id=',
Constant::APP_QUESTIONNAIRE => $domain . 'questionnaire/questionnaire-detail?qu_id=',
];
}
/**
* @desc 根据任务ID,检查任务内容状态,删除的内容
* @author tangxingguo
* @param int $customtaskId 任务ID
* @return array|bool
*/
public function contentStatus($customtaskId)
{
// 取app_data_ids
list($dataIds, $dataInfo) = $this->groupDataId($customtaskId);
if (empty($dataIds)) {
return false;
}
// 请求应用,检查任务内容的状态
$res = [];
$dels = [];
$params = [];
foreach ($dataIds as $k => $v) {
$app = ucfirst(strtolower($k));
$url = rpcUrl("/{$app}/Rpc/TaskCenter/Info");
$params['app_data_ids'] = $v;
$contents = Rpc::phprpc($url)->invoke('index', $params);
$res[$k] = $contents;
if (array_diff($v, array_column($contents, 'app_data_id'))) {
$delDataIds = array_diff($v, array_column($contents, 'app_data_id'));
foreach ($delDataIds as $id) {
$dels[] = [
'app_data_id' => $id,
'title' => $dataInfo[$k][$id],
];
}
}
}
return [$dels, $res];
}
/**
* @desc 根据任务ID取任务内容ID,并分组
* @author tangxingguo
* @param Int $customtaskId 任务ID
* @return array
*/
public function groupDataId($customtaskId)
{
$dataIds = [];
$dataInfo = [];
// 取任务内容
$contentList = $this->list_by_conds(['customtask_id' => $customtaskId]);
// 分组
foreach ($contentList as $k => $v) {
switch ($v['app']) {
case Constant::APP_NEWS:
$dataIds[Constant::APP_NEWS][] = $v['app_data_id'];
$dataInfo[Constant::APP_NEWS][$v['app_data_id']] = $v['title'];
break;
case Constant::APP_COURSE:
$dataIds[Constant::APP_COURSE][] = $v['app_data_id'];
$dataInfo[Constant::APP_COURSE][$v['app_data_id']] = $v['title'];
break;
case Constant::APP_EXAM:
$dataIds[Constant::APP_EXAM][] = $v['app_data_id'];
$dataInfo[Constant::APP_EXAM][$v['app_data_id']] = $v['title'];
break;
case Constant::APP_ACTIVITY:
$dataIds[Constant::APP_ACTIVITY][] = $v['app_data_id'];
$dataInfo[Constant::APP_ACTIVITY][$v['app_data_id']] = $v['title'];
break;
case Constant::APP_QUESTIONNAIRE:
$dataIds[Constant::APP_QUESTIONNAIRE][] = $v['app_data_id'];
$dataInfo[Constant::APP_QUESTIONNAIRE][$v['app_data_id']] = $v['title'];
break;
}
}
return [$dataIds, $dataInfo];
}
/**
* 根据应用获取应用数据ID数组
* @author zhonglei
* @param string $app 应用
* @return array
*/
public function getAppDataIds($app)
{
return $this->_d->getAppDataIds($app);
}
}