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
|
|
|
|
25
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Relgroupuser class. |
29
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
30
|
|
|
* of XOOPS user class objects. |
31
|
|
|
*/ |
32
|
|
|
class Relgroupuser extends \XoopsObject |
33
|
|
|
{ |
34
|
|
|
public \XoopsDatabase $db; |
35
|
|
|
public Helper $helper; |
36
|
|
|
public Permission $permHelper; |
37
|
|
|
public $rel_id; |
38
|
|
|
public $rel_group_id; |
39
|
|
|
public $rel_user_uid; |
40
|
|
|
// constructor |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Relgroupuser constructor. |
44
|
|
|
* @param null $id |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function __construct($id = null) |
47
|
|
|
{ |
48
|
|
|
/** @var Helper $helper */ |
49
|
|
|
$this->helper = Helper::getInstance(); |
50
|
|
|
$this->permHelper = new Permission(); |
51
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
52
|
|
|
$this->initVar('rel_id', \XOBJ_DTYPE_INT, null, false, 10); |
53
|
|
|
$this->initVar('rel_group_id', \XOBJ_DTYPE_INT, null, false, 10); |
54
|
|
|
$this->initVar('rel_user_uid', \XOBJ_DTYPE_INT, null, false, 10); |
55
|
|
|
if (!empty($id)) { |
56
|
|
|
if (\is_array($id)) { |
57
|
|
|
$this->assignVars($id); |
58
|
|
|
} else { |
59
|
|
|
$this->load((int)$id); |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
|
|
$this->setNew(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $id |
68
|
|
|
*/ |
69
|
|
|
public function load($id): void |
70
|
|
|
{ |
71
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('suico_relgroupuser') . ' WHERE rel_id=' . $id; |
72
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
73
|
|
|
$this->assignVars($myrow); |
74
|
|
|
if (!$myrow) { |
75
|
|
|
$this->setNew(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array $criteria |
81
|
|
|
* @param bool $asobject |
82
|
|
|
* @param string $sort |
83
|
|
|
* @param string $order |
84
|
|
|
* @param int $limit |
85
|
|
|
* @param int $start |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function getAllRelgroupusers( |
89
|
|
|
$criteria = [], |
90
|
|
|
$asobject = false, |
91
|
|
|
$sort = 'rel_id', |
92
|
|
|
$order = 'ASC', |
93
|
|
|
$limit = 0, |
94
|
|
|
$start = 0 |
95
|
|
|
) { |
96
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
97
|
|
|
$ret = []; |
98
|
|
|
$whereQuery = ''; |
99
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
100
|
|
|
$whereQuery = ' WHERE'; |
101
|
|
|
foreach ($criteria as $c) { |
102
|
|
|
$whereQuery .= " {$c} AND"; |
103
|
|
|
} |
104
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
105
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
106
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
107
|
|
|
} |
108
|
|
|
if ($asobject) { |
109
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('suico_relgroupuser') . "{$whereQuery} ORDER BY {$sort} {$order}"; |
110
|
|
|
$result = $db->query($sql, $limit, $start); |
111
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
112
|
|
|
$ret[] = new self($myrow); |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
$sql = 'SELECT rel_id FROM ' . $db->prefix( |
116
|
|
|
'suico_relgroupuser' |
117
|
|
|
) . "{$whereQuery} ORDER BY {$sort} {$order}"; |
118
|
|
|
$result = $db->query($sql, $limit, $start); |
119
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
120
|
|
|
$ret[] = $myrow['suico_relgroupuser_id']; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $ret; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get form |
129
|
|
|
* |
130
|
|
|
* @return \XoopsModules\Suico\Form\RelgroupuserForm |
131
|
|
|
*/ |
132
|
|
|
public function getForm() |
133
|
|
|
{ |
134
|
|
|
return new Form\RelgroupuserForm($this); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return array|null |
139
|
|
|
*/ |
140
|
|
|
public function getGroupsRead() |
141
|
|
|
{ |
142
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
143
|
|
|
return $this->permHelper->getGroupsForItem( |
144
|
|
|
'sbcolumns_read', |
145
|
|
|
$this->getVar('rel_id') |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return array|null |
151
|
|
|
*/ |
152
|
|
|
public function getGroupsSubmit() |
153
|
|
|
{ |
154
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
155
|
|
|
return $this->permHelper->getGroupsForItem( |
156
|
|
|
'sbcolumns_submit', |
157
|
|
|
$this->getVar('rel_id') |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return array|null |
163
|
|
|
*/ |
164
|
|
|
public function getGroupsModeration() |
165
|
|
|
{ |
166
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
167
|
|
|
return $this->permHelper->getGroupsForItem( |
168
|
|
|
'sbcolumns_moderation', |
169
|
|
|
$this->getVar('rel_id') |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|