1: <?php
2: 3: 4: 5:
6: if (!defined('XOOPS_ROOT_PATH')) exit();
7: class MessageInboxObject extends XoopsSimpleObject
8: {
9: public function __construct()
10: {
11: $this->initVar('inbox_id', XOBJ_DTYPE_INT, 0);
12: $this->initVar('uid', XOBJ_DTYPE_INT, 0, true);
13: $this->initVar('from_uid', XOBJ_DTYPE_INT, 0, true);
14: $this->initVar('title', XOBJ_DTYPE_STRING, '', true, 255);
15: $this->initVar('message', XOBJ_DTYPE_TEXT, '', true);
16: $this->initVar('utime', XOBJ_DTYPE_INT, time(), true);
17: $this->initVar('is_read', XOBJ_DTYPE_INT, 0);
18: $this->initVar('uname', XOBJ_DTYPE_STRING, '', true, 100);
19: }
20:
21: public function setVar($key, $value)
22: {
23: $this->set($key, $value);
24: }
25:
26: public function set($key, $value)
27: {
28: switch ($key) {
29: case 'subject': $key = 'title'; break;
30: case 'from_userid': $key = 'from_uid'; break;
31: case 'msg_text': $key = 'message'; break;
32: case 'to_userid': $key = 'uid'; break;
33: case 'read_msg': $key = 'is_read'; break;
34: case 'msg_time': $key = 'utime'; break;
35: }
36:
37: $this->assignVar($key, $value);
38: }
39: }
40:
41: class MessageInboxHandler extends XoopsObjectGenericHandler
42: {
43: public $mTable = 'message_inbox';
44: public $mPrimary = 'inbox_id';
45: public $mClass = 'MessageInboxObject';
46:
47: public function __construct(&$db)
48: {
49: parent::XoopsObjectGenericHandler($db);
50: }
51:
52: public function getCountUnreadByFromUid($uid)
53: {
54: $criteria = new CriteriaCompo(new Criteria('is_read', 0));
55: $criteria->add(new Criteria('uid', $uid));
56: return $this->getCount($criteria);
57: }
58:
59: public function getInboxCount($uid)
60: {
61: $criteria = new CriteriaCompo(new Criteria('uid', $uid));
62: return $this->getCount($criteria);
63: }
64:
65: public function getSendUserList($uid = 0, $fuid = 0)
66: {
67: $ret = array();
68: $sql = "SELECT u.`uname`,u.`uid` FROM `".$this->db->prefix('users')."` u, ";
69: $sql.= '`'.$this->mTable."` i ";
70: $sql.= "WHERE i.`from_uid` = u.`uid` ";
71: $sql.= "AND i.`uid` = ".$uid." ";
72: $sql.= "GROUP BY u.`uname`, u.`uid`";
73:
74: $result = $this->db->query($sql);
75: while ($row = $this->db->fetchArray($result)) {
76: if ( $fuid == $row['uid'] ) {
77: $row['select'] = true;
78: } else {
79: $row['select'] = false;
80: }
81: $ret[] = $row;
82: }
83: return $ret;
84: }
85:
86: public function deleteDays($day, $type)
87: {
88: if ( $day < 1 ) {
89: return;
90: }
91: $time = time() - ($day * 86400);
92: $sql = "DELETE FROM `".$this->mTable."` ";
93: $sql.= "WHERE `utime` < ".$time." ";
94: if ( $type == 0 ) {
95: $sql.= "AND `is_read` = 1 ";
96: } else {
97: $sql.= "AND `is_read` < 2 ";
98: }
99: $this->db->queryF($sql);
100: }
101:
102: public function _makeCriteria4sql($criteria)
103: {
104: $this->_chane_old($criteria);
105: return parent::_makeCriteria4sql($criteria);
106: }
107:
108: private function _chane_old(&$criteria)
109: {
110: if ( is_a($criteria, 'CriteriaElement') ) {
111: if ( $criteria->hasChildElements() ) {
112: for ( $i = 0; $i < $criteria->getCountChildElements(); $i++ ) {
113: $this->_chane_old($criteria->criteriaElements[$i]);
114: }
115: } elseif ( get_class($criteria) == 'Criteria' ) {
116: switch ( $criteria->column ) {
117: case 'read_msg': $criteria->column = 'is_read'; break;
118: case 'to_userid': $criteria->column = 'uid'; break;
119: case 'subject': $criteria->column = 'title'; break;
120: case 'from_userid': $criteria->column = 'from_uid'; break;
121: case 'msg_text': $criteria->column = 'message'; break;
122: case 'msg_time': $criteria->column = 'utime'; break;
123: }
124: }
125: }
126: }
127: }
128: ?>
129: