table_forum_ratelog.php
3.52 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_ratelog.php 32456 2013-01-21 05:18:56Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_ratelog extends discuz_table
{
public function __construct() {
$this->_table = 'forum_ratelog';
$this->_pk = '';
parent::__construct();
}
public function fetch_by_uid_pid($uid, $pid) {
return DB::fetch_first('SELECT * FROM %t WHERE uid=%d AND pid=%d LIMIT 1', array($this->_table, $uid, $pid));
}
public function fetch_all_by_pid($pid, $sort = 'DESC') {
if(is_array($pid)) {
$pid = array_map('intval', (array)$pid);
}
$wheresql = is_array($pid) ? 'pid IN(%n)' : 'pid=%d';
return DB::fetch_all("SELECT * FROM %t WHERE $wheresql ORDER BY dateline $sort", array($this->_table, $pid));
}
public function fetch_all_sum_score($uid, $dateline) {
return DB::fetch_all('SELECT extcredits, SUM(ABS(score)) AS todayrate FROM %t WHERE uid=%d AND dateline>=%d GROUP BY extcredits', array($this->_table, $uid, $dateline));
}
public function count_by_uid_pid($uid, $pid) {
return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d AND pid=%d LIMIT 1', array($this->_table, $uid, $pid));
}
public function delete_by_pid_uid_extcredits_dateline($pid = null, $uid = null, $extcredits = null, $dateline = null) {
$parameter = array($this->_table);
$wherearr = array();
if($pid !== null) {
$parameter[] = $pid;
$wherearr[] = "pid=%d";
}
if($uid !== null) {
$parameter[] = $uid;
$wherearr[] = "uid=%d";
}
if($extcredits !== null) {
$parameter[] = $extcredits;
$wherearr[] = "extcredits=%d";
}
if($dateline !== null) {
$parameter[] = $dateline;
$wherearr[] = "dateline=%d";
}
if(!empty($wherearr)) {
$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
return DB::query("DELETE FROM %t $wheresql", $parameter, true, true);
}
return false;
}
public function fetch_postrate_by_pid($pids, $postlist, $postcache, $ratelogrecord) {
$pids = array_map('intval', (array)$pids);
$query = DB::query("SELECT * FROM ".DB::table('forum_ratelog')." WHERE pid IN (".dimplode($pids).") ORDER BY dateline DESC");
$ratelogs = array();
while($ratelog = DB::fetch($query)) {
if(count($postlist[$ratelog['pid']]['ratelog']) < $ratelogrecord) {
$ratelogs[$ratelog['pid']][$ratelog['uid']]['username'] = $ratelog['username'];
$ratelogs[$ratelog['pid']][$ratelog['uid']]['score'][$ratelog['extcredits']] += $ratelog['score'];
empty($ratelogs[$ratelog['pid']][$ratelog['uid']]['reason']) && $ratelogs[$ratelog['pid']][$ratelog['uid']]['reason'] = dhtmlspecialchars($ratelog['reason']);
$postlist[$ratelog['pid']]['ratelog'][$ratelog['uid']] = $ratelogs[$ratelog['pid']][$ratelog['uid']];
}
$postcache[$ratelog['pid']]['rate']['ratelogs'] = $postlist[$ratelog['pid']]['ratelog'];
$postcache[$ratelog['pid']]['rate']['extcredits'][$ratelog['extcredits']] = $postlist[$ratelog['pid']]['ratelogextcredits'][$ratelog['extcredits']] += $ratelog['score'];
if(!$postlist[$ratelog['pid']]['totalrate'] || !in_array($ratelog['uid'], $postlist[$ratelog['pid']]['totalrate'])) {
$postlist[$ratelog['pid']]['totalrate'][] = $ratelog['uid'];
}
$postcache[$ratelog['pid']]['rate']['totalrate'] = $postlist[$ratelog['pid']]['totalrate'];
}
return array($ratelogs, $postlist, $postcache);
}
}
?>