table_home_userapp.php
2.92 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_home_userapp.php 27820 2012-02-15 05:15:59Z zhangguosheng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_home_userapp extends discuz_table
{
public function __construct() {
$this->_table = 'home_userapp';
$this->_pk = '';
parent::__construct();
}
public function fetch_by_uid_appid($uid, $appid) {
return DB::fetch_first('SELECT * FROM %t WHERE uid=%d AND appid=%d', array($this->_table, $uid, $appid));
}
public function fetch_max_menuorder_by_uid($uid) {
return DB::result_first('SELECT MAX(menuorder) FROM %t WHERE uid=%d', array($this->_table, $uid));
}
public function count_by_uid($uid) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d', array($this->_table, $uid));
}
public function fetch_all_by_uid_appid($uid = 0, $appid = 0, $order = null, $sort = 'DESC' , $start = 0, $limit = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($uid) {
$uid = dintval((array)$uid, true);
$wherearr[] = 'uid IN(%n)';
$parameter[] = $uid;
}
if($appid) {
$appid = dintval((array)$appid, true);
$wherearr[] = 'appid IN(%n)';
$parameter[] = $appid;
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
$sort = in_array($sort, array('DESC', 'ASC')) ? $sort : 'DESC';
$ordersql = $order !== null ? ' ORDER BY '.DB::order($order, $sort) : '';
if(!$uid) {
$limit = $limit ? $limit : 100;
}
return DB::fetch_all("SELECT * FROM %t $wheresql $ordersql ".DB::limit($start, $limit), $parameter);
}
public function update_by_uid_appid($uid = 0, $appid = 0, $data = array()) {
if($data && is_array($data)) {
$wherearr = array();
if($uid) {
$uid = dintval((array)$uid, true);
$wherearr[] = DB::field('uid', $uid);
}
if($appid) {
$appid = dintval((array)$appid, true);
$wherearr[] = DB::field('appid', $appid);
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? implode(' AND ', $wherearr) : '';
return DB::update($this->_table, $data, $wheresql);
}
return 0;
}
public function delete_by_uid_appid($uid = 0, $appid = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($uid) {
$uid = dintval((array)$uid, true);
$wherearr[] = 'uid IN(%n)';
$parameter[] = $uid;
}
if($appid) {
$appid = dintval((array)$appid, true);
$wherearr[] = 'appid IN(%n)';
$parameter[] = $appid;
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::query("DELETE FROM %t $wheresql", $parameter);
}
public function delete_by_uid($uids) {
if(($uids = dintval($uids, true))) {
return DB::delete($this->_table, DB::field('uid', $uids));
}
return 0;
}
}
?>