table_home_notification.php
4.08 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
119
120
121
122
123
124
125
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_home_notification.php 34369 2014-04-01 02:00:04Z jeffjzhang $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_home_notification extends discuz_table
{
public function __construct() {
$this->_table = 'home_notification';
$this->_pk = 'id';
parent::__construct();
}
public function delete_clear($new, $days) {
$days = TIMESTAMP - intval($days) * 86400;
DB::query("DELETE FROM %t WHERE new=%d AND dateline<%d", array($this->_table, $new, $days));
}
public function delete_by_type($type, $uid = 0) {
if(!$type) {
return;
}
$uid = $uid ? ' AND '.DB::field('uid', $uid) : '';
return DB::query("DELETE FROM %t WHERE type=%s %i", array($this->_table, $type, $uid));
}
public function optimize() {
DB::query("OPTIMIZE TABLE %t", array($this->_table), true);
}
public function fetch_by_fromid_uid($id, $idtype, $uid) {
return DB::fetch_first("SELECT * FROM %t WHERE from_id=%d AND from_idtype=%s AND uid=%d", array($this->_table, $id, $idtype, $uid));
}
public function delete_by_id_uid($id, $uid) {
DB::query("DELETE FROM %t WHERE id=%d AND uid=%d", array($this->_table, $id, $uid));
}
public function delete_by_uid($uid) {
DB::query("DELETE FROM %t WHERE uid IN (%n) OR authorid IN (%n)", array($this->_table, $uid, $uid));
}
public function delete_by_uid_type_authorid($uid, $type, $authorid) {
return DB::query('DELETE FROM %t WHERE uid=%d AND type=%s AND authorid=%d', array($this->_table, $uid, $type, $authorid));
}
public function fetch_all_by_authorid_fromid($authorid, $fromid, $type) {
return DB::fetch_all("SELECT * FROM %t WHERE authorid=%d AND from_id=%d AND type=%s", array($this->_table, $authorid, $fromid, $type));
}
public function ignore($uid, $type = '', $category = '', $new = true, $from_num = true) {
$uid = intval($uid);
$update = array();
if($new) {
$update['new'] = 0;
}
if($from_num) {
$update['from_num'] = 0;
}
$where = array('uid' => $uid, 'new' => 1);
if($type) {
$where['type'] = $type;
}
if($category !== '') {
switch ($category) {
case 'mypost' : $category = 1; break;
case 'interactive' : $category = 2; break;
case 'system' : $category = 3; break;
case 'manage' : $category = 4; break;
default : $category = 0;
}
$where['category'] = $category;
}
if($update) {
DB::update($this->_table, $update, $where);
}
}
public function count_by_uid($uid, $new, $type = '', $category = '') {
$new = intval($new);
$type = $type ? ' AND '.DB::field('type', $type) : '';
if($category !== '') {
switch ($category) {
case 'mypost' : $category = 1; break;
case 'interactive' : $category = 2; break;
case 'system' : $category = 3; break;
case 'manage' : $category = 4; break;
default : $category = 0;
}
$category = ' AND '.DB::field('category', $category);
}
$new = $new != '-1' ? ' AND '.DB::field('new', $new) : '';
return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d %i %i %i", array($this->_table, $uid, $new, $category, $type));
}
public function fetch_all_by_uid($uid, $new, $type, $start, $perpage, $category = '') {
$new = intval($new);
$type = $type ? ' AND '.DB::field('type', $type) : '';
if($category !== '') {
switch ($category) {
case 'mypost' : $category = 1; break;
case 'interactive' : $category = 2; break;
case 'system' : $category = 3; break;
case 'manage' : $category = 4; break;
case 'follow' : $category = 5; break;
case 'follower' : $category = 6; break;
default : $category = 0;
}
$category = ' AND '.DB::field('category', $category);
}
$new = $new != '-1' ? ' AND '.DB::field('new', $new) : '';
return DB::fetch_all("SELECT * FROM %t WHERE uid=%d %i %i %i ORDER BY dateline DESC %i", array($this->_table, $uid, $new, $category, $type, DB::limit($start, $perpage)));
}
}
?>