1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
7
|
|
|
* |
8
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
9
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
10
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
11
|
|
|
* @since 4.00 |
12
|
|
|
* @package module::newbb |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
\defined('NEWBB_FUNCTIONS_INI') || require $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php'); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* user stats |
21
|
|
|
*/ |
22
|
|
|
class UserstatsHandler extends \XoopsPersistableObjectHandler |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param \XoopsDatabase|null $db |
26
|
|
|
*/ |
27
|
|
|
public function __construct(\XoopsDatabase $db = null) |
28
|
|
|
{ |
29
|
|
|
parent::__construct($db, 'newbb_user_stats', Userstats::class, 'uid', ''); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param null $db |
|
|
|
|
34
|
|
|
* @return UserstatsHandler |
35
|
|
|
*/ |
36
|
|
|
public static function getInstance($db = null) |
37
|
|
|
{ |
38
|
|
|
static $instance; |
39
|
|
|
if (null === $instance) { |
40
|
|
|
$instance = new static($db); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $instance; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param mixed $id |
48
|
|
|
* @param null $fields |
|
|
|
|
49
|
|
|
* @return null|\XoopsObject |
50
|
|
|
*/ |
51
|
|
|
public function get($id = null, $fields = null) //get($id) |
52
|
|
|
{ |
53
|
|
|
$object = null; |
54
|
|
|
if (!$id = (int)$id) { |
55
|
|
|
return $object; |
56
|
|
|
} |
57
|
|
|
$object = $this->create(false); |
58
|
|
|
$object->setVar($this->keyName, $id); |
59
|
|
|
if (!$row = $this->getStats($id)) { |
60
|
|
|
return $object; |
61
|
|
|
} |
62
|
|
|
$object->assignVars($row); |
63
|
|
|
|
64
|
|
|
/* |
65
|
|
|
$sql = "SELECT * FROM " . $this->table . " WHERE ".$this->keyName." = " . $id; |
66
|
|
|
if (!$result = $this->db->query($sql)) { |
67
|
|
|
return $object; |
68
|
|
|
} |
69
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
70
|
|
|
$object->assignVars($row); |
71
|
|
|
} |
72
|
|
|
*/ |
73
|
|
|
|
74
|
|
|
return $object; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $id |
79
|
|
|
* @return null|array |
80
|
|
|
*/ |
81
|
|
|
public function getStats($id) |
82
|
|
|
{ |
83
|
|
|
if (empty($id)) { |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id; |
87
|
|
|
if (!$result = $this->db->query($sql)) { |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
$row = $this->db->fetchArray($result); |
91
|
|
|
|
92
|
|
|
return $row; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/* |
96
|
|
|
function insert(\XoopsObject $object, $force = true) |
97
|
|
|
{ |
98
|
|
|
if (!$object->isDirty()) { |
99
|
|
|
$object->setErrors("not isDirty"); |
100
|
|
|
|
101
|
|
|
return $object->getVar($this->keyName); |
102
|
|
|
} |
103
|
|
|
$this->loadHandler("write"); |
104
|
|
|
if (!$changedVars = $this->_handler["write"]->cleanVars($object)) { |
105
|
|
|
$object->setErrors("cleanVars failed"); |
106
|
|
|
|
107
|
|
|
return $object->getVar($this->keyName); |
108
|
|
|
} |
109
|
|
|
$queryFunc = empty($force) ? "query" : "queryF"; |
110
|
|
|
|
111
|
|
|
$keys = []; |
112
|
|
|
foreach ($changedVars as $k => $v) { |
113
|
|
|
$keys[] = " {$k} = {$v}"; |
114
|
|
|
} |
115
|
|
|
$sql = "REPLACE INTO " . $this->table . " SET ".implode(",",$keys); |
116
|
|
|
if (!$result = $this->db->{$queryFunc}($sql)) { |
117
|
|
|
$object->setErrors("update object error:" . $sql); |
118
|
|
|
|
119
|
|
|
return false; |
120
|
|
|
} |
121
|
|
|
unset($changedVars); |
122
|
|
|
|
123
|
|
|
return $object->getVar($this->keyName); |
124
|
|
|
} |
125
|
|
|
*/ |
126
|
|
|
} |
127
|
|
|
|