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
|
|
|
* Module: Yogurt |
18
|
|
|
* |
19
|
|
|
* @category Module |
20
|
|
|
* @package yogurt |
21
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
22
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
23
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
// Configs.php,v 1 |
27
|
|
|
// ---------------------------------------------------------------- // |
28
|
|
|
// Author: Bruno Barthez // |
29
|
|
|
// ----------------------------------------------------------------- // |
30
|
|
|
|
31
|
|
|
use Xmf\Module\Helper\Permission; |
32
|
|
|
use XoopsDatabaseFactory; |
33
|
|
|
use XoopsObject; |
34
|
|
|
|
35
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Configs class. |
39
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
40
|
|
|
* of XOOPS user class objects. |
41
|
|
|
*/ |
42
|
|
|
class Configs extends XoopsObject |
43
|
|
|
{ |
44
|
|
|
public $db; |
45
|
|
|
public $helper; |
46
|
|
|
public $permHelper; |
47
|
|
|
|
48
|
|
|
// constructor |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Configs constructor. |
52
|
|
|
* @param null $id |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
public function __construct($id = null) |
55
|
|
|
{ |
56
|
|
|
/** @var Helper $helper */ |
57
|
|
|
$this->helper = Helper::getInstance(); |
58
|
|
|
$this->permHelper = new Permission(); |
59
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
60
|
|
|
$this->initVar('config_id', \XOBJ_DTYPE_INT); |
61
|
|
|
$this->initVar('config_uid', \XOBJ_DTYPE_INT, null, false, 10); |
62
|
|
|
$this->initVar('pictures', \XOBJ_DTYPE_INT, null, false, 10); |
63
|
|
|
$this->initVar('audio', \XOBJ_DTYPE_INT, null, false, 10); |
64
|
|
|
$this->initVar('videos', \XOBJ_DTYPE_INT, null, false, 10); |
65
|
|
|
$this->initVar('groups', \XOBJ_DTYPE_INT, null, false, 10); |
66
|
|
|
$this->initVar('notes', \XOBJ_DTYPE_INT, null, false, 10); |
67
|
|
|
$this->initVar('friends', \XOBJ_DTYPE_INT, null, false, 10); |
68
|
|
|
$this->initVar('profile_contact', \XOBJ_DTYPE_INT, null, false, 10); |
69
|
|
|
$this->initVar('profile_general', \XOBJ_DTYPE_INT, null, false, 10); |
70
|
|
|
$this->initVar('profile_stats', \XOBJ_DTYPE_INT, null, false, 10); |
71
|
|
|
$this->initVar('suspension', \XOBJ_DTYPE_INT, null, false, 10); |
72
|
|
|
$this->initVar('backup_password', \XOBJ_DTYPE_TXTBOX, null, false); |
73
|
|
|
$this->initVar('backup_email', \XOBJ_DTYPE_TXTBOX, null, false); |
74
|
|
|
$this->initVar('end_suspension', \XOBJ_DTYPE_INT, 0, false); |
75
|
|
|
if (!empty($id)) { |
76
|
|
|
if (\is_array($id)) { |
77
|
|
|
$this->assignVars($id); |
78
|
|
|
} else { |
79
|
|
|
$this->load((int)$id); |
80
|
|
|
} |
81
|
|
|
} else { |
82
|
|
|
$this->setNew(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $id |
88
|
|
|
*/ |
89
|
|
|
public function load($id) |
90
|
|
|
{ |
91
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_configs') . ' WHERE config_id=' . $id; |
92
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
93
|
|
|
$this->assignVars($myrow); |
94
|
|
|
if (!$myrow) { |
95
|
|
|
$this->setNew(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $criteria |
101
|
|
|
* @param bool $asobject |
102
|
|
|
* @param string $sort |
103
|
|
|
* @param string $order |
104
|
|
|
* @param int $limit |
105
|
|
|
* @param int $start |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getAllConfigs( |
109
|
|
|
$criteria = [], |
110
|
|
|
$asobject = false, |
111
|
|
|
$sort = 'config_id', |
112
|
|
|
$order = 'ASC', |
113
|
|
|
$limit = 0, |
114
|
|
|
$start = 0 |
115
|
|
|
) { |
116
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
117
|
|
|
$ret = []; |
118
|
|
|
$whereQuery = ''; |
119
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
120
|
|
|
$whereQuery = ' WHERE'; |
121
|
|
|
foreach ($criteria as $c) { |
122
|
|
|
$whereQuery .= " ${c} AND"; |
123
|
|
|
} |
124
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
125
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
126
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
127
|
|
|
} |
128
|
|
|
if (!$asobject) { |
129
|
|
|
$sql = 'SELECT config_id FROM ' . $db->prefix( |
130
|
|
|
'yogurt_configs' |
131
|
|
|
) . "${whereQuery} ORDER BY ${sort} ${order}"; |
132
|
|
|
$result = $db->query($sql, $limit, $start); |
133
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
134
|
|
|
$ret[] = $myrow['yogurt_configs_id']; |
135
|
|
|
} |
136
|
|
|
} else { |
137
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('yogurt_configs') . "${whereQuery} ORDER BY ${sort} ${order}"; |
138
|
|
|
$result = $db->query($sql, $limit, $start); |
139
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
140
|
|
|
$ret[] = new self($myrow); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $ret; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get form |
149
|
|
|
* |
150
|
|
|
* @return \XoopsModules\Yogurt\Form\ConfigsForm |
151
|
|
|
*/ |
152
|
|
|
public function getForm() |
153
|
|
|
{ |
154
|
|
|
return new Form\ConfigsForm($this); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return array|null |
159
|
|
|
*/ |
160
|
|
|
public function getGroupsRead() |
161
|
|
|
{ |
162
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
163
|
|
|
return $this->permHelper->getGroupsForItem( |
164
|
|
|
'sbcolumns_read', |
165
|
|
|
$this->getVar('config_id') |
166
|
|
|
); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return array|null |
171
|
|
|
*/ |
172
|
|
|
public function getGroupsSubmit() |
173
|
|
|
{ |
174
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
175
|
|
|
return $this->permHelper->getGroupsForItem( |
176
|
|
|
'sbcolumns_submit', |
177
|
|
|
$this->getVar('config_id') |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return array|null |
183
|
|
|
*/ |
184
|
|
|
public function getGroupsModeration() |
185
|
|
|
{ |
186
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
187
|
|
|
return $this->permHelper->getGroupsForItem( |
188
|
|
|
'sbcolumns_moderation', |
189
|
|
|
$this->getVar('config_id') |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|