table_common_usergroup.php
4.88 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_common_usergroup.php 31679 2012-09-21 02:09:05Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_common_usergroup extends discuz_table
{
public function __construct() {
$this->_table = 'common_usergroup';
$this->_pk = 'groupid';
parent::__construct();
}
public function fetch_by_credits($credits, $type = 'member') {
if(is_array($credits)) {
$creditsf = intval($credits[0]);
$creditse = intval($credits[1]);
} else {
$creditsf = $creditse = intval($credits);
}
return DB::fetch_first('SELECT grouptitle, groupid FROM %t WHERE '.($type ? DB::field('type', $type).' AND ' : '').'%d>=creditshigher AND %d<creditslower LIMIT 1', array($this->_table, $creditsf, $creditse));
}
public function fetch_all_by_type($type = '', $radminid = null, $allfields = false) {
$parameter = array($this->_table);
$wherearr = array();
if(!empty($type)) {
$parameter[] = $type;
$wherearr[] = is_array($type) ? 'type IN(%n)' : 'type=%s';
}
if($radminid !== null) {
$parameter[] = $radminid;
$wherearr[] = 'radminid=%d';
}
$wheresql = !empty($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::fetch_all('SELECT '.($allfields ? '*' : 'groupid, grouptitle').' FROM %t '.$wheresql, $parameter, $this->_pk);
}
public function update($id, $data, $type = '') {
if(!is_array($data) || !$data || !is_array($data) || !$id) {
return null;
}
$condition = DB::field('groupid', $id);
if($type) {
$condition .= ' AND '.DB::field('type', $type);
}
return DB::update($this->_table, $data, $condition);
}
public function delete($id, $type = '') {
if(!$id) {
return null;
}
$condition = DB::field('groupid', $id);
if($type) {
$condition .= ' AND '.DB::field('type', $type);
}
return DB::delete($this->_table, $condition);
}
public function fetch_all_by_groupid($gid) {
if(!$gid) {
return null;
}
return DB::fetch_all('SELECT groupid FROM %t WHERE groupid IN (%n) AND type=\'special\' AND radminid>0', array($this->_table, $gid), $this->_pk);
}
public function fetch_all_by_not_groupid($gid) {
return DB::fetch_all('SELECT groupid, type, grouptitle, creditshigher, radminid FROM %t WHERE type=\'member\' AND creditshigher=\'0\' OR (groupid NOT IN (%n) AND radminid<>\'1\' AND type<>\'member\') ORDER BY (creditshigher<>\'0\' || creditslower<>\'0\'), creditslower, groupid', array($this->_table, $gid), $this->_pk);
}
public function fetch_all_not($gid, $creditnotzero = false) {
return DB::fetch_all('SELECT groupid, radminid, type, grouptitle, creditshigher, creditslower FROM %t WHERE groupid NOT IN (%n) ORDER BY '.($creditnotzero ? "(creditshigher<>'0' || creditslower<>'0'), " : '').'creditshigher, groupid', array($this->_table, $gid), $this->_pk);
}
public function fetch_new_groupid($fetch = false) {
$sql = 'SELECT groupid, grouptitle FROM '.DB::table($this->_table)." WHERE type='member' AND creditslower>'0' ORDER BY creditslower LIMIT 1";
if($fetch) {
return DB::fetch_first($sql);
} else {
return DB::result_first($sql);
}
}
public function fetch_all($ids) {
if(!$ids) {
return null;
}
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('groupid', $ids).' ORDER BY type, radminid, creditshigher', array($this->_table), $this->_pk);
}
public function fetch_all_switchable($ids) {
if(!$ids) {
return null;
}
return DB::fetch_all('SELECT * FROM %t WHERE (type=\'special\' AND system<>\'private\' AND radminid=\'0\') OR groupid IN (%n) ORDER BY type, system', array($this->_table, $ids), $this->_pk);
}
public function range_orderby_credit() {
return DB::fetch_all('SELECT * FROM %t ORDER BY (creditshigher<>\'0\' || creditslower<>\'0\'), creditslower, groupid', array($this->_table), $this->_pk);
}
public function range_orderby_creditshigher() {
return DB::fetch_all('SELECT * FROM %t ORDER BY creditshigher', array($this->_table), $this->_pk);
}
public function fetch_all_by_radminid($radminid, $glue = '>', $orderby = 'type'){
$ordersql = '';
if($ordersql = DB::order($orderby, 'DESC')) {
$ordersql = ' ORDER BY '.$ordersql;
}
return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, DB::field('radminid', intval($radminid), $glue) . $ordersql), 'groupid');
}
public function fetch_table_struct($result = 'FIELD') {
$datas = array();
$query = DB::query('DESCRIBE %t', array($this->_table));
while($data = DB::fetch($query)) {
$datas[$data['Field']] = $result == 'FIELD' ? $data['Field'] : $data;
}
return $datas;
}
public function buyusergroup_exists() {
return DB::result_first("SELECT COUNT(*) FROM %t WHERE type='special' and system>0", array($this->_table));
}
}
?>