table_common_member_magic.php
3.05 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_common_member_magic.php 27757 2012-02-14 03:08:15Z chenmengshu $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_common_member_magic extends discuz_table
{
public function __construct() {
$this->_table = 'common_member_magic';
$this->_pk = '';
parent::__construct();
}
public function delete($uid = null, $magicid = null) {
$para = array();
if($uid) {
$para[] = DB::field('uid', $uid);
}
if($magicid) {
$para[] = DB::field('magicid', $magicid);
}
if(!($where = $para ? implode(' AND ', $para) : '')) {
return null;
}
return DB::delete($this->_table, $where);
}
public function fetch_all($uid, $magicid = '', $start = 0, $limit = 0) {
$para = array();
if($uid) {
$para[] = DB::field('uid', $uid);
}
if($magicid) {
$para[] = DB::field('magicid', $magicid);
}
if($limit) {
$sql = DB::limit($start, $limit);
}
if(!count($para)) {
return null;
}
$para = implode(' AND ', $para);
return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, $para.$sql));
}
public function fetch($uid, $magicid) {
$para = array();
if($uid) {
$para[] = DB::field('uid', $uid);
}
if($magicid) {
$para[] = DB::field('magicid', $magicid);
}
if(!count($para)) {
return null;
}
$sql = implode(' AND ', $para);
return DB::fetch_first('SELECT * FROM %t WHERE %i', array($this->_table, $sql));
}
public function count($uid, $magicid) {
$para = array();
if($uid) {
$para[] = DB::field('uid', $uid);
}
if($magicid) {
$para[] = DB::field('magicid', $magicid);
}
if(!count($para)) {
return null;
}
$sql = implode(' AND ', $para);
return (int) DB::result_first('SELECT count(*) FROM %t WHERE %i', array($this->_table, $sql));
}
public function increase($uid, $magicid, $setarr, $slient = false, $unbuffered = false) {
$para = array();
$setsql = array();
$allowkey = array('num');
foreach($setarr as $key => $value) {
if(($value = intval($value)) && in_array($key, $allowkey)) {
$setsql[] = "`$key`=`$key`+'$value'";
}
}
if($uid) {
$para[] = DB::field('uid', $uid);
}
if($magicid) {
$para[] = DB::field('magicid', $magicid);
}
if(!count($para) || !count($setsql)) {
return null;
}
$sql = implode(' AND ', $para);
return DB::query('UPDATE %t SET %i WHERE %i', array($this->_table, implode(',', $setsql), $sql), $slient, $unbuffered);
}
public function count_by_uid($uid) {
return DB::result_first('SELECT COUNT(*) FROM %t mm, %t m WHERE mm.uid=%d AND mm.magicid=m.magicid', array($this->_table, 'common_magic', $uid));
}
public function fetch_magicid_by_identifier($uid, $identifier) {
return DB::result_first('SELECT m.magicid FROM %t mm,%t m WHERE mm.uid=%d AND m.identifier=%s AND mm.magicid=m.magicid', array($this->_table, 'common_magic', $uid, $identifier));
}
}
?>