table_home_favorite.php
2.68 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_home_favorite.php 29149 2012-03-27 09:52:07Z chenmengshu $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_home_favorite extends discuz_table
{
public function __construct() {
$this->_table = 'home_favorite';
$this->_pk = 'favid';
parent::__construct();
}
public function fetch_all_by_uid_idtype($uid, $idtype, $favid = 0, $start = 0, $limit = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($favid) {
$parameter[] = dintval($favid, is_array($favid) ? true : false);
$wherearr[] = is_array($favid) ? 'favid IN(%n)' : 'favid=%d';
}
$parameter[] = $uid;
$wherearr[] = "uid=%d";
if(!empty($idtype)) {
$parameter[] = $idtype;
$wherearr[] = "idtype=%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 count_by_uid_idtype($uid, $idtype, $favid = 0) {
$parameter = array($this->_table);
$wherearr = array();
if($favid) {
$parameter[] = dintval($favid, is_array($favid) ? true : false);
$wherearr[] = is_array($favid) ? 'favid IN(%n)' : 'favid=%d';
}
$parameter[] = $uid;
$wherearr[] = "uid=%d";
if(!empty($idtype)) {
$parameter[] = $idtype;
$wherearr[] = "idtype=%s";
}
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::result_first("SELECT COUNT(*) FROM %t $wheresql ", $parameter);
}
public function fetch_by_id_idtype($id, $idtype, $uid = 0) {
if($uid) {
$uidsql = ' AND '.DB::field('uid', $uid);
}
return DB::fetch_first("SELECT * FROM %t WHERE id=%d AND idtype=%s $uidsql", array($this->_table, $id, $idtype));
}
public function count_by_id_idtype($id, $idtype) {
return DB::result_first("SELECT COUNT(*) FROM %t WHERE id=%d AND idtype=%s", array($this->_table, $id, $idtype));
}
public function delete_by_id_idtype($id, $idtype) {
return DB::delete($this->_table, DB::field('id', $id) .' AND '.DB::field('idtype', $idtype));
}
public function delete($val, $unbuffered = false, $uid = 0) {
$val = dintval($val, is_array($val) ? true : false);
if($val) {
if($uid) {
$uid = dintval($uid, is_array($uid) ? true : false);
}
return DB::delete($this->_table, DB::field($this->_pk, $val).($uid ? ' AND '.DB::field('uid', $uid) : ''), null, $unbuffered);
}
return !$unbuffered ? 0 : false;
}
}
?>