1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\Classes; |
4
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
7
|
|
|
|
8
|
|
|
/* |
9
|
|
|
You may not change or alter any portion of this comment or credits |
10
|
|
|
of supporting developers from this source code or any supporting source code |
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
12
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* tc module. |
19
|
|
|
* |
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
21
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
22
|
|
|
* |
23
|
|
|
* @since 2.5.0 |
24
|
|
|
* |
25
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class ClassFiles. |
31
|
|
|
*/ |
32
|
|
|
class ClassFiles extends Files\CreateFile |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var mixed |
37
|
|
|
*/ |
38
|
|
|
private $cxc = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $xc = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $pc = null; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $helper = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @public function constructor |
57
|
|
|
* @param null |
58
|
|
|
*/ |
59
|
|
|
public function __construct() |
60
|
|
|
{ |
61
|
|
|
parent::__construct(); |
62
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
|
|
|
|
63
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
|
|
|
|
64
|
|
|
$this->cxc = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance(); |
65
|
|
|
$this->helper = Modulebuilder\Helper::getInstance(); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @static function getInstance |
70
|
|
|
* |
71
|
|
|
* @param null |
72
|
|
|
* |
73
|
|
|
* @return ClassFiles |
74
|
|
|
*/ |
75
|
|
|
public static function getInstance() |
76
|
|
|
{ |
77
|
|
|
static $instance = false; |
78
|
|
|
if (!$instance) { |
79
|
|
|
$instance = new self(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $instance; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @public function write |
87
|
|
|
* |
88
|
|
|
* @param string $module |
89
|
|
|
* @param string $table |
90
|
|
|
* @param mixed $tables |
91
|
|
|
* @param $filename |
92
|
|
|
*/ |
93
|
|
|
public function write($module, $table, $tables, $filename) |
94
|
|
|
{ |
95
|
|
|
$this->setModule($module); |
96
|
|
|
$this->setTable($table); |
97
|
|
|
$this->setTables($tables); |
98
|
|
|
$this->setFileName($filename); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @private function getInitVar |
103
|
|
|
* |
104
|
|
|
* @param string $fieldName |
105
|
|
|
* @param string $type |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
private function getInitVar($fieldName, $type = 'INT') |
110
|
|
|
{ |
111
|
|
|
|
112
|
|
|
return $this->cxc->getClassInitVar($fieldName, $type); |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @private function getInitVars |
118
|
|
|
* |
119
|
|
|
* @param array $fields |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
private function getInitVars($fields) |
124
|
|
|
{ |
125
|
|
|
$ret = ''; |
126
|
|
|
// Creation of the initVar functions list |
127
|
|
|
foreach (array_keys($fields) as $f) { |
128
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
129
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
130
|
|
|
switch ($fieldType) { |
131
|
|
|
case 2: |
132
|
|
|
case 3: |
133
|
|
|
case 4: |
134
|
|
|
case 5: |
135
|
|
|
$ret .= $this->getInitVar($fieldName, 'INT'); |
136
|
|
|
break; |
137
|
|
|
case 6: |
138
|
|
|
$ret .= $this->getInitVar($fieldName, 'FLOAT'); |
139
|
|
|
break; |
140
|
|
|
case 7: |
141
|
|
|
case 8: |
142
|
|
|
$ret .= $this->getInitVar($fieldName, 'DECIMAL'); |
143
|
|
|
break; |
144
|
|
|
case 10: |
145
|
|
|
$ret .= $this->getInitVar($fieldName, 'ENUM'); |
146
|
|
|
break; |
147
|
|
|
case 11: |
148
|
|
|
$ret .= $this->getInitVar($fieldName, 'EMAIL'); |
149
|
|
|
break; |
150
|
|
|
case 12: |
151
|
|
|
$ret .= $this->getInitVar($fieldName, 'URL'); |
152
|
|
|
break; |
153
|
|
|
case 13: |
154
|
|
|
case 14: |
155
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTBOX'); |
156
|
|
|
break; |
157
|
|
|
case 15: |
158
|
|
|
case 16: |
159
|
|
|
case 17: |
160
|
|
|
case 18: |
161
|
|
|
if ((int)$fields[$f]->getVar('field_element') == 4) { |
162
|
|
|
$ret .= $this->getInitVar($fieldName, 'OTHER'); |
163
|
|
|
} else { |
164
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTAREA'); |
165
|
|
|
} |
166
|
|
|
break; |
167
|
|
|
case 19: |
168
|
|
|
case 20: |
169
|
|
|
case 21: |
170
|
|
|
case 22: |
171
|
|
|
case 23: |
172
|
|
|
$ret .= $this->getInitVar($fieldName, 'LTIME'); |
173
|
|
|
break; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $ret; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @private function getClassObject |
182
|
|
|
* @param $module |
183
|
|
|
* @param $table |
184
|
|
|
* @param $fields |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
private function getClassObject($module, $table, $fields) |
188
|
|
|
{ |
189
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
190
|
|
|
$tableName = $table->getVar('table_name'); |
191
|
|
|
$ucfTableName = ucfirst($tableName); |
192
|
|
|
$ret = $this->pc->getPhpCodeDefined(); |
193
|
|
|
$ret .= $this->pc->getPhpCodeCommentMultiLine(['Class Object' => $ucfTableName]); |
194
|
|
|
$cCl = ''; |
195
|
|
|
|
196
|
|
|
$fieldInForm = []; |
197
|
|
|
$fieldElementId = []; |
198
|
|
|
$optionsFieldName = []; |
199
|
|
|
$fieldId = null; |
200
|
|
|
foreach (array_keys($fields) as $f) { |
201
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
202
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
203
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
204
|
|
|
$fieldElements = $this->helper->getHandler('Fieldelements')->get($fieldElement); |
205
|
|
|
$fieldElementId[] = $fieldElements->getVar('fieldelement_id'); |
206
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
207
|
|
|
if (in_array(5, $fieldElementId)) { |
208
|
|
|
//if (count($rpFieldName) % 5) { |
209
|
|
|
//$optionsFieldName[] = "'" . $rpFieldName . "'"; |
210
|
|
|
//} else { |
211
|
|
|
$optionsFieldName[] = "'" . $rpFieldName . "'\n"; |
212
|
|
|
//} |
213
|
|
|
} |
214
|
|
|
if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) { |
215
|
|
|
$fieldId = $fieldName; |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
219
|
|
|
$cCl .= $this->pc->getPhpCodeCommentMultiLine(['Options' => '']); |
220
|
|
|
$options = $this->pc->getPhpCodeArray('', $optionsFieldName, true); |
221
|
|
|
$cCl .= $this->pc->getPhpCodeVariableClass('private', 'options', $options); |
222
|
|
|
} |
223
|
|
|
unset($optionsFieldName); |
224
|
|
|
|
225
|
|
|
$cCl .= $this->pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t"); |
226
|
|
|
$constr = $this->getInitVars($fields); |
227
|
|
|
$cCl .= $this->pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t"); |
228
|
|
|
$arrayGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null']; |
229
|
|
|
$cCl .= $this->pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t"); |
230
|
|
|
$getInstance = $this->pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t"); |
231
|
|
|
$instance = $this->xc->getXcEqualsOperator('$instance', 'new self()', null, "\t\t\t"); |
232
|
|
|
$getInstance .= $this->pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t"); |
233
|
|
|
$cCl .= $this->pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t"); |
234
|
|
|
|
235
|
|
|
$cCl .= $this->getNewInsertId($table); |
236
|
|
|
$cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm); |
237
|
|
|
$cCl .= $this->getValuesInObject($moduleDirname, $table, $fields); |
238
|
|
|
$cCl .= $this->getToArrayInObject($table); |
239
|
|
|
|
240
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
241
|
|
|
$cCl .= $this->getOptionsCheck($table); |
242
|
|
|
} |
243
|
|
|
unset($fieldElementId); |
244
|
|
|
|
245
|
|
|
$ret .= $this->pc->getPhpCodeClass($ucfTableName, $cCl, '\XoopsObject'); |
246
|
|
|
|
247
|
|
|
return $ret; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @private function getNewInsertId |
252
|
|
|
* |
253
|
|
|
* @param $table |
254
|
|
|
* |
255
|
|
|
* @return string |
256
|
|
|
*/ |
257
|
|
|
private function getNewInsertId($table) |
258
|
|
|
{ |
259
|
|
|
$tableName = $table->getVar('table_name'); |
260
|
|
|
$ucfTableName = ucfirst($tableName); |
261
|
|
|
$ret = $this->pc->getPhpCodeCommentMultiLine(['The new inserted' => '$Id', '@return' => 'inserted id'], "\t"); |
262
|
|
|
$getInsertedId = $this->xc->getXcEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, "\t\t"); |
263
|
|
|
$getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t"); |
264
|
|
|
|
265
|
|
|
$ret .= $this->pc->getPhpCodeFunction('getNewInsertedId' . $ucfTableName, '', $getInsertedId, 'public ', false, "\t"); |
266
|
|
|
|
267
|
|
|
return $ret; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @private function getFunctionForm |
272
|
|
|
* |
273
|
|
|
* @param string $module |
274
|
|
|
* @param string $table |
275
|
|
|
* |
276
|
|
|
* @param $fieldId |
277
|
|
|
* @param $fieldInForm |
278
|
|
|
* @return string |
279
|
|
|
*/ |
280
|
|
|
private function getFunctionForm($module, $table, $fieldId, $fieldInForm) |
281
|
|
|
{ |
282
|
|
|
$fe = ClassFormElements::getInstance(); |
283
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
284
|
|
|
$tableName = $table->getVar('table_name'); |
285
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
286
|
|
|
$tableCategory = $table->getVar('table_category'); |
287
|
|
|
$ucfTableName = ucfirst($tableName); |
288
|
|
|
$stuTableSoleName = mb_strtoupper($tableSoleName); |
289
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
290
|
|
|
$fe->initForm($module, $table); |
291
|
|
|
$ret = $this->pc->getPhpCodeCommentMultiLine(['@public function' => 'getForm', '@param bool' => '$action', '@return' => '\XoopsThemeForm'], "\t"); |
292
|
|
|
$action = $this->xc->getXcEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, "\t\t\t"); |
293
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
294
|
|
|
$getForm = $this->xc->getXcGetInstance('helper', "\XoopsModules\\{$ucfModuleDirname}\Helper", "\t\t"); |
295
|
|
|
$getForm .= $this->pc->getPhpCodeConditions('$action', ' === ', 'false', $action, false, "\t\t"); |
296
|
|
|
$xUser = $this->pc->getPhpCodeGlobals('xoopsUser'); |
297
|
|
|
$xModule = $this->pc->getPhpCodeGlobals('xoopsModule'); |
298
|
|
|
$getForm .= $this->xc->getXcEqualsOperator('$isAdmin', $xUser . '->isAdmin(' . $xModule . '->mid())', null, "\t\t"); |
299
|
|
|
$permString = 'upload_groups'; |
300
|
|
|
if (1 != $tableCategory/* && (1 == $tablePermissions)*/) { |
301
|
|
|
$getForm .= $this->pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t"); |
302
|
|
|
$getForm .= $this->xc->getXcXoopsHandler('groupperm', "\t\t"); |
303
|
|
|
$getForm .= $this->pc->getPhpCodeTernaryOperator('groups', 'is_object(' . $xUser . ')', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t"); |
304
|
|
|
$checkRight = $this->xc->getXcCheckRight('$grouppermHandler', $permString, 32, '$groups', $xModule . '->getVar(\'mid\')', true); |
305
|
|
|
$getForm .= $this->pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t"); |
306
|
|
|
} |
307
|
|
|
$getForm .= $this->pc->getPhpCodeCommentLine('Title', '', "\t\t"); |
308
|
|
|
$getForm .= $this->pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "sprintf({$language}{$stuTableSoleName}_ADD)", "sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t"); |
309
|
|
|
$getForm .= $this->pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t"); |
310
|
|
|
$getForm .= $this->xc->getXcXoopsLoad('XoopsFormLoader', "\t\t"); |
311
|
|
|
$getForm .= $this->cxc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post'); |
312
|
|
|
$getForm .= $this->cxc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'"); |
313
|
|
|
$getForm .= $fe->renderElements(); |
314
|
|
|
|
315
|
|
|
if (in_array(1, $fieldInForm)) { |
316
|
|
|
if (1 == $table->getVar('table_permissions')) { |
317
|
|
|
$getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId, $tableName); |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
$getForm .= $this->pc->getPhpCodeCommentLine('To Save', '', "\t\t"); |
321
|
|
|
//$hiddenSave = $cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false); |
322
|
|
|
$getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormHidden('op', 'save')"); |
323
|
|
|
$getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)"); |
324
|
|
|
$getForm .= $this->getSimpleString('return $form;', "\t\t"); |
325
|
|
|
|
326
|
|
|
$ret .= $this->pc->getPhpCodeFunction('getForm' . $ucfTableName, '$action = false', $getForm, 'public ', false, "\t"); |
327
|
|
|
|
328
|
|
|
return $ret; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @private function getPermissionsInForm |
333
|
|
|
* |
334
|
|
|
* @param string $moduleDirname |
335
|
|
|
* @param string $fieldId |
336
|
|
|
* |
337
|
|
|
* @param $tableName |
338
|
|
|
* @return string |
339
|
|
|
*/ |
340
|
|
|
private function getPermissionsInForm($moduleDirname, $fieldId, $tableName) |
341
|
|
|
{ |
342
|
|
|
$permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE'); |
343
|
|
|
$permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT'); |
344
|
|
|
$permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW'); |
345
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Permissions', '', "\t\t"); |
346
|
|
|
$ret .= $this->xc->getXcXoopsHandler('member', "\t\t"); |
347
|
|
|
$ret .= $this->xc->getXcEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, "\t\t"); |
348
|
|
|
$ret .= $this->xc->getXcXoopsHandler('groupperm', "\t\t"); |
349
|
|
|
$ret .= $this->pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t"); |
350
|
|
|
$fId = $this->xc->getXcGetVar('', 'this', $fieldId, true); |
351
|
|
|
$mId = $this->xc->getXcGetVar('', "GLOBALS['xoopsModule']", 'mid', true); |
352
|
|
|
$ifGroups = $this->xc->getXcGetGroupIds('groupsIdsApprove', 'grouppermHandler', "'{$moduleDirname}_approve_{$tableName}'", $fId, $mId, "\t\t\t"); |
353
|
|
|
$ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t"); |
354
|
|
|
$ifGroups .= $this->cxc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, "groups_approve_{$tableName}[]", '$groupsIdsApprove', false, "\t\t\t"); |
355
|
|
|
$ifGroups .= $this->xc->getXcGetGroupIds('groupsIdsSubmit', 'grouppermHandler', "'{$moduleDirname}_submit_{$tableName}'", $fId, $mId, "\t\t\t"); |
356
|
|
|
$ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t"); |
357
|
|
|
$ifGroups .= $this->cxc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, "groups_submit_{$tableName}[]", '$groupsIdsSubmit', false, "\t\t\t"); |
358
|
|
|
$ifGroups .= $this->xc->getXcGetGroupIds('groupsIdsView', 'grouppermHandler', "'{$moduleDirname}_view_{$tableName}'", $fId, $mId, "\t\t\t"); |
359
|
|
|
$ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t"); |
360
|
|
|
$ifGroups .= $this->cxc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, "groups_view_{$tableName}[]", '$groupsIdsView', false, "\t\t\t"); |
361
|
|
|
|
362
|
|
|
$else = $this->cxc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, "groups_approve_{$tableName}[]", '$fullList', false, "\t\t\t"); |
363
|
|
|
$else .= $this->cxc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, "groups_submit_{$tableName}[]", '$fullList', false, "\t\t\t"); |
364
|
|
|
$else .= $this->cxc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, "groups_view_{$tableName}[]", '$fullList', false, "\t\t\t"); |
365
|
|
|
|
366
|
|
|
$ret .= $this->pc->getPhpCodeConditions('!$this->isNew()', null, null, $ifGroups, $else, "\t\t"); |
367
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('To Approve', '', "\t\t"); |
368
|
|
|
$ret .= $this->cxc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList'); |
369
|
|
|
$ret .= $this->cxc->getClassAddElement('form', '$groupsCanApproveCheckbox'); |
370
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('To Submit', '', "\t\t"); |
371
|
|
|
$ret .= $this->cxc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList'); |
372
|
|
|
$ret .= $this->cxc->getClassAddElement('form', '$groupsCanSubmitCheckbox'); |
373
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('To View', '', "\t\t"); |
374
|
|
|
$ret .= $this->cxc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList'); |
375
|
|
|
$ret .= $this->cxc->getClassAddElement('form', '$groupsCanViewCheckbox'); |
376
|
|
|
|
377
|
|
|
return $ret; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @private function getValuesInObject |
382
|
|
|
* |
383
|
|
|
* @param $moduleDirname |
384
|
|
|
* @param $table |
385
|
|
|
* @param $fields |
386
|
|
|
* @return string |
387
|
|
|
* @internal param $null |
388
|
|
|
*/ |
389
|
|
|
private function getValuesInObject($moduleDirname, $table, $fields) |
390
|
|
|
{ |
391
|
|
|
$tc = Modulebuilder\Helper::getInstance(); |
|
|
|
|
392
|
|
|
$ucfTableName = ucfirst($table->getVar('table_name')); |
393
|
|
|
$ret = $this->pc->getPhpCodeCommentMultiLine(['Get' => 'Values', '@param null $keys' => '', '@param null $format' => '', '@param null$maxDepth' => '', '@return' => 'array'], "\t"); |
394
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
395
|
|
|
$getValues = $this->xc->getXcEqualsOperator('$ret', '$this->getValues($keys, $format, $maxDepth)', null, "\t\t"); |
396
|
|
|
$fieldMainTopic = null; |
397
|
|
|
$helper = 0; |
398
|
|
|
$utility = 0; |
399
|
|
|
$header = ''; |
400
|
|
|
$configMaxchar = 0; |
401
|
|
|
$lenMaxName = 0; |
402
|
|
|
foreach (array_keys($fields) as $f) { |
403
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
404
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
405
|
|
|
$len = strlen($rpFieldName); |
406
|
|
|
if (3 == $fields[$f]->getVar('field_element') || 4 == $fields[$f]->getVar('field_element')) { |
407
|
|
|
$len = $len + strlen('_short'); |
408
|
|
|
} |
409
|
|
|
$lenMaxName = max($len, $lenMaxName); |
410
|
|
|
} |
411
|
|
|
foreach (array_keys($fields) as $f) { |
412
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
413
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
414
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
415
|
|
|
$spacer = str_repeat(' ', $lenMaxName - strlen($rpFieldName)); |
416
|
|
|
switch ($fieldElement) { |
417
|
|
|
case 3: |
418
|
|
|
$getValues .= $this->pc->getPhpCodeStripTags("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}', 'e')", false, "\t\t"); |
419
|
|
|
if ($configMaxchar == 0) { |
420
|
|
|
$getValues .= $this->xc->getXcEqualsOperator('$editorMaxchar', $this->xc->getXcGetConfig('editor_maxchar'), false, "\t\t"); |
421
|
|
|
$configMaxchar = 1; |
422
|
|
|
} |
423
|
|
|
$truncate = "\$utility::truncateHtml(\$ret['{$rpFieldName}'], \$editorMaxchar)"; |
424
|
|
|
$spacer = str_repeat(' ', $lenMaxName - strlen($rpFieldName) - strlen('_short')); |
425
|
|
|
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_short']{$spacer}", $truncate, false, "\t\t"); |
426
|
|
|
$helper = 1; |
427
|
|
|
$utility = 1; |
428
|
|
|
break; |
429
|
|
|
case 4: |
430
|
|
|
$getValues .= $this->xc->getXcGetVar("ret['{$rpFieldName}']{$spacer}", 'this', $fieldName, false, "\t\t", ", 'e'"); |
431
|
|
|
if ($configMaxchar == 0) { |
432
|
|
|
$getValues .= $this->xc->getXcEqualsOperator('$editorMaxchar', $this->xc->getXcGetConfig('editor_maxchar'), false, "\t\t"); |
433
|
|
|
$configMaxchar = 1; |
434
|
|
|
} |
435
|
|
|
$truncate = "\$utility::truncateHtml(\$ret['{$rpFieldName}'], \$editorMaxchar)"; |
436
|
|
|
$spacer = str_repeat(' ', $lenMaxName - strlen($rpFieldName) - strlen('_short')); |
437
|
|
|
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_short']{$spacer}", $truncate, false, "\t\t"); |
438
|
|
|
$helper = 1; |
439
|
|
|
$utility = 1; |
440
|
|
|
break; |
441
|
|
|
case 6: |
442
|
|
|
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}']{$spacer}", "(int)\$this->getVar('{$fieldName}') > 0 ? _YES : _NO", false, "\t\t"); |
443
|
|
|
break; |
444
|
|
|
case 8: |
445
|
|
|
$getValues .= $this->xc->getXcXoopsUserUnameFromId("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", "\t\t"); |
446
|
|
|
break; |
447
|
|
|
case 15: |
448
|
|
|
$getValues .= $this->xc->getXcFormatTimeStamp("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", 's', "\t\t"); |
449
|
|
|
break; |
450
|
|
|
case 21: |
451
|
|
|
$getValues .= $this->xc->getXcFormatTimeStamp("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", 'm', "\t\t"); |
452
|
|
|
break; |
453
|
|
|
default: |
454
|
|
|
$fieldElements = $this->helper->getHandler('Fieldelements')->get($fieldElement); |
455
|
|
|
$fieldElementTid = $fieldElements->getVar('fieldelement_tid'); |
456
|
|
|
if ((int)$fieldElementTid > 0 ) { |
457
|
|
|
$fieldElementMid = $fieldElements->getVar('fieldelement_mid'); |
458
|
|
|
$fieldElementName = (string)$fieldElements->getVar('fieldelement_name'); |
459
|
|
|
$fieldNameDesc = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)); |
460
|
|
|
$topicTableName = str_replace(': ', '', mb_strtolower($fieldNameDesc)); |
461
|
|
|
$fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid); |
462
|
|
|
foreach (array_keys($fieldsTopics) as $g) { |
463
|
|
|
$fieldNameTopic = $fieldsTopics[$g]->getVar('field_name'); |
464
|
|
|
if (1 == $fieldsTopics[$g]->getVar('field_main')) { |
465
|
|
|
$fieldMainTopic = $fieldNameTopic; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
$getValues .= $this->xc->getXcHandlerLine($topicTableName, "\t\t"); |
469
|
|
|
$getTopicTable = "\${$topicTableName}Handler->get(\$this->getVar('{$fieldName}'))"; |
470
|
|
|
$getValues .= $this->xc->getXcEqualsOperator("\${$topicTableName}Obj", $getTopicTable, null, "\t\t"); |
471
|
|
|
$fMainTopic = "\${$topicTableName}Obj->getVar('{$fieldMainTopic}')"; |
472
|
|
|
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}']{$spacer}", $fMainTopic, null, "\t\t"); |
473
|
|
|
$helper = 1; |
474
|
|
|
} else { |
475
|
|
|
$getValues .= $this->xc->getXcGetVar("ret['{$rpFieldName}']{$spacer}", 'this', $fieldName, false, "\t\t"); |
476
|
|
|
} |
477
|
|
|
break; |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
if ($helper > 0) { |
481
|
|
|
$header .= $this->xc->getXcGetInstance('helper ', "\XoopsModules\\{$ucfModuleDirname}\Helper", "\t\t"); |
482
|
|
|
} |
483
|
|
|
if ($utility > 0) { |
484
|
|
|
$header .= $this->xc->getXcEqualsOperator('$utility', "new \XoopsModules\\{$ucfModuleDirname}\Utility()", '',"\t\t"); |
485
|
|
|
} |
486
|
|
|
$getValues .= $this->getSimpleString('return $ret;', "\t\t"); |
487
|
|
|
|
488
|
|
|
$ret .= $this->pc->getPhpCodeFunction('getValues' . $ucfTableName, '$keys = null, $format = null, $maxDepth = null', $header . $getValues, 'public ', false, "\t"); |
489
|
|
|
|
490
|
|
|
return $ret; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* @private function getToArrayInObject |
495
|
|
|
* |
496
|
|
|
* @param $table |
497
|
|
|
* |
498
|
|
|
* @return string |
499
|
|
|
*/ |
500
|
|
|
private function getToArrayInObject($table) |
501
|
|
|
{ |
502
|
|
|
$tableName = $table->getVar('table_name'); |
503
|
|
|
$ucfTableName = ucfirst($tableName); |
504
|
|
|
$multiLineCom = ['Returns an array representation' => 'of the object', '' => '', '@return' => 'array']; |
505
|
|
|
$ret = $this->pc->getPhpCodeCommentMultiLine($multiLineCom, "\t"); |
506
|
|
|
|
507
|
|
|
$getToArray = $this->pc->getPhpCodeArray('ret', [], false, "\t\t"); |
508
|
|
|
$getToArray .= $this->xc->getXcEqualsOperator('$vars', '$this->getVars()', null, "\t\t"); |
509
|
|
|
$foreach = $this->xc->getXcGetVar('ret[$var]', 'this', '"{$var}"', false, "\t\t\t"); |
510
|
|
|
$getToArray .= $this->pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t"); |
511
|
|
|
$getToArray .= $this->getSimpleString('return $ret;', "\t\t"); |
512
|
|
|
|
513
|
|
|
$ret .= $this->pc->getPhpCodeFunction('toArray' . $ucfTableName, '', $getToArray, 'public ', false, "\t"); |
514
|
|
|
|
515
|
|
|
return $ret; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* @private function getOptionsCheck |
520
|
|
|
* |
521
|
|
|
* @param $table |
522
|
|
|
* |
523
|
|
|
* @return string |
524
|
|
|
*/ |
525
|
|
|
private function getOptionsCheck($table) |
526
|
|
|
{ |
527
|
|
|
$tableName = $table->getVar('table_name'); |
528
|
|
|
$ucfTableName = ucfirst($tableName); |
529
|
|
|
$ret = $this->pc->getPhpCodeCommentMultiLine(['Get' => 'Options'], "\t"); |
530
|
|
|
$getOptions = $this->pc->getPhpCodeArray('ret', [], false, "\t"); |
531
|
|
|
|
532
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
533
|
|
|
foreach (array_keys($fields) as $f) { |
534
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
535
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
536
|
|
|
|
537
|
|
|
$fieldElements = $this->helper->getHandler('Fieldelements')->get($fieldElement); |
538
|
|
|
$fieldElementId = $fieldElements->getVar('fieldelement_id'); |
539
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
540
|
|
|
if (5 == $fieldElementId) { |
541
|
|
|
$arrayPush = $this->pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t"); |
542
|
|
|
$getOptions .= $this->pc->getPhpCodeConditions("\$this->getVar('{$fieldName}')", ' == ', '1', $arrayPush, false, "\t\t"); |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
$getOptions .= $this->getSimpleString('return $ret;', "\t\t"); |
547
|
|
|
|
548
|
|
|
$ret .= $this->pc->getPhpCodeFunction('getOptions' . $ucfTableName, '', $getOptions, 'public ', false, "\t"); |
549
|
|
|
|
550
|
|
|
return $ret; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* @public function render |
555
|
|
|
* @param null |
556
|
|
|
* |
557
|
|
|
* @return bool|string |
558
|
|
|
*/ |
559
|
|
|
public function render() |
560
|
|
|
{ |
561
|
|
|
$module = $this->getModule(); |
562
|
|
|
$table = $this->getTable(); |
563
|
|
|
$filename = $this->getFileName(); |
564
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
565
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
566
|
|
|
|
567
|
|
|
$namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]); |
568
|
|
|
$content = $this->getHeaderFilesComments($module, null, $namespace); |
569
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname]); |
570
|
|
|
$content .= $this->getClassObject($module, $table, $fields); |
571
|
|
|
|
572
|
|
|
$this->create($moduleDirname, 'class', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
573
|
|
|
|
574
|
|
|
return $this->renderFile(); |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..