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