StudyTimeModel.class.php
2.92 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/10/9
* Time: 16:43
*/
namespace Common\Model;
class StudyTimeModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 获取已参与学习的用户ID数组(去重)
* @author zhonglei
* @param array $conds 条件
* @return array
*/
public function listDistinctUidByConds($conds)
{
$wheres = [];
$params = [];
if (is_array($conds) && !empty($conds)) {
$this->_parse_where($wheres, $params, $conds);
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT DISTINCT(`uid`) FROM __TABLE__ WHERE {$wheres_sql}";
$list = $this->_m->fetch_array($sql, $params);
return array_column($list, 'uid');
}
/**
* 获取累计学习时长(单位:秒)
*
* @param array $conditions 条件
*
* @return array
*/
public function getTotalStudyTime($conditions)
{
$wheres = [];
$params = [];
if (is_array($conditions) && !empty($conditions)) {
$this->_parse_where($wheres, $params, $conditions);
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT SUM(`study_time`) `total` FROM __TABLE__ WHERE {$wheres_sql}";
return $this->_m->result($sql, $params);
}
/**
* 获取学员课程学习时长数据
* @param int $article_id 课程id
* @param int $customtask_id 任务id
* @param int $plan_id 培训计划id
* @param int $ed_id 培训id
* @param int $map_id 学习地图id
* @param int $path_id 学习路径id
*
* @return array
*/
public function users_study_time($article_id = 0, $customtask_id = 0, $plan_id = 0, $ed_id = 0, $map_id = 0, $path_id = 0)
{
// 查询sql语句
$sql = "SELECT `uid`,SUM(`study_time`) AS `study_time` FROM `oa_course_study_time` WHERE `article_id`=? AND `customtask_id`=? AND `plan_id`=? AND `ed_id`=? AND `map_id`=? AND `path_id`=? AND `domain`=? AND `status`<? AND `source_id`!=? GROUP BY `uid`";
$status = $this->get_st_delete();
// 参数
$params = [
$article_id,
$customtask_id,
$plan_id,
$ed_id,
$map_id,
$path_id,
QY_DOMAIN,
$status,
0
];
return $this->_m->fetch_array($sql, $params);
}
}