|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Tdmcreate\Files\Classes; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Tdmcreate; |
|
6
|
|
|
use XoopsModules\Tdmcreate\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
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
88
|
|
|
|
|
89
|
|
|
return $cc->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
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
102
|
|
|
$ret = ''; |
|
103
|
|
|
// Creation of the initVar functions list |
|
104
|
|
|
foreach (array_keys($fields) as $f) { |
|
105
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
106
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
|
107
|
|
|
if ($fieldType > 1) { |
|
108
|
|
|
$fType = $tc->getHandler('fieldtype')->get($fieldType); |
|
109
|
|
|
$fieldTypeName = $fType->getVar('fieldtype_name'); |
|
|
|
|
|
|
110
|
|
|
} else { |
|
111
|
|
|
$fieldType = null; |
|
112
|
|
|
} |
|
113
|
|
|
switch ($fieldType) { |
|
114
|
|
|
case 2: |
|
115
|
|
|
case 3: |
|
116
|
|
|
case 4: |
|
117
|
|
|
case 5: |
|
118
|
|
|
$ret .= $this->getInitVar($fieldName, 'INT'); |
|
119
|
|
|
break; |
|
120
|
|
|
case 6: |
|
121
|
|
|
$ret .= $this->getInitVar($fieldName, 'FLOAT'); |
|
122
|
|
|
break; |
|
123
|
|
|
case 7: |
|
124
|
|
|
case 8: |
|
125
|
|
|
$ret .= $this->getInitVar($fieldName, 'DECIMAL'); |
|
126
|
|
|
break; |
|
127
|
|
|
case 10: |
|
128
|
|
|
$ret .= $this->getInitVar($fieldName, 'ENUM'); |
|
129
|
|
|
break; |
|
130
|
|
|
case 11: |
|
131
|
|
|
$ret .= $this->getInitVar($fieldName, 'EMAIL'); |
|
132
|
|
|
break; |
|
133
|
|
|
case 12: |
|
134
|
|
|
$ret .= $this->getInitVar($fieldName, 'URL'); |
|
135
|
|
|
break; |
|
136
|
|
|
case 13: |
|
137
|
|
|
case 14: |
|
138
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTBOX'); |
|
139
|
|
|
break; |
|
140
|
|
|
case 15: |
|
141
|
|
|
case 16: |
|
142
|
|
|
case 17: |
|
143
|
|
|
case 18: |
|
144
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTAREA'); |
|
145
|
|
|
break; |
|
146
|
|
|
case 19: |
|
147
|
|
|
case 20: |
|
148
|
|
|
case 21: |
|
149
|
|
|
case 22: |
|
150
|
|
|
case 23: |
|
151
|
|
|
$ret .= $this->getInitVar($fieldName, 'LTIME'); |
|
152
|
|
|
break; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return $ret; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @private function getClassObject |
|
161
|
|
|
* @param $module |
|
162
|
|
|
* @param $table |
|
163
|
|
|
* @param $fields |
|
164
|
|
|
* @return string |
|
165
|
|
|
*/ |
|
166
|
|
|
private function getClassObject($module, $table, $fields) |
|
167
|
|
|
{ |
|
168
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
169
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
170
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
171
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
172
|
|
|
$tableName = $table->getVar('table_name'); |
|
173
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
174
|
|
|
$ucfTableName = ucfirst($tableName); |
|
175
|
|
|
$ret = $pc->getPhpCodeDefined(); |
|
176
|
|
|
$ret .= $pc->getPhpCodeCommentMultiLine(['Class Object' => $ucfModuleDirname . $ucfTableName]); |
|
177
|
|
|
$cCl = ''; |
|
178
|
|
|
|
|
179
|
|
|
$fieldInForm = []; |
|
180
|
|
|
$fieldElementId = []; |
|
181
|
|
|
$optionsFieldName = []; |
|
182
|
|
|
foreach (array_keys($fields) as $f) { |
|
183
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
184
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
185
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
|
186
|
|
|
$fieldElements = $tc->getHandler('fieldelements')->get($fieldElement); |
|
187
|
|
|
$fieldElementId[] = $fieldElements->getVar('fieldelement_id'); |
|
188
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
|
189
|
|
|
if (in_array(5, $fieldElementId)) { |
|
190
|
|
|
if (count($rpFieldName) % 5) { |
|
|
|
|
|
|
191
|
|
|
$optionsFieldName[] = "'" . $rpFieldName . "'"; |
|
192
|
|
|
} else { |
|
193
|
|
|
$optionsFieldName[] = "'" . $rpFieldName . "'\n"; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) { |
|
197
|
|
|
$fieldId = $fieldName; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
|
201
|
|
|
$optionsElements = implode(', ', $optionsFieldName); |
|
|
|
|
|
|
202
|
|
|
$cCl .= $pc->getPhpCodeCommentMultiLine(['Options' => '']); |
|
203
|
|
|
$options = $pc->getPhpCodeArray('', $optionsFieldName, true); |
|
204
|
|
|
$cCl .= $pc->getPhpCodeVariableClass('private', 'options', $options); |
|
205
|
|
|
} |
|
206
|
|
|
unset($optionsFieldName); |
|
207
|
|
|
|
|
208
|
|
|
$cCl .= $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t"); |
|
209
|
|
|
$constr = $this->getInitVars($fields); |
|
210
|
|
|
$cCl .= $pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t"); |
|
211
|
|
|
$arrayGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null']; |
|
212
|
|
|
$cCl .= $pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t"); |
|
213
|
|
|
$getInstance = $pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t"); |
|
214
|
|
|
$instance = $xc->getXcEqualsOperator('$instance', 'new self()', null, false, "\t\t\t"); |
|
215
|
|
|
$getInstance .= $pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t"); |
|
216
|
|
|
$cCl .= $pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t"); |
|
217
|
|
|
|
|
218
|
|
|
$cCl .= $this->getNewInsertId($table); |
|
219
|
|
|
$cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm); |
|
|
|
|
|
|
220
|
|
|
$cCl .= $this->getValuesInObject($moduleDirname, $table, $fields); |
|
221
|
|
|
$cCl .= $this->getToArrayInObject($table); |
|
222
|
|
|
|
|
223
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
|
224
|
|
|
$cCl .= $this->getOptionsCheck($table); |
|
225
|
|
|
} |
|
226
|
|
|
unset($fieldElementId); |
|
227
|
|
|
|
|
228
|
|
|
$ret .= $pc->getPhpCodeClass($ucfModuleDirname . $ucfTableName, $cCl, 'XoopsObject'); |
|
229
|
|
|
|
|
230
|
|
|
return $ret; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @private function getNewInsertId |
|
235
|
|
|
* |
|
236
|
|
|
* @param $table |
|
237
|
|
|
* |
|
238
|
|
|
* @return string |
|
239
|
|
|
*/ |
|
240
|
|
|
private function getNewInsertId($table) |
|
241
|
|
|
{ |
|
242
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
243
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
244
|
|
|
$tableName = $table->getVar('table_name'); |
|
245
|
|
|
$ucfTableName = ucfirst($tableName); |
|
246
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['The new inserted' => '$Id', '@return' => 'inserted id'], "\t"); |
|
247
|
|
|
$getInsertedId = $xc->getXcEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, false, "\t\t"); |
|
248
|
|
|
$getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t"); |
|
249
|
|
|
|
|
250
|
|
|
$ret .= $pc->getPhpCodeFunction('getNewInsertedId' . $ucfTableName, '', $getInsertedId, 'public ', false, "\t"); |
|
251
|
|
|
|
|
252
|
|
|
return $ret; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @private function getFunctionForm |
|
257
|
|
|
* |
|
258
|
|
|
* @param string $module |
|
259
|
|
|
* @param string $table |
|
260
|
|
|
* |
|
261
|
|
|
* @param $fieldId |
|
262
|
|
|
* @param $fieldInForm |
|
263
|
|
|
* @return string |
|
264
|
|
|
*/ |
|
265
|
|
|
private function getFunctionForm($module, $table, $fieldId, $fieldInForm) |
|
266
|
|
|
{ |
|
267
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
268
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
269
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
270
|
|
|
$fe = ClassFormElements::getInstance(); |
|
271
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
272
|
|
|
$tableName = $table->getVar('table_name'); |
|
273
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
274
|
|
|
$tableCategory = $table->getVar('table_category'); |
|
275
|
|
|
$tablePermissions = $table->getVar('table_permissions'); |
|
|
|
|
|
|
276
|
|
|
$ucfTableName = ucfirst($tableName); |
|
277
|
|
|
$stuTableSoleName = mb_strtoupper($tableSoleName); |
|
278
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
|
279
|
|
|
$fe->initForm($module, $table); |
|
280
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['@public function' => 'getForm', '@param bool' => '$action', '@return' => 'XoopsThemeForm'], "\t"); |
|
281
|
|
|
$action = $xc->getXcEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, false, "\t\t\t"); |
|
282
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
283
|
|
|
$getForm = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t"); |
|
284
|
|
|
//$getForm .= $pc->getPhpCodeConditions('$action', ' === ', 'false', $action, false, "\t\t"); |
|
285
|
|
|
$getForm .= $pc->getPhpCodeConditions('false', ' === ', '$action', $action, false, "\t\t"); |
|
286
|
|
|
$xUser = $pc->getPhpCodeGlobals('xoopsUser'); |
|
287
|
|
|
$xModule = $pc->getPhpCodeGlobals('xoopsModule'); |
|
288
|
|
|
if (1 != $tableCategory/* && (1 == $tablePermissions)*/) { |
|
289
|
|
|
$getForm .= $pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t"); |
|
290
|
|
|
$getForm .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t"); |
|
291
|
|
|
$getForm .= $pc->getPhpCodeTernaryOperator('groups', 'is_object(' . $xUser . ')', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t"); |
|
292
|
|
|
$checkRight = $xc->getXcCheckRight('$gpermHandler', $permString = '', 32, '$groups', $xModule . '->getVar(\'mid\')', true); |
|
293
|
|
|
$ternaryOperator = $pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t\t"); |
|
294
|
|
|
$permissionUpload = $xc->getXcEqualsOperator('$permissionUpload', 'true', null, false, "\t\t\t\t"); |
|
295
|
|
|
$ternOperator = $pc->getPhpCodeRemoveCarriageReturn($ternaryOperator, '', "\r"); |
|
296
|
|
|
$if = $pc->getPhpCodeConditions('!' . $xUser . '->isAdmin(' . $xModule . '->mid())', '', '', $ternaryOperator, $permissionUpload, "\t\t\t"); |
|
297
|
|
|
$getForm .= $pc->getPhpCodeConditions($xUser, '', '', $if, $ternOperator, "\t\t"); |
|
298
|
|
|
} |
|
299
|
|
|
$getForm .= $pc->getPhpCodeCommentLine('Title', '', "\t\t"); |
|
300
|
|
|
$getForm .= $pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "sprintf({$language}{$stuTableSoleName}_ADD)", "sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t"); |
|
301
|
|
|
$getForm .= $pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t"); |
|
302
|
|
|
$getForm .= $xc->getXcLoad('XoopsFormLoader', "\t\t"); |
|
303
|
|
|
$getForm .= $cc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post'); |
|
304
|
|
|
$getForm .= $cc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'"); |
|
305
|
|
|
$getForm .= $fe->renderElements(); |
|
306
|
|
|
|
|
307
|
|
|
if (in_array(1, $fieldInForm)) { |
|
308
|
|
|
if (1 == $table->getVar('table_permissions')) { |
|
309
|
|
|
$getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId); |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
$getForm .= $pc->getPhpCodeCommentLine('To Save', '', "\t\t"); |
|
313
|
|
|
//$hiddenSave = $cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false); |
|
314
|
|
|
$getForm .= $cc->getClassAddElement('form', "new \XoopsFormHidden('op', 'save')"); |
|
315
|
|
|
//$buttonSend = $cc->getClassXoopsFormButton('', '', 'submit', '_SUBMIT', 'submit', true); |
|
316
|
|
|
$getForm .= $cc->getClassAddElement('form', "new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)"); |
|
317
|
|
|
$getForm .= $this->getSimpleString('return $form;', "\t\t"); |
|
318
|
|
|
|
|
319
|
|
|
$ret .= $pc->getPhpCodeFunction('getForm' . $ucfTableName, '$action = false', $getForm, 'public ', false, "\t"); |
|
320
|
|
|
|
|
321
|
|
|
return $ret; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @private function getPermissionsInForm |
|
326
|
|
|
* |
|
327
|
|
|
* @param string $moduleDirname |
|
328
|
|
|
* @param string $fieldId |
|
329
|
|
|
* |
|
330
|
|
|
* @return string |
|
331
|
|
|
*/ |
|
332
|
|
|
private function getPermissionsInForm($moduleDirname, $fieldId) |
|
333
|
|
|
{ |
|
334
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
335
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
336
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
337
|
|
|
$permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE'); |
|
338
|
|
|
$permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT'); |
|
339
|
|
|
$permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW'); |
|
340
|
|
|
$ret = $pc->getPhpCodeCommentLine('Permissions', '', "\t\t"); |
|
341
|
|
|
$ret .= $xc->getXcEqualsOperator('$memberHandler', "xoops_getHandler('member')", null, false, "\t\t"); |
|
342
|
|
|
$ret .= $xc->getXcEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, false, "\t\t"); |
|
343
|
|
|
$ret .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, false, "\t\t"); |
|
344
|
|
|
$ret .= $pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t"); |
|
345
|
|
|
$fId = $xc->getXcGetVar('', 'this', $fieldId, true); |
|
346
|
|
|
$mId = $xc->getXcGetVar('', "GLOBALS['xoopsModule']", 'mid', true); |
|
347
|
|
|
$ifGroups = $xc->getXcGetGroupIds('groupsIdsApprove', 'gpermHandler', "'{$moduleDirname}_approve'", $fId, $mId, "\t\t\t"); |
|
348
|
|
|
$ifGroups .= $pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t"); |
|
349
|
|
|
$ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$groupsIdsApprove', false, "\t\t\t"); |
|
350
|
|
|
$ifGroups .= $xc->getXcGetGroupIds('groupsIdsSubmit', 'gpermHandler', "'{$moduleDirname}_submit'", $fId, $mId, "\t\t\t"); |
|
351
|
|
|
$ifGroups .= $pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t"); |
|
352
|
|
|
$ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$groupsIdsSubmit', false, "\t\t\t"); |
|
353
|
|
|
$ifGroups .= $xc->getXcGetGroupIds('groupsIdsView', 'gpermHandler', "'{$moduleDirname}_view'", $fId, $mId, "\t\t\t"); |
|
354
|
|
|
$ifGroups .= $pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t"); |
|
355
|
|
|
$ifGroups .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$groupsIdsView', false, "\t\t\t"); |
|
356
|
|
|
|
|
357
|
|
|
$else = $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$fullList', false, "\t\t\t"); |
|
358
|
|
|
$else .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$fullList', false, "\t\t\t"); |
|
359
|
|
|
$else .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$fullList', false, "\t\t\t"); |
|
360
|
|
|
|
|
361
|
|
|
$ret .= $pc->getPhpCodeConditions('!$this->isNew()', null, null, $ifGroups, $else, "\t\t"); |
|
362
|
|
|
$ret .= $pc->getPhpCodeCommentLine('To Approve', '', "\t\t"); |
|
363
|
|
|
$ret .= $cc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList'); |
|
364
|
|
|
$ret .= $cc->getClassAddElement('form', '$groupsCanApproveCheckbox'); |
|
365
|
|
|
$ret .= $pc->getPhpCodeCommentLine('To Submit', '', "\t\t"); |
|
366
|
|
|
$ret .= $cc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList'); |
|
367
|
|
|
$ret .= $cc->getClassAddElement('form', '$groupsCanSubmitCheckbox'); |
|
368
|
|
|
$ret .= $pc->getPhpCodeCommentLine('To View', '', "\t\t"); |
|
369
|
|
|
$ret .= $cc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList'); |
|
370
|
|
|
$ret .= $cc->getClassAddElement('form', '$groupsCanViewCheckbox'); |
|
371
|
|
|
|
|
372
|
|
|
return $ret; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @private function getValuesInObject |
|
377
|
|
|
* |
|
378
|
|
|
* @param $moduleDirname |
|
379
|
|
|
* @param $table |
|
380
|
|
|
* @param $fields |
|
381
|
|
|
* @return string |
|
382
|
|
|
* @internal param $null |
|
383
|
|
|
*/ |
|
384
|
|
|
private function getValuesInObject($moduleDirname, $table, $fields) |
|
385
|
|
|
{ |
|
386
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
387
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
388
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
389
|
|
|
$stuModuleDirname = mb_strtoupper($moduleDirname); |
|
|
|
|
|
|
390
|
|
|
$ucfTableName = ucfirst($table->getVar('table_name')); |
|
391
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Values', '@param null $keys' => '', '@param null $format' => '', '@param null$maxDepth' => '', '@return' => 'array'], "\t"); |
|
392
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
393
|
|
|
$getValues = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t"); |
|
394
|
|
|
$getValues .= $xc->getXcEqualsOperator('$ret', '$this->getValues($keys, $format, $maxDepth)', null, false, "\t\t"); |
|
395
|
|
|
|
|
396
|
|
|
foreach (array_keys($fields) as $f) { |
|
397
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
398
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
399
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
|
400
|
|
|
switch ($fieldElement) { |
|
401
|
|
|
case 3: |
|
402
|
|
|
case 4: |
|
403
|
|
|
$getValues .= $pc->getPhpCodeStripTags("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", false, "\t\t"); |
|
404
|
|
|
break; |
|
405
|
|
|
case 8: |
|
406
|
|
|
$getValues .= $xc->getXcUnameFromId("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", "\t\t"); |
|
407
|
|
|
break; |
|
408
|
|
|
case 15: |
|
409
|
|
|
$getValues .= $xc->getXcFormatTimeStamp("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", 's', "\t\t"); |
|
410
|
|
|
break; |
|
411
|
|
|
default: |
|
412
|
|
|
if ($fieldElement > 15) { |
|
413
|
|
|
$fieldElements = $tc->getHandler('fieldelements')->get($fieldElement); |
|
414
|
|
|
$fieldElementMid = $fieldElements->getVar('fieldelement_mid'); |
|
415
|
|
|
$fieldElementTid = $fieldElements->getVar('fieldelement_tid'); |
|
416
|
|
|
$fieldElementName = $fieldElements->getVar('fieldelement_name'); |
|
417
|
|
|
$fieldNameDesc = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)); |
|
|
|
|
|
|
418
|
|
|
$topicTableName = str_replace(': ', '', mb_strtolower($fieldNameDesc)); |
|
419
|
|
|
$fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid); |
|
420
|
|
|
foreach (array_keys($fieldsTopics) as $g) { |
|
421
|
|
|
$fieldNameTopic = $fieldsTopics[$g]->getVar('field_name'); |
|
422
|
|
|
if (1 == $fieldsTopics[$g]->getVar('field_main')) { |
|
423
|
|
|
$fieldMainTopic = $fieldNameTopic; |
|
424
|
|
|
} |
|
425
|
|
|
} |
|
426
|
|
|
$getHandlerVar = "\${$moduleDirname}->getHandler('{$topicTableName}')"; |
|
427
|
|
|
$getValues .= $xc->getXcEqualsOperator("\${$topicTableName}", $getHandlerVar, null, false, "\t\t"); |
|
428
|
|
|
$getTopicTable = "\${$topicTableName}->get(\$this->getVar('{$fieldName}'))"; |
|
429
|
|
|
$getValues .= $xc->getXcEqualsOperator("\${$topicTableName}Obj", $getTopicTable, null, false, "\t\t"); |
|
430
|
|
|
$fMainTopic = "\${$topicTableName}Obj->getVar('{$fieldMainTopic}')"; |
|
|
|
|
|
|
431
|
|
|
$getValues .= $xc->getXcEqualsOperator("\$ret['{$rpFieldName}']", $fMainTopic, null, false, "\t\t"); |
|
432
|
|
|
} else { |
|
433
|
|
|
$getValues .= $xc->getXcGetVar("ret['{$rpFieldName}']", 'this', $fieldName, false, "\t\t"); |
|
434
|
|
|
} |
|
435
|
|
|
break; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
$getValues .= $this->getSimpleString('return $ret;', "\t\t"); |
|
439
|
|
|
|
|
440
|
|
|
$ret .= $pc->getPhpCodeFunction('getValues' . $ucfTableName, '$keys = null, $format = null, $maxDepth = null', $getValues, 'public ', false, "\t"); |
|
441
|
|
|
|
|
442
|
|
|
return $ret; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* @private function getToArrayInObject |
|
447
|
|
|
* |
|
448
|
|
|
* @param $table |
|
449
|
|
|
* |
|
450
|
|
|
* @return string |
|
451
|
|
|
*/ |
|
452
|
|
|
private function getToArrayInObject($table) |
|
453
|
|
|
{ |
|
454
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
455
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
456
|
|
|
$tableName = $table->getVar('table_name'); |
|
457
|
|
|
$ucfTableName = ucfirst($tableName); |
|
458
|
|
|
$multiLineCom = ['Returns an array representation' => 'of the object', '' => '', '@return' => 'array']; |
|
459
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine($multiLineCom, "\t"); |
|
460
|
|
|
|
|
461
|
|
|
$getToArray = $pc->getPhpCodeArray('ret', [], false, "\t\t"); |
|
462
|
|
|
$getToArray .= $xc->getXcEqualsOperator('$vars', '$this->getVars()', null, false, "\t\t"); |
|
463
|
|
|
$foreach = $xc->getXcGetVar('ret[$var]', 'this', '"{$var}"', false, "\t"); |
|
464
|
|
|
$getToArray .= $pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t"); |
|
465
|
|
|
$getToArray .= $this->getSimpleString('return $ret;', "\t\t"); |
|
466
|
|
|
|
|
467
|
|
|
$ret .= $pc->getPhpCodeFunction('toArray' . $ucfTableName, '', $getToArray, 'public ', false, "\t"); |
|
468
|
|
|
|
|
469
|
|
|
return $ret; |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* @private function getOptionsCheck |
|
474
|
|
|
* |
|
475
|
|
|
* @param $table |
|
476
|
|
|
* |
|
477
|
|
|
* @return string |
|
478
|
|
|
*/ |
|
479
|
|
|
private function getOptionsCheck($table) |
|
480
|
|
|
{ |
|
481
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
482
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
483
|
|
|
$tableName = $table->getVar('table_name'); |
|
484
|
|
|
$ucfTableName = ucfirst($tableName); |
|
485
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Options'], "\t"); |
|
486
|
|
|
$getOptions = $pc->getPhpCodeArray('ret', [], false, "\t"); |
|
487
|
|
|
|
|
488
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
489
|
|
|
foreach (array_keys($fields) as $f) { |
|
490
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
491
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
492
|
|
|
|
|
493
|
|
|
$fieldElements = $tc->getHandler('fieldelements')->get($fieldElement); |
|
494
|
|
|
$fieldElementId = $fieldElements->getVar('fieldelement_id'); |
|
495
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
|
496
|
|
|
if (5 == $fieldElementId) { |
|
497
|
|
|
$arrayPush = $pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t"); |
|
498
|
|
|
$getOptions .= $pc->getPhpCodeConditions(1, ' == ', "\$this->getVar('{$fieldName}')", $arrayPush, false, "\t\t"); |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
$getOptions .= $this->getSimpleString('return $ret;', "\t\t"); |
|
503
|
|
|
|
|
504
|
|
|
$ret .= $pc->getPhpCodeFunction('getOptions' . $ucfTableName, '', $getOptions, 'public ', false, "\t"); |
|
505
|
|
|
|
|
506
|
|
|
return $ret; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
/** |
|
510
|
|
|
* @public function getClassHandler |
|
511
|
|
|
* |
|
512
|
|
|
* @param string $moduleDirname |
|
513
|
|
|
* @param string $table |
|
514
|
|
|
* @param string $fieldId |
|
515
|
|
|
* @param $fieldName |
|
516
|
|
|
* @param string $fieldMain |
|
517
|
|
|
* |
|
518
|
|
|
* @param $fieldParent |
|
519
|
|
|
* @param $fieldParentId |
|
520
|
|
|
* @param $fieldElement |
|
521
|
|
|
* @return string |
|
522
|
|
|
*/ |
|
523
|
|
|
private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement) |
|
524
|
|
|
{ |
|
525
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
526
|
|
|
$tableName = $table->getVar('table_name'); |
|
527
|
|
|
$tableCategory = $table->getVar('table_category'); |
|
|
|
|
|
|
528
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
529
|
|
|
$tableFieldname = $table->getVar('table_fieldname'); |
|
|
|
|
|
|
530
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
531
|
|
|
$ucfTableName = ucfirst($tableName); |
|
532
|
|
|
$ucfTableSoleName = ucfirst($tableSoleName); |
|
|
|
|
|
|
533
|
|
|
$ucfModuleTable = $ucfModuleDirname . $ucfTableName; |
|
534
|
|
|
$multiLineCom = ['Class Object Handler' => $ucfModuleDirname . $ucfTableName]; |
|
535
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine($multiLineCom); |
|
536
|
|
|
|
|
537
|
|
|
$cClh = $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null|XoopsDatabase $db'], "\t"); |
|
538
|
|
|
$constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n"; |
|
539
|
|
|
|
|
540
|
|
|
$cClh .= $pc->getPhpCodeFunction('__construct', 'XoopsDatabase $db', $constr, 'public ', false, "\t"); |
|
541
|
|
|
$cClh .= $this->getClassCreate(); |
|
542
|
|
|
$cClh .= $this->getClassGet(); |
|
543
|
|
|
$cClh .= $this->getClassGetInsertId(); |
|
544
|
|
|
$cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain); |
|
545
|
|
|
$cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain); |
|
546
|
|
|
$cClh .= $this->getClassCriteria($tableName); |
|
547
|
|
|
if ($fieldElement > 15 && in_array(1, $fieldParentId)) { |
|
548
|
|
|
$cClh .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement); |
|
|
|
|
|
|
549
|
|
|
$cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
$ret .= $pc->getPhpCodeClass("{$ucfModuleTable}Handler", $cClh, 'XoopsPersistableObjectHandler'); |
|
553
|
|
|
|
|
554
|
|
|
return $ret; |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
/** |
|
558
|
|
|
* @public function getClassCreate |
|
559
|
|
|
* |
|
560
|
|
|
* @return string |
|
561
|
|
|
*/ |
|
562
|
|
|
private function getClassCreate() |
|
563
|
|
|
{ |
|
564
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
565
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['@param bool' => '$isNew', '' => '', '@return' => 'object'], "\t"); |
|
566
|
|
|
$cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t"); |
|
567
|
|
|
|
|
568
|
|
|
$ret .= $pc->getPhpCodeFunction('create', '$isNew = true', $cClhc, 'public ', false, "\t"); |
|
569
|
|
|
|
|
570
|
|
|
return $ret; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* @public function getClassGet |
|
575
|
|
|
* |
|
576
|
|
|
* @return string |
|
577
|
|
|
*/ |
|
578
|
|
|
private function getClassGet() |
|
579
|
|
|
{ |
|
580
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
581
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['retrieve a' => 'field', '' => '', '@param int' => '$i field id', '@param null' => 'fields', '@return mixed reference to the' => '{@link Get} object'], "\t"); |
|
582
|
|
|
$cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t"); |
|
583
|
|
|
|
|
584
|
|
|
$ret .= $pc->getPhpCodeFunction('get', '$i = null, $fields = null', $cClhg, 'public ', false, "\t"); |
|
585
|
|
|
|
|
586
|
|
|
return $ret; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
/** |
|
590
|
|
|
* @public function getClassGetInsertId |
|
591
|
|
|
* |
|
592
|
|
|
* @return string |
|
593
|
|
|
*/ |
|
594
|
|
|
private function getClassGetInsertId() |
|
595
|
|
|
{ |
|
596
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
597
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['get inserted' => 'id', '' => '', '@param' => 'null', '@return integer reference to the' => '{@link Get} object'], "\t"); |
|
598
|
|
|
$cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t"); |
|
599
|
|
|
|
|
600
|
|
|
$ret .= $pc->getPhpCodeFunction('getInsertId', '', $cClhgid, 'public ', false, "\t"); |
|
601
|
|
|
|
|
602
|
|
|
return $ret; |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
/** |
|
606
|
|
|
* @public function getClassCounter |
|
607
|
|
|
* |
|
608
|
|
|
* @param $tableName |
|
609
|
|
|
* @param $fieldId |
|
610
|
|
|
* @param $fieldMain |
|
611
|
|
|
* |
|
612
|
|
|
* @return string |
|
613
|
|
|
*/ |
|
614
|
|
|
private function getClassCounter($tableName, $fieldId, $fieldMain) |
|
615
|
|
|
{ |
|
616
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
617
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
618
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
619
|
|
|
$ucfTableName = ucfirst($tableName); |
|
620
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Get Count ' . $ucfTableName => 'in the database', '@param int $start' => '', '@param int $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t"); |
|
621
|
|
|
|
|
622
|
|
|
$critCount = $cc->getClassCriteriaCompo('crCount' . $ucfTableName, "\t\t"); |
|
623
|
|
|
$paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)"; |
|
624
|
|
|
$critCount .= $xc->getXcEqualsOperator('$crCount' . $ucfTableName, $paramsCrit, null, false, "\t\t"); |
|
625
|
|
|
$critCount .= $this->getSimpleString("return parent::getCount(\$crCount{$ucfTableName});", "\t\t"); |
|
626
|
|
|
$params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'"; |
|
627
|
|
|
|
|
628
|
|
|
$ret .= $pc->getPhpCodeFunction('getCount' . $ucfTableName, $params, $critCount, 'public ', false, "\t"); |
|
629
|
|
|
|
|
630
|
|
|
return $ret; |
|
631
|
|
|
} |
|
632
|
|
|
|
|
633
|
|
|
/** |
|
634
|
|
|
* @public function getClassAll |
|
635
|
|
|
* |
|
636
|
|
|
* @param $tableName |
|
637
|
|
|
* @param $fieldId |
|
638
|
|
|
* @param $fieldMain |
|
639
|
|
|
* |
|
640
|
|
|
* @return string |
|
641
|
|
|
*/ |
|
642
|
|
|
private function getClassAll($tableName, $fieldId, $fieldMain) |
|
643
|
|
|
{ |
|
644
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
645
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
646
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
647
|
|
|
$ucfTableName = ucfirst($tableName); |
|
648
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Get All ' . $ucfTableName => 'in the database', '@param int $start' => '', '@param int $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t"); |
|
649
|
|
|
|
|
650
|
|
|
$critAll = $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t"); |
|
651
|
|
|
$paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)"; |
|
652
|
|
|
$critAll .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCrit, null, false, "\t\t"); |
|
653
|
|
|
$critAll .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t"); |
|
654
|
|
|
$params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'"; |
|
655
|
|
|
|
|
656
|
|
|
$ret .= $pc->getPhpCodeFunction('getAll' . $ucfTableName, $params, $critAll, 'public ', false, "\t"); |
|
657
|
|
|
|
|
658
|
|
|
return $ret; |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
/** |
|
662
|
|
|
* @public function getClassByCategory |
|
663
|
|
|
* |
|
664
|
|
|
* @param $moduleDirname |
|
665
|
|
|
* @param $tableName |
|
666
|
|
|
* @param $tableFieldName |
|
667
|
|
|
* @param $fieldId |
|
668
|
|
|
* @param $fieldName |
|
669
|
|
|
* @param $fieldMain |
|
670
|
|
|
* @param $fieldParent |
|
671
|
|
|
* |
|
672
|
|
|
* @param $fieldElement |
|
673
|
|
|
* @return string |
|
674
|
|
|
*/ |
|
675
|
|
|
private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement) |
|
|
|
|
|
|
676
|
|
|
{ |
|
677
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
678
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
679
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
680
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
681
|
|
|
$ucfTableName = ucfirst($tableName); |
|
682
|
|
|
$fieldElements = $tc->getHandler('fieldelements')->get($fieldElement); |
|
683
|
|
|
$fieldElementMid = $fieldElements->getVar('fieldelement_mid'); |
|
|
|
|
|
|
684
|
|
|
$fieldElementTid = $fieldElements->getVar('fieldelement_tid'); |
|
|
|
|
|
|
685
|
|
|
$fieldElementName = $fieldElements->getVar('fieldelement_name'); |
|
686
|
|
|
$fieldNameDesc = ucfirst(mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName))); |
|
|
|
|
|
|
687
|
|
|
$topicTableName = str_replace(': ', '', $fieldNameDesc); |
|
688
|
|
|
$lcfTopicTableName = lcfirst($topicTableName); |
|
689
|
|
|
|
|
690
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(["Get All {$ucfTableName} By" => "{$fieldNameDesc} Id", '@param int $start' => '', '@param int $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t"); |
|
691
|
|
|
|
|
692
|
|
|
$critAll = $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t"); |
|
693
|
|
|
$param1 = "'{$moduleDirname}_view'"; |
|
694
|
|
|
$param2 = "\$GLOBALS['xoopsUser']->getGroups()"; |
|
695
|
|
|
$param3 = "\$GLOBALS['xoopsModule']->getVar('mid')"; |
|
696
|
|
|
$critAll .= $xc->getXcGetItemIds($lcfTopicTableName, 'gpermHandler', $param1, $param2, $param3, "\t\t"); |
|
697
|
|
|
$critAll .= $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t"); |
|
698
|
|
|
|
|
699
|
|
|
if (false !== mb_strpos($fieldName, 'status')) { |
|
700
|
|
|
$crit = $cc->getClassCriteria('', "'{$fieldName}'", '0', "'!='", true); |
|
701
|
|
|
$critAll .= $cc->getClassAdd('crAll' . $ucfTableName, $crit, "\t\t"); |
|
702
|
|
|
} |
|
703
|
|
|
$paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)"; |
|
704
|
|
|
$critAll .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCritAll, null, false, "\t\t"); |
|
705
|
|
|
|
|
706
|
|
|
$critAll .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t"); |
|
707
|
|
|
$params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'"; |
|
708
|
|
|
|
|
709
|
|
|
$ret .= $pc->getPhpCodeFunction("getAll{$ucfTableName}By{$fieldNameDesc}Id" . $ucfTableName, $params, $critAll, 'public ', false, "\t"); |
|
710
|
|
|
|
|
711
|
|
|
return $ret; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
/** |
|
715
|
|
|
* @public function getClassCriteria |
|
716
|
|
|
* |
|
717
|
|
|
* @param $tableName |
|
718
|
|
|
* @return string |
|
719
|
|
|
*/ |
|
720
|
|
|
private function getClassCriteria($tableName) |
|
721
|
|
|
{ |
|
722
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
723
|
|
|
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
|
724
|
|
|
$ucfTableName = ucfirst($tableName); |
|
725
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Get' => 'Criteria ' . $ucfTableName, '@param ' => "\$cr{$ucfTableName}", '@param int $start' => '', '@param int $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t"); |
|
726
|
|
|
|
|
727
|
|
|
$paramsAllCriteria = "\$cr{$ucfTableName}, \$start, \$limit, \$sort, \$order"; |
|
728
|
|
|
|
|
729
|
|
|
$critSets = $cc->getClassSetStart('cr' . $ucfTableName, 'start', "\t\t"); |
|
730
|
|
|
$critSets .= $cc->getClassSetLimit('cr' . $ucfTableName, 'limit', "\t\t"); |
|
731
|
|
|
$critSets .= $cc->getClassSetSort('cr' . $ucfTableName, 'sort', "\t\t"); |
|
732
|
|
|
$critSets .= $cc->getClassSetOrder('cr' . $ucfTableName, 'order', "\t\t"); |
|
733
|
|
|
$critSets .= $this->getSimpleString("return \$cr{$ucfTableName};", "\t\t"); |
|
734
|
|
|
|
|
735
|
|
|
$ret .= $pc->getPhpCodeFunction("get{$ucfTableName}Criteria", $paramsAllCriteria, $critSets, 'private ', false, "\t"); |
|
736
|
|
|
|
|
737
|
|
|
return $ret; |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
/** |
|
741
|
|
|
* @public function getClassGetTableSolenameById |
|
742
|
|
|
* |
|
743
|
|
|
* @param $moduleDirname |
|
744
|
|
|
* @param $table |
|
745
|
|
|
* |
|
746
|
|
|
* @param $fieldMain |
|
747
|
|
|
* @return string |
|
748
|
|
|
*/ |
|
749
|
|
|
private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain) |
|
750
|
|
|
{ |
|
751
|
|
|
$pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
|
752
|
|
|
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
|
753
|
|
|
$tableName = $table->getVar('table_name'); |
|
754
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
755
|
|
|
$ucfTableSoleName = ucfirst($tableSoleName); |
|
756
|
|
|
$ccTableSoleName = $this->getCamelCase($tableSoleName, true); |
|
757
|
|
|
$ret = $pc->getPhpCodeCommentMultiLine(['Returns the' => $ucfTableSoleName . ' from id', '' => '', '@return' => 'string'], "\t"); |
|
758
|
|
|
$soleName = $xc->getXcEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t"); |
|
759
|
|
|
$soleName .= $xc->getXcEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t"); |
|
760
|
|
|
|
|
761
|
|
|
$contentIf = $xc->getXoopsHandlerLine($moduleDirname, $tableName, "\t\t\t"); |
|
762
|
|
|
$contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t"); |
|
|
|
|
|
|
763
|
|
|
$getVar = $xc->getXcGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t"); |
|
764
|
|
|
$contentIf .= $pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t"); |
|
765
|
|
|
|
|
766
|
|
|
$soleName .= $pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t"); |
|
767
|
|
|
$soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t"); |
|
768
|
|
|
|
|
769
|
|
|
$ret .= $pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t"); |
|
770
|
|
|
|
|
771
|
|
|
return $ret; |
|
772
|
|
|
} |
|
773
|
|
|
|
|
774
|
|
|
/** |
|
775
|
|
|
* @public function render |
|
776
|
|
|
* @param null |
|
777
|
|
|
* |
|
778
|
|
|
* @return bool|string |
|
779
|
|
|
*/ |
|
780
|
|
|
public function render() |
|
781
|
|
|
{ |
|
782
|
|
|
$tc = Tdmcreate\Helper::getInstance(); |
|
783
|
|
|
$module = $this->getModule(); |
|
784
|
|
|
$table = $this->getTable(); |
|
785
|
|
|
$filename = $this->getFileName(); |
|
786
|
|
|
$tableName = $table->getVar('table_name'); |
|
|
|
|
|
|
787
|
|
|
$tableFieldName = $table->getVar('table_fieldname'); |
|
|
|
|
|
|
788
|
|
|
$tableCategory = $table->getVar('table_category'); |
|
|
|
|
|
|
789
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
790
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
791
|
|
|
$fieldInForm = []; |
|
792
|
|
|
$fieldParentId = []; |
|
793
|
|
|
$fieldElementId = []; |
|
794
|
|
|
$fieldParent = null; |
|
795
|
|
|
foreach (array_keys($fields) as $f) { |
|
796
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
797
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
|
798
|
|
|
$fieldParentId[] = $fields[$f]->getVar('field_parent'); |
|
799
|
|
|
if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) { |
|
800
|
|
|
$fieldId = $fieldName; // $fieldId = fields parameter index field |
|
801
|
|
|
} |
|
802
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
803
|
|
|
$fieldMain = $fieldName; // $fieldMain = fields parameter main field |
|
804
|
|
|
} |
|
805
|
|
|
if (1 == $fields[$f]->getVar('field_parent')) { |
|
806
|
|
|
$fieldParent = $fieldName; // $fieldParent = fields parameter parent field |
|
807
|
|
|
} |
|
808
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
809
|
|
|
|
|
810
|
|
|
$fieldElements = $tc->getHandler('fieldelements')->get($fieldElement); |
|
811
|
|
|
$fieldElementId[] = $fieldElements->getVar('fieldelement_id'); |
|
812
|
|
|
} |
|
813
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
814
|
|
|
$content .= $this->getClassObject($module, $table, $fields); |
|
815
|
|
|
$content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement); |
|
|
|
|
|
|
816
|
|
|
|
|
817
|
|
|
$this->create($moduleDirname, 'class', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
818
|
|
|
|
|
819
|
|
|
return $this->renderFile(); |
|
820
|
|
|
} |
|
821
|
|
|
} |
|
822
|
|
|
|