table_home_share.php
6.3 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
207
208
209
210
211
212
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_home_share.php 27898 2012-02-16 07:43:21Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_home_share extends discuz_table
{
public function __construct() {
$this->_table = 'home_share';
$this->_pk = 'sid';
parent::__construct();
}
public function fetch_by_id_idtype($id) {
if(!$id) {
return null;
}
return DB::fetch_first('SELECT * FROM %t WHERE %i', array($this->_table, DB::field('sid', $id)));
}
public function update_dateline_by_id_idtype_uid($id, $idtype, $dateline, $uid) {
$uid = dintval($uid);
if(empty($idtype) || empty($id) || empty($uid)) {
return 0;
}
return DB::update($this->_table, array('dateline' => $dateline), DB::field($idtype, $id).' AND '.DB::field('uid', $uid));
}
public function fetch_by_type($type) {
return DB::fetch_first('SELECT * FROM %t WHERE type=%s', array($this->_table, $type));
}
public function fetch_by_sid_uid($sid, $uid) {
return DB::fetch_first('SELECT * FROM %t WHERE sid=%d AND uid=%d', array($this->_table, $sid, $uid));
}
public function fetch_all_by_uid($uids, $start = 0, $limit = 0) {
$uids = dintval($uids);
if($uids) {
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('uid', $uids).' ORDER BY dateline DESC '.DB::limit($start, $limit), array($this->_table), $this->_pk);
}
return array();
}
public function fetch_all_by_sid_uid_type($sid = 0, $uids = 0, $type = '', $start = 0, $limit = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($sid) {
$parameter[] = $sid;
$wherearr[] = 'sid=%d';
}
if(!empty($uids)) {
$uids = dintval($uids, true);
$parameter[] = $uids;
$wherearr[] = is_array($uids) ? 'uid IN(%n)' : 'uid=%d';
}
if(!empty($type)) {
$parameter[] = $type;
$wherearr[] = 'type=%s';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::fetch_all('SELECT * FROM %t '.$wheresql.' ORDER BY dateline DESC '.DB::limit($start, $limit), $parameter, $this->_pk);
}
public function fetch_all_by_username($users) {
if(!empty($users)) {
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('username', $users), array($this->_table), $this->_pk);
}
return array();
}
public function fetch_all_search($sid = 0, $uids = 0, $type = '', $starttime = 0, $endtime = 0, $starthot = 0, $endhot = 0, $start = 0, $limit = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($sid) {
$sid = dintval($sid, true);
$parameter[] = $sid;
$wherearr[] = is_array($sid) ? 'sid IN(%n)' : 'sid=%d';
}
if($uids) {
$uids = dintval($uids, true);
$parameter[] = $uids;
$wherearr[] = is_array($uids) ? 'uid IN(%n)' : 'uid=%d';
}
if(!empty($type)) {
$parameter[] = $type;
$wherearr[] = 'type=%s';
}
if($starttime) {
$parameter[] = $starttime;
$wherearr[] = 'dateline>=%d';
}
if($endtime) {
$parameter[] = $endtime;
$wherearr[] = 'dateline<=%d';
}
if($starthot) {
$parameter[] = $starthot;
$wherearr[] = 'hot>=%d';
}
if($endhot) {
$parameter[] = $endhot;
$wherearr[] = 'hot<=%d';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::fetch_all('SELECT * FROM %t '.$wheresql.' ORDER BY dateline DESC '.DB::limit($start, $limit), $parameter, $this->_pk);
}
public function count_by_type($type) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE type=%s', array($this->_table, $type));
}
public function count_by_uid_itemid_type($uid = null, $itemid = null, $type = null) {
$parameter = array($this->_table);
$wherearr = array();
if($uid !== null) {
$parameter[] = $uid;
$wherearr[] = 'uid=%d';
}
if($itemid !== null) {
$parameter[] = $itemid;
$wherearr[] = 'itemid=%d';
}
if($type !== null) {
$parameter[] = $type;
$wherearr[] = 'type=%s';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter);
}
public function count_by_sid_uid_type($sid = 0, $uids = 0, $type = '') {
$parameter = array($this->_table);
$wherearr = array();
if($sid) {
$parameter[] = $sid;
$wherearr[] = 'sid=%d';
}
if(!empty($uids)) {
$uids = dintval($uids, true);
$parameter[] = $uids;
$wherearr[] = is_array($uids) ? 'uid IN(%n)' : 'uid=%d';
}
if(!empty($type)) {
$parameter[] = $type;
$wherearr[] = 'type=%s';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter);
}
public function count_by_search($sid = 0, $uids = 0, $type = '', $starttime = 0, $endtime = 0, $starthot = 0, $endhot = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($sid) {
$sid = dintval($sid, true);
$parameter[] = $sid;
$wherearr[] = is_array($sid) ? 'sid IN(%n)' : 'sid=%d';
}
if($uids) {
$uids = dintval($uids, true);
$parameter[] = $uids;
$wherearr[] = is_array($uids) ? 'uid IN(%n)' : 'uid=%d';
}
if(!empty($type)) {
$parameter[] = $type;
$wherearr[] = 'type=%s';
}
if($starttime) {
$parameter[] = $starttime;
$wherearr[] = 'dateline>=%d';
}
if($endtime) {
$parameter[] = $endtime;
$wherearr[] = 'dateline<=%d';
}
if($starthot) {
$parameter[] = $starthot;
$wherearr[] = 'hot>=%d';
}
if($endhot) {
$parameter[] = $endhot;
$wherearr[] = 'hot<=%d';
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter);
}
public function delete_by_uid($uids) {
$uids = dintval($uids, true);
if($uids) {
return DB::query('DELETE FROM %t WHERE '.DB::field('uid', $uids), array($this->_table));
}
return 0;
}
public function update_hot_by_sid($sid, $hotuser) {
return DB::query('UPDATE %t SET hot=hot+1, hotuser=%s WHERE sid=%d', array($this->_table, $hotuser, $sid));
}
}
?>