|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* morefiles class. |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
17
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
18
|
|
|
* |
|
19
|
|
|
* @since 2.5.7 |
|
20
|
|
|
* |
|
21
|
|
|
* @author Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/> |
|
22
|
|
|
* |
|
23
|
|
|
* @version $Id: morefiles.php 13080 2015-06-12 10:12:32Z timgno $ |
|
24
|
|
|
*/ |
|
25
|
|
|
include __DIR__.'/autoload.php'; |
|
26
|
|
|
/* |
|
27
|
|
|
* @Class TDMCreateMoreFiles |
|
28
|
|
|
* @extends XoopsObject |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class TDMCreateMoreFiles. |
|
33
|
|
|
*/ |
|
34
|
|
|
class TDMCreateMoreFiles extends XoopsObject |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Settings. |
|
38
|
|
|
* |
|
39
|
|
|
* @var mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
private $settings; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @public function constructor class |
|
45
|
|
|
* |
|
46
|
|
|
* @param null |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->initVar('file_id', XOBJ_DTYPE_INT); |
|
|
|
|
|
|
51
|
|
|
$this->initVar('file_mid', XOBJ_DTYPE_INT); |
|
|
|
|
|
|
52
|
|
|
$this->initVar('file_name', XOBJ_DTYPE_TXTBOX); |
|
|
|
|
|
|
53
|
|
|
$this->initVar('file_extension', XOBJ_DTYPE_TXTBOX); |
|
|
|
|
|
|
54
|
|
|
$this->initVar('file_infolder', XOBJ_DTYPE_TXTBOX); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $method |
|
59
|
|
|
* @param array $args |
|
60
|
|
|
* |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __call($method, $args) |
|
64
|
|
|
{ |
|
65
|
|
|
$arg = isset($args[0]) ? $args[0] : null; |
|
66
|
|
|
|
|
67
|
|
|
return $this->getVar($method, $arg); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @static function getInstance |
|
72
|
|
|
* |
|
73
|
|
|
* @param null |
|
74
|
|
|
* |
|
75
|
|
|
* @return TDMCreateMoreFiles |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function getInstance() |
|
78
|
|
|
{ |
|
79
|
|
|
static $instance = false; |
|
80
|
|
|
if (!$instance) { |
|
81
|
|
|
$instance = new self(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $instance; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @public function getFormMoreFiles |
|
89
|
|
|
* |
|
90
|
|
|
* @param mixed $action |
|
91
|
|
|
* @param bool $action |
|
92
|
|
|
* |
|
93
|
|
|
* @return XoopsThemeForm |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getFormMoreFiles($action = false) |
|
96
|
|
|
{ |
|
97
|
|
|
$tdmcreate = TDMCreateHelper::getInstance(); |
|
98
|
|
|
if ($action === false) { |
|
99
|
|
|
$action = $_SERVER['REQUEST_URI']; |
|
100
|
|
|
} |
|
101
|
|
|
// |
|
102
|
|
|
$isNew = $this->isNew(); |
|
|
|
|
|
|
103
|
|
|
$title = $isNew ? sprintf(_AM_TDMCREATE_MORE_FILES_NEW) : sprintf(_AM_TDMCREATE_MORE_FILES_EDIT); |
|
104
|
|
|
// |
|
105
|
|
|
xoops_load('XoopsFormLoader'); |
|
106
|
|
|
// |
|
107
|
|
|
$form = new XoopsThemeForm($title, 'morefilesform', $action, 'post', true); |
|
108
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
|
109
|
|
|
// |
|
110
|
|
|
$modules = $tdmcreate->getHandler('modules')->getObjects(null); |
|
|
|
|
|
|
111
|
|
|
$modulesSelect = new XoopsFormSelect(_AM_TDMCREATE_MORE_FILES_MODULES, 'file_mid', $this->getVar('file_mid')); |
|
|
|
|
|
|
112
|
|
|
$modulesSelect->addOption('', _AM_TDMCREATE_MORE_FILES_MODULE_SELECT); |
|
113
|
|
|
foreach ($modules as $mod) { |
|
114
|
|
|
//$modulesSelect->addOptionArray(); |
|
|
|
|
|
|
115
|
|
|
$modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name')); |
|
116
|
|
|
} |
|
117
|
|
|
$form->addElement($modulesSelect, true); |
|
118
|
|
|
// |
|
119
|
|
|
$modName = new XoopsFormText(_AM_TDMCREATE_MORE_FILES_NAME, 'file_name', 50, 255, $this->getVar('file_name')); |
|
|
|
|
|
|
120
|
|
|
$modName->setDescription(_AM_TDMCREATE_MORE_FILES_NAME_DESC); |
|
121
|
|
|
$form->addElement($modName, true); |
|
122
|
|
|
// |
|
123
|
|
|
$fileEstension = new XoopsFormText(_AM_TDMCREATE_MORE_FILES_EXTENSION, 'file_extension', 50, 255, $this->getVar('file_extension')); |
|
|
|
|
|
|
124
|
|
|
$fileEstension->setDescription(_AM_TDMCREATE_MORE_FILES_EXTENSION_DESC); |
|
125
|
|
|
$form->addElement($fileEstension, true); |
|
126
|
|
|
// |
|
127
|
|
|
$fileInfolder = new XoopsFormText(_AM_TDMCREATE_MORE_FILES_INFOLDER, 'file_infolder', 50, 255, $this->getVar('file_infolder')); |
|
|
|
|
|
|
128
|
|
|
$fileInfolder->setDescription(_AM_TDMCREATE_MORE_FILES_INFOLDER_DESC); |
|
129
|
|
|
$form->addElement($fileInfolder, true); |
|
130
|
|
|
// |
|
131
|
|
|
$form->addElement(new XoopsFormHidden('op', 'save')); |
|
132
|
|
|
$form->addElement(new XoopsFormButton(_REQUIRED.' <sup class="red bold">*</sup>', 'submit', _SUBMIT, 'submit')); |
|
133
|
|
|
|
|
134
|
|
|
return $form; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Get Values. |
|
139
|
|
|
* |
|
140
|
|
|
* @param null $keys |
|
141
|
|
|
* @param null $format |
|
142
|
|
|
* @param null $maxDepth |
|
143
|
|
|
* |
|
144
|
|
|
* @return array |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getValuesMoreFiles($keys = null, $format = null, $maxDepth = null) |
|
147
|
|
|
{ |
|
148
|
|
|
$tdmcreate = TDMCreateHelper::getInstance(); |
|
149
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
|
|
|
|
|
|
150
|
|
|
// Values |
|
151
|
|
|
$ret['id'] = $this->getVar('file_id'); |
|
|
|
|
|
|
152
|
|
|
$ret['mid'] = $tdmcreate->getHandler('modules')->get($this->getVar('file_mid'))->getVar('mod_name'); |
|
|
|
|
|
|
153
|
|
|
$ret['name'] = $this->getVar('file_name'); |
|
|
|
|
|
|
154
|
|
|
$ret['extension'] = $this->getVar('file_extension'); |
|
|
|
|
|
|
155
|
|
|
$ret['infolder'] = $this->getVar('file_infolder'); |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
return $ret; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @Class TDMCreateMoreFilesHandler |
|
163
|
|
|
* @extends XoopsPersistableObjectHandler |
|
164
|
|
|
*/ |
|
165
|
|
|
class TDMCreateMoreFilesHandler extends XoopsPersistableObjectHandler |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
/** |
|
168
|
|
|
* @public function constructor class |
|
169
|
|
|
* |
|
170
|
|
|
* @param null|object $db |
|
171
|
|
|
*/ |
|
172
|
|
|
public function __construct(&$db) |
|
173
|
|
|
{ |
|
174
|
|
|
parent::__construct($db, 'tdmcreate_morefiles', 'tdmcreatemorefiles', 'file_id', 'file_name'); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param bool $isNew |
|
179
|
|
|
* |
|
180
|
|
|
* @return object |
|
181
|
|
|
*/ |
|
182
|
|
|
public function create($isNew = true) |
|
183
|
|
|
{ |
|
184
|
|
|
return parent::create($isNew); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* retrieve a field. |
|
189
|
|
|
* |
|
190
|
|
|
* @param int $i field id |
|
191
|
|
|
* @param null $fields |
|
192
|
|
|
* |
|
193
|
|
|
* @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object |
|
194
|
|
|
* object |
|
195
|
|
|
*/ |
|
196
|
|
|
public function get($i = null, $fields = null) |
|
197
|
|
|
{ |
|
198
|
|
|
return parent::get($i, $fields); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* get inserted id. |
|
203
|
|
|
* |
|
204
|
|
|
* @param null |
|
205
|
|
|
* |
|
206
|
|
|
* @return int reference to the {@link TDMCreateTables} object |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getInsertId() |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->db->getInsertId(); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Get Count MoreFiles. |
|
215
|
|
|
* |
|
216
|
|
|
* @param int $start |
|
217
|
|
|
* @param int $limit |
|
218
|
|
|
* @param string $sort |
|
219
|
|
|
* @param string $order |
|
220
|
|
|
* |
|
221
|
|
|
* @return int |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getCountMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC') |
|
224
|
|
|
{ |
|
225
|
|
|
$crMoreFilesCount = new CriteriaCompo(); |
|
226
|
|
|
$crMoreFilesCount = $this->getMoreFilesCriteria($crMoreFilesCount, $start, $limit, $sort, $order); |
|
227
|
|
|
|
|
228
|
|
|
return $this->getCount($crMoreFilesCount); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Get All MoreFiles. |
|
233
|
|
|
* |
|
234
|
|
|
* @param int $start |
|
235
|
|
|
* @param int $limit |
|
236
|
|
|
* @param string $sort |
|
237
|
|
|
* @param string $order |
|
238
|
|
|
* |
|
239
|
|
|
* @return array |
|
240
|
|
|
*/ |
|
241
|
|
|
public function getAllMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC') |
|
242
|
|
|
{ |
|
243
|
|
|
$crMoreFilesAdd = new CriteriaCompo(); |
|
244
|
|
|
$crMoreFilesAdd = $this->getMoreFilesCriteria($crMoreFilesAdd, $start, $limit, $sort, $order); |
|
245
|
|
|
|
|
246
|
|
|
return $this->getAll($crMoreFilesAdd); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Get All MoreFiles By Module Id. |
|
251
|
|
|
* |
|
252
|
|
|
* @param $modId |
|
253
|
|
|
* @param int $start |
|
254
|
|
|
* @param int $limit |
|
255
|
|
|
* @param string $sort |
|
256
|
|
|
* @param string $order |
|
257
|
|
|
* |
|
258
|
|
|
* @return array |
|
259
|
|
|
*/ |
|
260
|
|
|
public function getAllMoreFilesByModuleId($modId, $start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC') |
|
261
|
|
|
{ |
|
262
|
|
|
$crMoreFilesByModuleId = new CriteriaCompo(); |
|
263
|
|
|
$crMoreFilesByModuleId->add(new Criteria('file_mid', $modId)); |
|
264
|
|
|
$crMoreFilesByModuleId = $this->getMoreFilesCriteria($crMoreFilesByModuleId, $start, $limit, $sort, $order); |
|
265
|
|
|
|
|
266
|
|
|
return $this->getAll($crMoreFilesByModuleId); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Get MoreFiles Criteria. |
|
271
|
|
|
* |
|
272
|
|
|
* @param $crMoreFiles |
|
273
|
|
|
* @param $start |
|
274
|
|
|
* @param $limit |
|
275
|
|
|
* @param $sort |
|
276
|
|
|
* @param $order |
|
277
|
|
|
* |
|
278
|
|
|
* @return |
|
279
|
|
|
*/ |
|
280
|
|
|
private function getMoreFilesCriteria($crMoreFiles, $start, $limit, $sort, $order) |
|
281
|
|
|
{ |
|
282
|
|
|
$crMoreFiles->setStart($start); |
|
283
|
|
|
$crMoreFiles->setLimit($limit); |
|
284
|
|
|
$crMoreFiles->setSort($sort); |
|
285
|
|
|
$crMoreFiles->setOrder($order); |
|
286
|
|
|
|
|
287
|
|
|
return $crMoreFiles; |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.