CourseCompleteModel.class.php
3.9 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/10/11
* Time: 15:05
*/
namespace Common\Model;
class CourseCompleteModel extends \Com\Model
{
// 构造方法
public function __construct()
{
parent::__construct('Complete', 'oa_course_');
}
/**
* 获取课程完成人数排行
* @author zhonglei
*
* @param array $conds 条件
* @param int $limit 数据总数,0为取所有数据
*
* @return array
*/
public function listArticleRank($conds, $limit = 0)
{
$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 `article_id`, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `article_id` ORDER BY `total` DESC";
if ($limit > 0) {
$sql .= " LIMIT {$limit}";
}
return $this->_m->fetch_array($sql, $params);
}
/**
* 根据UID获取人员已完成课程数
* @author liyifei
*
* @param array $uids 人员UID
* @param array $articles 常规课程ID集合
*
* @return array
*/
public function completeTotalByUids($uids, $articles = [])
{
$conds = [
'uid' => $uids,
'article_id' => $articles
];
$wheres = [];
$params = [];
$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 `uid`, count(DISTINCT `article_id`) total FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid`";
return $this->_m->fetch_array($sql, $params);
}
/**
* 获取用户已完成课程门数排行
* @author zhonglei
*
* @param array $conds 条件
* @param int $limit 数据总数,0为取所有数据
*
* @return array
*/
public function listUserRank($conds, $limit = 0)
{
$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 *, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid` ORDER BY `total` DESC";
if ($limit > 0) {
$sql .= " LIMIT {$limit}";
}
return $this->_m->fetch_array($sql, $params);
}
/**
* 根据人员ID、课程ID数组,获取该人员课程完成情况
*
* @param array $datas 人员ID、课程ID数组
* + string $datas[]['uid']
* + string $datas[]['article_id']
*
* @return array
*/
public function listUserComplete($datas)
{
$domain = QY_DOMAIN;
$status = $this->get_st_delete();
$where = "`{$this->prefield}domain`='{$domain}' AND `{$this->prefield}status`<{$status} AND";
foreach ($datas as $data) {
$where .= " (`article_id` = {$data['article_id']} AND `uid` = '{$data['uid']}') OR";
}
$where = substr($where, 0, -3);
$sql = "SELECT `article_id`, `uid`, `created` AS `complete_time` FROM __TABLE__ WHERE {$where}";
return $this->_m->fetch_array($sql);
}
}