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