PathContentService.class.php
4.54 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 18/4/24
* Time: 11:57
*/
namespace Common\Service;
use Common\Common\Constant;
use Common\Model\PathContentModel;
class PathContentService extends AbstractService
{
// 构造方法
public function __construct()
{
parent::__construct();
$this->_d = new PathContentModel();
}
/**
* 根据应用获取应用数据ID数组
* @author zhonglei
* @param string $app 应用
* @param int $path_id 路径ID
* @return array
*/
public function getAppDataIds($app, $path_id = 0)
{
return $this->_d->getAppDataIds($app, $path_id);
}
/**
* 获取格式化后的任务内容(追加任务内容详情页url)
* @author liyifei
* @param int $pathId 常规任务ID
* @return array
*/
public function formatPathContent($pathId)
{
$contents = $this->list_by_conds(['path_id' => $pathId], 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_COURSE => $domain . 'course-center/course-detail?article_id=',
Constant::APP_EXAM => $domain . 'exam/exam-paper-detail?ep_id=',
Constant::APP_QUESTIONNAIRE => $domain . 'questionnaire/questionnaire-detail?qu_id=',
];
}
/**
* 验证学习内容是否已被其他路径使用
* @param array $data 使用的学习内容
* @param int $pathId 路径ID
* @return array
*/
public function getUsePathList($data, $pathId = 0)
{
return $this->_d->getUsePathList($data, $pathId);
}
}