table_forum_medallog.php
2.79 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_medallog.php 27751 2012-02-14 02:26:11Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_medallog extends discuz_table
{
public function __construct() {
$this->_table = 'forum_medallog';
$this->_pk = 'id';
parent::__construct();
}
public function count_by_type($type) {
return DB::result_first("SELECT COUNT(*) FROM %t WHERE type=%d", array($this->_table, $type));
}
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_type($type) {
return DB::fetch_all("SELECT * FROM %t WHERE type=%d ORDER BY dateline", array($this->_table, $type), $this->_pk);
}
public function fetch_all_lastmedal($limit) {
return DB::fetch_all("SELECT * FROM %t WHERE type<'2' ORDER BY dateline DESC LIMIT %d", array($this->_table, $limit), $this->_pk);
}
public function fetch_all_by_expiration($expiration) {
return DB::fetch_all("SELECT * FROM %t WHERE status=1 AND expiration>0 AND expiration<%d", array($this->_table, $expiration));
}
public function fetch_all_by_uid($uid, $start, $limit) {
return DB::fetch_all("SELECT * FROM %t WHERE uid=%d ORDER BY dateline DESC LIMIT %d,%d", array($this->_table, $uid, $start, $limit));
}
public function update_type_by_uid_medalid($type, $uid, $medalid) {
$type = intval($type);
if(!$uid || !$medalid) {
return;
}
DB::update($this->_table, array('type' => $type), DB::field('uid', $uid).' AND '.DB::field('medalid', $medalid));
}
public function fetch_all_by_type_medalid($type, $medalid, $start_limit, $lpp) {
$where = array();
if($type !== '') {
$where[] = DB::field('type', $type);
}
if($medalid !== '') {
$where[] = DB::field('medalid', $medalid);
}
$where = $where ? 'WHERE '.implode(' AND ', $where) : '';
$start_limit = intval($start_limit);
$lpp = intval($lpp);
return DB::fetch_all("SELECT * FROM ".DB::table('forum_medallog')." $where ORDER BY dateline DESC LIMIT $start_limit, $lpp");
}
public function count_by_type_medalid($type, $medalid) {
$where = array();
if($type !== '') {
$where[] = DB::field('type', $type);
}
if($medalid !== '') {
$where[] = DB::field('medalid', $medalid);
}
$where = $where ? 'WHERE '.implode(' AND ', $where) : '';
return DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_medallog')." $where");
}
public function count_by_verify_medalid($uid, $medalid) {
return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d AND medalid=%d AND type=2", array($this->_table, $uid, $medalid));
}
}
?>