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