1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Suico; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @category Module |
17
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
18
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
19
|
|
|
* @author Bruno Barthez, Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use Xmf\Module\Helper\Permission; |
23
|
|
|
use XoopsDatabaseFactory; |
24
|
|
|
use XoopsObject; |
25
|
|
|
|
26
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Visitors class. |
30
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
31
|
|
|
* of XOOPS user class objects. |
32
|
|
|
*/ |
33
|
|
|
class Visitors extends XoopsObject |
34
|
|
|
{ |
35
|
|
|
public \XoopsDatabase $db; |
36
|
|
|
public Helper $helper; |
37
|
|
|
public Permission $permHelper; |
38
|
|
|
public $visit_id; |
39
|
|
|
public $uid_owner; |
40
|
|
|
public $uid_visitor; |
41
|
|
|
public $uname_visitor; |
42
|
|
|
public $date_visited; |
43
|
|
|
// constructor |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Visitors constructor. |
47
|
|
|
* @param null $id |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public function __construct($id = null) |
50
|
|
|
{ |
51
|
|
|
/** @var Helper $helper */ |
52
|
|
|
$this->helper = Helper::getInstance(); |
53
|
|
|
$this->permHelper = new Permission(); |
54
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
55
|
|
|
$this->initVar('visit_id', \XOBJ_DTYPE_INT, null, false, 10); |
56
|
|
|
$this->initVar('uid_owner', \XOBJ_DTYPE_INT, null, false, 10); |
57
|
|
|
$this->initVar('uid_visitor', \XOBJ_DTYPE_INT, null, false, 10); |
58
|
|
|
$this->initVar('uname_visitor', \XOBJ_DTYPE_TXTBOX, null, false); |
59
|
|
|
$this->initVar('date_visited', \XOBJ_DTYPE_INT, 0, false); |
60
|
|
|
if (!empty($id)) { |
61
|
|
|
if (\is_array($id)) { |
62
|
|
|
$this->assignVars($id); |
63
|
|
|
} else { |
64
|
|
|
$this->load((int)$id); |
65
|
|
|
} |
66
|
|
|
} else { |
67
|
|
|
$this->setNew(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $id |
73
|
|
|
*/ |
74
|
|
|
public function load($id): void |
75
|
|
|
{ |
76
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('suico_visitors') . ' WHERE visit_id=' . $id; |
77
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
78
|
|
|
$this->assignVars($myrow); |
79
|
|
|
if (!$myrow) { |
80
|
|
|
$this->setNew(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $criteria |
86
|
|
|
* @param bool $asobject |
87
|
|
|
* @param string $sort |
88
|
|
|
* @param string $order |
89
|
|
|
* @param int $limit |
90
|
|
|
* @param int $start |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getAllVisitors( |
94
|
|
|
$criteria = [], |
95
|
|
|
$asobject = false, |
96
|
|
|
$sort = 'visit_id', |
97
|
|
|
$order = 'ASC', |
98
|
|
|
$limit = 0, |
99
|
|
|
$start = 0 |
100
|
|
|
) { |
101
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
102
|
|
|
$ret = []; |
103
|
|
|
$whereQuery = ''; |
104
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
105
|
|
|
$whereQuery = ' WHERE'; |
106
|
|
|
foreach ($criteria as $c) { |
107
|
|
|
$whereQuery .= " {$c} AND"; |
108
|
|
|
} |
109
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
110
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
111
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
112
|
|
|
} |
113
|
|
|
if ($asobject) { |
114
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('suico_visitors') . "{$whereQuery} ORDER BY {$sort} {$order}"; |
115
|
|
|
$result = $db->query($sql, $limit, $start); |
116
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
117
|
|
|
$ret[] = new static($myrow); |
118
|
|
|
} |
119
|
|
|
} else { |
120
|
|
|
$sql = 'SELECT visit_id FROM ' . $db->prefix( |
121
|
|
|
'suico_visitors' |
122
|
|
|
) . "{$whereQuery} ORDER BY {$sort} {$order}"; |
123
|
|
|
$result = $db->query($sql, $limit, $start); |
124
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
125
|
|
|
$ret[] = $myrow['suico_visitors_id']; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $ret; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get form |
134
|
|
|
* |
135
|
|
|
* @return \XoopsModules\Suico\Form\VisitorsForm |
136
|
|
|
*/ |
137
|
|
|
public function getForm() |
138
|
|
|
{ |
139
|
|
|
return new Form\VisitorsForm($this); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return array|null |
144
|
|
|
*/ |
145
|
|
|
public function getGroupsRead() |
146
|
|
|
{ |
147
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
148
|
|
|
return $this->permHelper->getGroupsForItem( |
149
|
|
|
'sbcolumns_read', |
150
|
|
|
$this->getVar('visit_id') |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return array|null |
156
|
|
|
*/ |
157
|
|
|
public function getGroupsSubmit() |
158
|
|
|
{ |
159
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
160
|
|
|
return $this->permHelper->getGroupsForItem( |
161
|
|
|
'sbcolumns_submit', |
162
|
|
|
$this->getVar('visit_id') |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return array|null |
168
|
|
|
*/ |
169
|
|
|
public function getGroupsModeration() |
170
|
|
|
{ |
171
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
172
|
|
|
return $this->permHelper->getGroupsForItem( |
173
|
|
|
'sbcolumns_moderation', |
174
|
|
|
$this->getVar('visit_id') |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|