table_forum_groupuser.php
5.67 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_groupuser.php 31121 2012-07-18 06:01:56Z liulanbo $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_groupuser extends discuz_table
{
public function __construct() {
$this->_table = 'forum_groupuser';
$this->_pk = '';
parent::__construct();
}
public function fetch_all_fid_by_uids($uids) {
if(empty($uids)) {
return array();
}
$data = array();
$query = DB::query("SELECT fid FROM %t WHERE %i AND level>0 ORDER BY lastupdate DESC", array($this->_table, DB::field('uid', $uids)));
while($row = DB::fetch($query)) {
$data[] = $row['fid'];
}
return $data;
}
public function fetch_userinfo($uid, $fid) {
if(empty($uid) || empty($fid)) {
return array();
}
return DB::fetch_first("SELECT * FROM %t WHERE fid=%d AND uid=%d", array($this->_table, $fid, $uid));
}
public function fetch_all_userinfo($uids, $fid) {
if(empty($uids) || empty($fid)) {
return array();
}
return DB::fetch_all("SELECT * FROM %t WHERE fid=%d AND ".DB::field('uid', $uids), array($this->_table, $fid));
}
public function fetch_all_by_fid($fid, $level = 0) {
if(empty($fid)) {
return array();
}
$levelsql = ' AND level>0';
if($level == 1) {
$levelsql = ' AND level=0';
} elseif($level == -1) {
$levelsql = '';
}
return DB::fetch_all("SELECT * FROM %t WHERE fid=%d".$levelsql, array($this->_table, $fid));
}
public function fetch_count_by_fid($fid, $level = 0) {
$levelsql = ' AND level>0';
if($level == 1) {
$levelsql = ' AND level=0';
} elseif($level == -1) {
$levelsql = '';
}
return DB::result_first("SELECT COUNT(*) FROM %t WHERE fid=%d".$levelsql, array($this->_table, $fid));
}
public function insert($fid, $uid, $username, $level, $joindateline, $lastupdate = 0) {
DB::query("INSERT INTO %t (fid, uid, username, level, joindateline, lastupdate) VALUES (%d,%d,%s,%d,%d,%d)", array($this->_table, $fid, $uid, addslashes($username), $level, $joindateline, $lastupdate));
}
public function update_counter_for_user($uid, $fid, $threads = 0, $replies = 0) {
if(empty($uid) || empty($fid)) {
return array();
}
$sql = $threads ? 'threads=threads+1' : '';
if($replies) {
$sql = ($sql ? ', ' : '').'replies=replies+1';
}
if(empty($sql)) {
return false;
}
DB::query("UPDATE ".DB::table('forum_groupuser')." SET $sql, lastupdate='".TIMESTAMP."' WHERE fid=%d AND uid=%d", array($fid, $uid));
}
public function delete_by_fid($fids, $uid = 0) {
if(empty($fids)) {
return false;
}
if($uid) {
$sqladd = ' AND '.DB::field('uid', $uid);
}
DB::query("DELETE FROM ".DB::table('forum_groupuser')." WHERE %i ".$sqladd, array(DB::field('fid', $fids)));
}
public function update_for_user($uid, $fid, $threads = null, $replies = null, $level = null) {
if(empty($uid) || empty($fid)) {
return array();
}
$sqladd = $threads !== null ? 'threads='.intval($threads) : '';
if($replies !== null) {
$sqladd .= ($sqladd ? ', ' : '').'replies='.intval($replies);
}
if($level !== null) {
$sqladd .= ($sqladd ? ', ' : '').'level='.intval($level);
}
DB::query("UPDATE %t SET $sqladd WHERE fid=%d AND ".DB::field('uid', $uid), array($this->_table, $fid));
}
public function groupuserlist($fid, $orderby = '', $num = 0, $start = 0, $addwhere = '', $fieldarray = array(), $onlinemember = array()) {
$fid = intval($fid);
if($fieldarray && is_array($fieldarray)) {
$fieldadd = 'uid';
foreach($fieldarray as $field) {
$fieldadd .= ' ,'.$field;
}
} else {
$fieldadd = '*';
}
$sqladd = $levelwhere = '';
if($addwhere) {
if(is_array($addwhere)) {
foreach($addwhere as $field => $value) {
if(is_array($value)) {
$levelwhere = "AND level>'0' ";
$sqladd .= "AND $field IN (".dimplode($value).") ";
} else {
$sqladd .= is_numeric($field) ? "AND $value " : "AND $field='$value' ";
}
}
if(!empty($addwhere['level'])) $levelwhere = '';
} else {
$sqladd = $addwhere;
}
}
$orderbyarray = array('level_join' => 'level ASC, joindateline ASC', 'joindateline' => 'joindateline DESC', 'lastupdate' => 'lastupdate DESC', 'threads' => 'threads DESC', 'replies' => 'replies DESC');
$orderby = !empty($orderbyarray[$orderby]) ? "ORDER BY $orderbyarray[$orderby]" : '';
$limitsql = $num ? DB::limit($start, $num) : '';
$groupuserlist = array();
$query = DB::query("SELECT $fieldadd FROM ".DB::table('forum_groupuser')." WHERE fid=%d $levelwhere %i $orderby $limitsql", array($fid,$sqladd));
while($groupuser = DB::fetch($query)) {
$groupuserlist[$groupuser['uid']] = $groupuser;
$groupuserlist[$groupuser['uid']]['online'] = !empty($onlinemember) && is_array($onlinemember) && !empty($onlinemember[$groupuser['uid']]) ? 1 : 0;
}
return $groupuserlist;
}
public function fetch_all_group_for_user($uid, $count = 0, $ismanager = 0, $start = 0, $num = 0) {
$uid = intval($uid);
if(empty($uid)) {
return array();
}
if(empty($ismanager)) {
$levelsql = '';
} elseif($ismanager == 1) {
$levelsql = ' AND level IN(1,2)';
} elseif($ismanager == 2) {
$levelsql = ' AND level IN(3,4)';
}
if($count == 1) {
return DB::result_first("SELECT count(*) FROM ".DB::table('forum_groupuser')." WHERE uid='$uid' $levelsql");
}
empty($start) && $start = 0;
empty($num) && $num = 100;
return DB::fetch_all("SELECT fid, level FROM ".DB::table('forum_groupuser')." WHERE uid='$uid' $levelsql ORDER BY lastupdate DESC ".DB::limit($start, $num));
}
}
?>