|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: ClassFiles.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class ClassFiles. |
|
27
|
|
|
*/ |
|
28
|
|
|
class ClassFiles extends TDMCreateFile |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $classcode = null; |
|
34
|
|
|
|
|
35
|
|
|
/* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $tdmcfile = null; |
|
39
|
|
|
|
|
40
|
|
|
/* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $formelements = null; |
|
44
|
|
|
|
|
45
|
|
|
/* |
|
46
|
|
|
* @public function constructor |
|
47
|
|
|
* @param null |
|
48
|
|
|
*/ |
|
49
|
|
|
/** |
|
50
|
|
|
* |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
parent::__construct(); |
|
55
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
|
|
|
|
|
56
|
|
|
$this->tdmcfile = TDMCreateFile::getInstance(); |
|
|
|
|
|
|
57
|
|
|
$this->tdmcreate = TDMCreateHelper::getInstance(); |
|
|
|
|
|
|
58
|
|
|
$this->classcode = ClassXoopsCode::getInstance(); |
|
|
|
|
|
|
59
|
|
|
$this->formelements = ClassFormElements::getInstance(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/* |
|
63
|
|
|
* @static function &getInstance |
|
64
|
|
|
* @param null |
|
65
|
|
|
*/ |
|
66
|
|
|
/** |
|
67
|
|
|
* @return ClassFiles |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function &getInstance() |
|
70
|
|
|
{ |
|
71
|
|
|
static $instance = false; |
|
72
|
|
|
if (!$instance) { |
|
73
|
|
|
$instance = new self(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $instance; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/* |
|
80
|
|
|
* @public function write |
|
81
|
|
|
* @param string $module |
|
82
|
|
|
* @param string $table |
|
83
|
|
|
* @param mixed $tables |
|
84
|
|
|
*/ |
|
85
|
|
|
/** |
|
86
|
|
|
* @param $module |
|
87
|
|
|
* @param $table |
|
88
|
|
|
* @param $tables |
|
89
|
|
|
*/ |
|
90
|
|
|
public function write($module, $table, $tables) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->setModule($module); |
|
93
|
|
|
$this->setTable($table); |
|
94
|
|
|
$this->setTables($tables); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/* |
|
98
|
|
|
* @private function getInitVar |
|
99
|
|
|
* @param string $fieldName |
|
100
|
|
|
* @param string $type |
|
101
|
|
|
*/ |
|
102
|
|
|
/** |
|
103
|
|
|
* @param $fieldName |
|
104
|
|
|
* @param string $type |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
private function getInitVar($fieldName, $type = 'INT') |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->classcode->getClassInitVar($fieldName, $type); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/* |
|
114
|
|
|
* @private function getInitVars |
|
115
|
|
|
* @param array $fields |
|
116
|
|
|
*/ |
|
117
|
|
|
/** |
|
118
|
|
|
* @param $fields |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
private function getInitVars($fields) |
|
123
|
|
|
{ |
|
124
|
|
|
$ret = ''; |
|
125
|
|
|
// Creation of the initVar functions list |
|
126
|
|
|
foreach (array_keys($fields) as $f) { |
|
127
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
128
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
|
129
|
|
|
if ($fieldType > 1) { |
|
130
|
|
|
$fType = $this->tdmcreate->getHandler('fieldtype')->get($fieldType); |
|
|
|
|
|
|
131
|
|
|
$fieldTypeName = $fType->getVar('fieldtype_name'); |
|
|
|
|
|
|
132
|
|
|
} else { |
|
133
|
|
|
$fieldType = null; |
|
134
|
|
|
} |
|
135
|
|
|
switch ($fieldType) { |
|
136
|
|
|
case 2: |
|
137
|
|
|
case 3: |
|
138
|
|
|
case 4: |
|
139
|
|
|
case 5: |
|
140
|
|
|
$ret .= $this->getInitVar($fieldName, 'INT'); |
|
141
|
|
|
break; |
|
142
|
|
|
case 6: |
|
143
|
|
|
$ret .= $this->getInitVar($fieldName, 'FLOAT'); |
|
144
|
|
|
break; |
|
145
|
|
|
case 7: |
|
146
|
|
|
case 8: |
|
147
|
|
|
$ret .= $this->getInitVar($fieldName, 'DECIMAL'); |
|
148
|
|
|
break; |
|
149
|
|
|
case 10: |
|
150
|
|
|
$ret .= $this->getInitVar($fieldName, 'ENUM'); |
|
151
|
|
|
break; |
|
152
|
|
|
case 11: |
|
153
|
|
|
$ret .= $this->getInitVar($fieldName, 'EMAIL'); |
|
154
|
|
|
break; |
|
155
|
|
|
case 12: |
|
156
|
|
|
$ret .= $this->getInitVar($fieldName, 'URL'); |
|
157
|
|
|
break; |
|
158
|
|
|
case 13: |
|
159
|
|
|
case 14: |
|
160
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTBOX'); |
|
161
|
|
|
break; |
|
162
|
|
|
case 15: |
|
163
|
|
|
case 16: |
|
164
|
|
|
case 17: |
|
165
|
|
|
case 18: |
|
166
|
|
|
$ret .= $this->getInitVar($fieldName, 'TXTAREA'); |
|
167
|
|
|
break; |
|
168
|
|
|
case 19: |
|
169
|
|
|
case 20: |
|
170
|
|
|
case 21: |
|
171
|
|
|
case 22: |
|
172
|
|
|
case 23: |
|
173
|
|
|
$ret .= $this->getInitVar($fieldName, 'LTIME'); |
|
174
|
|
|
break; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
return $ret; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/* |
|
182
|
|
|
* @private function getHeadClass |
|
183
|
|
|
* @param string $moduleDirname |
|
184
|
|
|
* @param string $tableName |
|
185
|
|
|
* @param array $fields |
|
186
|
|
|
*/ |
|
187
|
|
|
/** |
|
188
|
|
|
* @param $moduleDirname |
|
189
|
|
|
* @param $tableName |
|
190
|
|
|
* @param $fields |
|
191
|
|
|
* |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
private function getHeadClass($moduleDirname, $tableName, $fields) |
|
195
|
|
|
{ |
|
196
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
197
|
|
|
$ucfTableName = ucfirst($tableName); |
|
198
|
|
|
$ret = $this->phpcode->getPhpCodeDefined(); |
|
|
|
|
|
|
199
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentMultiLine(array('Class Object ' => $ucfModuleDirname.$ucfTableName)); |
|
|
|
|
|
|
200
|
|
|
$contentClass = $this->phpcode->getPhpCodeCommentMultiLine(array('@var ' => 'mixed')); |
|
|
|
|
|
|
201
|
|
|
$contentClass .= $this->phpcode->getPhpCodeVariableClass('private', $moduleDirname); |
|
|
|
|
|
|
202
|
|
|
$ret .= <<<EOT |
|
203
|
|
|
class {$ucfModuleDirname}{$ucfTableName} extends XoopsObject |
|
204
|
|
|
{ |
|
205
|
|
|
/* |
|
206
|
|
|
* @var mixed |
|
207
|
|
|
*/ |
|
208
|
|
|
private \${$moduleDirname} = null;\n\n |
|
209
|
|
|
EOT; |
|
210
|
|
|
$fieldElementId = array(); |
|
211
|
|
|
$optionsFieldName = array(); |
|
212
|
|
|
foreach (array_keys($fields) as $f) { |
|
213
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
214
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
215
|
|
|
$fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement); |
|
|
|
|
|
|
216
|
|
|
$fieldElementId[] = $fieldElements->getVar('fieldelement_id'); |
|
217
|
|
|
$rpFieldName = $this->tdmcfile->getRightString($fieldName); |
|
|
|
|
|
|
218
|
|
|
if (in_array(5, $fieldElementId)) { |
|
219
|
|
|
if (count($rpFieldName) % 5) { |
|
220
|
|
|
$optionsFieldName[] = "'".$rpFieldName."'"; |
|
221
|
|
|
} else { |
|
222
|
|
|
$optionsFieldName[] = "'".$rpFieldName."'\n"; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
|
227
|
|
|
$optionsElements = implode(', ', $optionsFieldName); |
|
228
|
|
|
$ret .= <<<EOT |
|
229
|
|
|
/** |
|
230
|
|
|
* Options |
|
231
|
|
|
*/ |
|
232
|
|
|
public \$options = array({$optionsElements});\n\n |
|
233
|
|
|
EOT; |
|
234
|
|
|
} |
|
235
|
|
|
unset($fieldElementId, $optionsFieldName); |
|
236
|
|
|
$ret .= <<<EOT |
|
237
|
|
|
/* |
|
238
|
|
|
* Constructor |
|
239
|
|
|
* |
|
240
|
|
|
* @param null |
|
241
|
|
|
*/ |
|
242
|
|
|
public function __construct() |
|
243
|
|
|
{ |
|
244
|
|
|
\$this->{$moduleDirname} = {$ucfModuleDirname}Helper::getInstance(); |
|
245
|
|
|
{$this->getInitVars($fields)}\t}\n |
|
246
|
|
|
/* |
|
247
|
|
|
* @static function &getInstance |
|
248
|
|
|
* @param null |
|
249
|
|
|
*/ |
|
250
|
|
|
public static function &getInstance() |
|
251
|
|
|
{ |
|
252
|
|
|
static \$instance = false; |
|
253
|
|
|
if(!\$instance) { |
|
254
|
|
|
\$instance = new self(); |
|
255
|
|
|
} |
|
256
|
|
|
return \$instance; |
|
257
|
|
|
}\n\n |
|
258
|
|
|
EOT; |
|
259
|
|
|
|
|
260
|
|
|
return $ret; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/* |
|
264
|
|
|
* @private function getHeadInForm |
|
265
|
|
|
* @param string $module |
|
266
|
|
|
* @param string $table |
|
267
|
|
|
*/ |
|
268
|
|
|
/** |
|
269
|
|
|
* @param $module |
|
270
|
|
|
* @param $table |
|
271
|
|
|
* |
|
272
|
|
|
* @return string |
|
273
|
|
|
*/ |
|
274
|
|
|
private function getHeadInForm($module, $table) |
|
275
|
|
|
{ |
|
276
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
277
|
|
|
$tableName = $table->getVar('table_name'); |
|
278
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
279
|
|
|
$tablePermissions = $table->getVar('table_permissions'); |
|
280
|
|
|
$ucfTableName = ucfirst($tableName); |
|
281
|
|
|
$stuTableSoleName = strtoupper($tableSoleName); |
|
282
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
|
283
|
|
|
$this->formelements->initForm($module, $table); |
|
|
|
|
|
|
284
|
|
|
$ret = <<<EOT |
|
285
|
|
|
/* |
|
286
|
|
|
* Get form |
|
287
|
|
|
* |
|
288
|
|
|
* @param mixed \$action |
|
289
|
|
|
*/ |
|
290
|
|
|
public function getForm{$ucfTableName}(\$action = false) |
|
291
|
|
|
{ |
|
292
|
|
|
if(\$action === false) { |
|
293
|
|
|
\$action = \$_SERVER['REQUEST_URI']; |
|
294
|
|
|
}\n |
|
295
|
|
|
EOT; |
|
296
|
|
|
if (1 == $tablePermissions) { |
|
297
|
|
|
$ret .= <<<EOT |
|
298
|
|
|
global \$xoopsUser, \$xoopsModule; |
|
299
|
|
|
// Permissions for uploader |
|
300
|
|
|
\$gpermHandler =& xoops_gethandler('groupperm'); |
|
301
|
|
|
\$groups = is_object(\$xoopsUser) ? \$xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
302
|
|
|
if(\$xoopsUser) { |
|
303
|
|
|
if( !\$xoopsUser->isAdmin(\$xoopsModule->mid()) ) { |
|
304
|
|
|
\$permissionUpload =(\$gpermHandler->checkRight('{$moduleDirname}_ac', 32, \$groups, \$xoopsModule->getVar('mid'))) ? true : false ; |
|
305
|
|
|
}else{ |
|
306
|
|
|
\$permissionUpload = true; |
|
307
|
|
|
} |
|
308
|
|
|
}else{ |
|
309
|
|
|
\$permissionUpload = (\$gpermHandler->checkRight('{$moduleDirname}_ac', 32, \$groups, \$xoopsModule->getVar('mid'))) ? true : false ; |
|
310
|
|
|
}\n |
|
311
|
|
|
EOT; |
|
312
|
|
|
} |
|
313
|
|
|
$ret .= <<<EOT |
|
314
|
|
|
// Title |
|
315
|
|
|
\$title = \$this->isNew() ? sprintf({$language}{$stuTableSoleName}_ADD) : sprintf({$language}{$stuTableSoleName}_EDIT); |
|
316
|
|
|
// Get Theme Form |
|
317
|
|
|
xoops_load('XoopsFormLoader'); |
|
318
|
|
|
\$form = new XoopsThemeForm(\$title, 'form', \$action, 'post', true); |
|
319
|
|
|
\$form->setExtra('enctype="multipart/form-data"');\n |
|
320
|
|
|
EOT; |
|
321
|
|
|
|
|
322
|
|
|
if (0 == $table->getVar('table_category')) { |
|
323
|
|
|
$ret .= <<<EOT |
|
324
|
|
|
// {$ucfTableName} handler |
|
325
|
|
|
//\${$tableName}Handler =& \$this->{$moduleDirname}->getHandler('{$tableName}');\n |
|
326
|
|
|
EOT; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
$ret .= <<<EOT |
|
330
|
|
|
{$this->formelements->renderElements()} |
|
|
|
|
|
|
331
|
|
|
EOT; |
|
332
|
|
|
|
|
333
|
|
|
return $ret; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/* |
|
337
|
|
|
* @private function getPermissionsInForm |
|
338
|
|
|
* @param string $moduleDirname |
|
339
|
|
|
* @param string $fieldId |
|
340
|
|
|
*/ |
|
341
|
|
|
/** |
|
342
|
|
|
* @param $moduleDirname |
|
343
|
|
|
* @param $fieldId |
|
344
|
|
|
* |
|
345
|
|
|
* @return string |
|
346
|
|
|
*/ |
|
347
|
|
|
private function getPermissionsInForm($moduleDirname, $fieldId) |
|
348
|
|
|
{ |
|
349
|
|
|
$permissionApprove = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE'); |
|
|
|
|
|
|
350
|
|
|
$permissionSubmit = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT'); |
|
|
|
|
|
|
351
|
|
|
$permissionView = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW'); |
|
|
|
|
|
|
352
|
|
|
$ret = <<<EOT |
|
353
|
|
|
// Permissions |
|
354
|
|
|
\$memberHandler = & xoops_gethandler( 'member' ); |
|
355
|
|
|
\$groupList = \$memberHandler->getGroupList(); |
|
356
|
|
|
\$gpermHandler = &xoops_gethandler( 'groupperm' ); |
|
357
|
|
|
\$fullList = array_keys( \$groupList ); |
|
358
|
|
|
global \$xoopsModule; |
|
359
|
|
|
if( !\$this->isNew() ) { |
|
360
|
|
|
\$groupsIdsApprove = \$gpermHandler->getGroupIds( '{$moduleDirname}_approve', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) ); |
|
361
|
|
|
\$groupsIdsSubmit = \$gpermHandler->getGroupIds( '{$moduleDirname}_submit', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) ); |
|
362
|
|
|
\$groupsIdsView = \$gpermHandler->getGroupIds( '{$moduleDirname}_view', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) ); |
|
363
|
|
|
\$groupsIdsApprove = array_values( \$groupsIdsApprove ); |
|
364
|
|
|
\$groupsCanApproveCheckbox = new XoopsFormCheckBox( {$permissionApprove}, 'groups_approve[]', \$groupsIdsApprove ); |
|
365
|
|
|
\$groupsIdsSubmit = array_values( \$groupsIdsSubmit ); |
|
366
|
|
|
\$groupsCanSubmitCheckbox = new XoopsFormCheckBox( {$permissionSubmit}, 'groups_submit[]', \$groupsIdsSubmit ); |
|
367
|
|
|
\$groupsIdsView = array_values( \$groupsIdsView ); |
|
368
|
|
|
\$groupsCanViewCheckbox = new XoopsFormCheckBox( {$permissionView}, 'groups_view[]', \$groupsIdsView ); |
|
369
|
|
|
} else { |
|
370
|
|
|
\$groupsCanApproveCheckbox = new XoopsFormCheckBox( {$permissionApprove}, 'groups_approve[]', \$fullList ); |
|
371
|
|
|
\$groupsCanSubmitCheckbox = new XoopsFormCheckBox( {$permissionSubmit}, 'groups_submit[]', \$fullList ); |
|
372
|
|
|
\$groupsCanViewCheckbox = new XoopsFormCheckBox( {$permissionView}, 'groups_view[]', \$fullList ); |
|
373
|
|
|
} |
|
374
|
|
|
// For approve |
|
375
|
|
|
\$groupsCanApproveCheckbox->addOptionArray( \$groupList ); |
|
376
|
|
|
\$form->addElement( \$groupsCanApproveCheckbox ); |
|
377
|
|
|
// For submit |
|
378
|
|
|
\$groupsCanSubmitCheckbox->addOptionArray( \$groupList ); |
|
379
|
|
|
\$form->addElement( \$groupsCanSubmitCheckbox ); |
|
380
|
|
|
// For view |
|
381
|
|
|
\$groupsCanViewCheckbox->addOptionArray( \$groupList ); |
|
382
|
|
|
\$form->addElement( \$groupsCanViewCheckbox );\n\n |
|
383
|
|
|
EOT; |
|
384
|
|
|
|
|
385
|
|
|
return $ret; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/* |
|
389
|
|
|
* @private function getFootInForm |
|
390
|
|
|
* @param null |
|
391
|
|
|
*/ |
|
392
|
|
|
/** |
|
393
|
|
|
* @return string |
|
394
|
|
|
*/ |
|
395
|
|
|
private function getFootInForm() |
|
396
|
|
|
{ |
|
397
|
|
|
$ret = <<<EOT |
|
398
|
|
|
// Send |
|
399
|
|
|
\$form->addElement(new XoopsFormHidden('op', 'save')); |
|
400
|
|
|
\$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
401
|
|
|
return \$form; |
|
402
|
|
|
}\n\n |
|
403
|
|
|
EOT; |
|
404
|
|
|
|
|
405
|
|
|
return $ret; |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
/* |
|
409
|
|
|
* @private function getToArray |
|
410
|
|
|
* @param null |
|
411
|
|
|
*/ |
|
412
|
|
|
/** |
|
413
|
|
|
* @return string |
|
414
|
|
|
*/ |
|
415
|
|
|
private function getValuesInForm($moduleDirname, $table, $fields) |
|
416
|
|
|
{ |
|
417
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
|
|
|
|
|
418
|
|
|
$ucfTableName = ucfirst($table->getVar('table_name')); |
|
419
|
|
|
$ret = <<<EOT |
|
420
|
|
|
/** |
|
421
|
|
|
* Get Values |
|
422
|
|
|
*/ |
|
423
|
|
|
public function getValues{$ucfTableName}(\$keys = null, \$format = null, \$maxDepth = null) |
|
424
|
|
|
{ |
|
425
|
|
|
\$ret = parent::getValues(\$keys, \$format, \$maxDepth);\n |
|
426
|
|
|
EOT; |
|
427
|
|
|
foreach (array_keys($fields) as $f) { |
|
428
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
429
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
430
|
|
|
$rpFieldName = $this->tdmcfile->getRightString($fieldName); |
|
|
|
|
|
|
431
|
|
|
switch ($fieldElement) { |
|
432
|
|
|
case 3: |
|
433
|
|
|
case 4: |
|
434
|
|
|
$ret .= <<<EOT |
|
435
|
|
|
\$ret['{$rpFieldName}'] = strip_tags(\$this->getVar('{$fieldName}'));\n |
|
436
|
|
|
EOT; |
|
437
|
|
|
break; |
|
438
|
|
|
case 8: |
|
439
|
|
|
$ret .= <<<EOT |
|
440
|
|
|
\$ret['{$rpFieldName}'] = XoopsUser::getUnameFromId(\$this->getVar('{$fieldName}'));\n |
|
441
|
|
|
EOT; |
|
442
|
|
|
break; |
|
443
|
|
|
/*case 10: |
|
|
|
|
|
|
444
|
|
|
$ret .= <<<EOT |
|
445
|
|
|
\$ret['{$rpFieldName}'] = XOOPS_ICONS32_URL .'/'. \$this->getVar('{$fieldName}');\n |
|
446
|
|
|
EOT; |
|
447
|
|
|
break; |
|
448
|
|
|
case 13: |
|
449
|
|
|
$ret .= <<<EOT |
|
450
|
|
|
\$ret['{$rpFieldName}'] = {$stuModuleDirname}_UPLOAD_IMAGE_URL .'/'. \$this->getVar('{$fieldName}');\n |
|
451
|
|
|
EOT; |
|
452
|
|
|
break;*/ |
|
453
|
|
|
case 15: |
|
454
|
|
|
$ret .= <<<EOT |
|
455
|
|
|
\$ret['{$rpFieldName}'] = formatTimeStamp(\$this->getVar('{$fieldName}'));\n |
|
456
|
|
|
EOT; |
|
457
|
|
|
break; |
|
458
|
|
|
default: |
|
459
|
|
|
if ($fieldElement > 15) { |
|
460
|
|
|
$fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement); |
|
|
|
|
|
|
461
|
|
|
$fieldElementMid = $fieldElements->getVar('fieldelement_mid'); |
|
462
|
|
|
$fieldElementTid = $fieldElements->getVar('fieldelement_tid'); |
|
463
|
|
|
$fieldElementName = $fieldElements->getVar('fieldelement_name'); |
|
464
|
|
|
$fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)); |
|
465
|
|
|
$topicTableName = str_replace(': ', '', strtolower($fieldNameDesc)); |
|
466
|
|
|
$fieldsTopics = $this->tdmcfile->getTableFields($fieldElementMid, $fieldElementTid); |
|
|
|
|
|
|
467
|
|
|
foreach (array_keys($fieldsTopics) as $f) { |
|
468
|
|
|
$fieldNameTopic = $fieldsTopics[$f]->getVar('field_name'); |
|
469
|
|
|
if (1 == $fieldsTopics[$f]->getVar('field_main')) { |
|
470
|
|
|
$fieldMainTopic = $fieldNameTopic; |
|
471
|
|
|
} |
|
472
|
|
|
} |
|
473
|
|
|
$ret .= <<<EOT |
|
474
|
|
|
\$ret['{$rpFieldName}'] = \$this->{$moduleDirname}->getHandler('{$topicTableName}')->get(\$this->getVar('{$fieldName}'))->getVar('{$fieldMainTopic}');\n |
|
|
|
|
|
|
475
|
|
|
EOT; |
|
476
|
|
|
} else { |
|
477
|
|
|
$ret .= <<<EOT |
|
478
|
|
|
\$ret['{$rpFieldName}'] = \$this->getVar('{$fieldName}');\n |
|
479
|
|
|
EOT; |
|
480
|
|
|
} |
|
481
|
|
|
break; |
|
482
|
|
|
} |
|
483
|
|
|
} |
|
484
|
|
|
$ret .= <<<EOT |
|
485
|
|
|
|
|
486
|
|
|
return \$ret; |
|
487
|
|
|
}\n\n |
|
488
|
|
|
EOT; |
|
489
|
|
|
|
|
490
|
|
|
return $ret; |
|
491
|
|
|
} |
|
492
|
|
|
/* |
|
493
|
|
|
* @private function getToArray |
|
494
|
|
|
* @param $table |
|
495
|
|
|
*/ |
|
496
|
|
|
/** |
|
497
|
|
|
* @return string |
|
498
|
|
|
*/ |
|
499
|
|
|
private function getToArrayInForm($table) |
|
500
|
|
|
{ |
|
501
|
|
|
$tableName = $table->getVar('table_name'); |
|
502
|
|
|
$ucfTableName = ucfirst($tableName); |
|
503
|
|
|
$ret = <<<EOT |
|
504
|
|
|
/** |
|
505
|
|
|
* Returns an array representation of the object |
|
506
|
|
|
* |
|
507
|
|
|
* @return array |
|
508
|
|
|
**/ |
|
509
|
|
|
public function toArray{$ucfTableName}() |
|
510
|
|
|
{ |
|
511
|
|
|
\$ret = array(); |
|
512
|
|
|
\$vars = \$this->getVars(); |
|
513
|
|
|
foreach( array_keys( \$vars ) as \$var ) { |
|
514
|
|
|
\$ret[\$var] = \$this->getVar( \$var ); |
|
515
|
|
|
} |
|
516
|
|
|
return \$ret; |
|
517
|
|
|
} |
|
518
|
|
|
}\n\n |
|
519
|
|
|
EOT; |
|
520
|
|
|
|
|
521
|
|
|
return $ret; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/* |
|
525
|
|
|
* @private function getOptionsCheck |
|
526
|
|
|
* @param $table |
|
527
|
|
|
*/ |
|
528
|
|
|
/** |
|
529
|
|
|
* @return string |
|
530
|
|
|
*/ |
|
531
|
|
|
private function getOptionsCheck($table) |
|
532
|
|
|
{ |
|
533
|
|
|
$tableName = $table->getVar('table_name'); |
|
534
|
|
|
$ucfTableName = ucfirst($tableName); |
|
535
|
|
|
$ret = <<<EOT |
|
536
|
|
|
/** |
|
537
|
|
|
* Get Options |
|
538
|
|
|
*/ |
|
539
|
|
|
public function getOptions{$ucfTableName}() |
|
540
|
|
|
{ |
|
541
|
|
|
\$ret = array();\n |
|
542
|
|
|
EOT; |
|
543
|
|
|
$fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
|
|
|
|
|
544
|
|
|
foreach (array_keys($fields) as $f) { |
|
545
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
546
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
547
|
|
|
// |
|
548
|
|
|
$fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement); |
|
|
|
|
|
|
549
|
|
|
$fieldElementId = $fieldElements->getVar('fieldelement_id'); |
|
550
|
|
|
$rpFieldName = $this->tdmcfile->getRightString($fieldName); |
|
|
|
|
|
|
551
|
|
|
if (5 == $fieldElementId) { |
|
552
|
|
|
$ret .= <<<EOT |
|
553
|
|
|
if(1 == \$this->getVar('{$fieldName}')) { |
|
554
|
|
|
array_push(\$ret, '{$rpFieldName}'); |
|
555
|
|
|
}\n |
|
556
|
|
|
EOT; |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
$ret .= <<<EOT |
|
560
|
|
|
return \$ret; |
|
561
|
|
|
} |
|
562
|
|
|
}\n\n |
|
563
|
|
|
EOT; |
|
564
|
|
|
|
|
565
|
|
|
return $ret; |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
/* |
|
569
|
|
|
* @public function getClassHandler |
|
570
|
|
|
* @param string $moduleDirname |
|
571
|
|
|
* @param string $tableName |
|
572
|
|
|
* @param string $fieldId |
|
573
|
|
|
* @param string $fieldMain |
|
574
|
|
|
*/ |
|
575
|
|
|
/** |
|
576
|
|
|
* @param $moduleDirname |
|
577
|
|
|
* @param $tableName |
|
578
|
|
|
* @param $tableCategory |
|
579
|
|
|
* @param $tableFieldname |
|
580
|
|
|
* @param $fieldId |
|
581
|
|
|
* @param $fieldMain |
|
582
|
|
|
* |
|
583
|
|
|
* @return string |
|
584
|
|
|
*/ |
|
585
|
|
|
private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldMain) |
|
586
|
|
|
{ |
|
587
|
|
|
$tableName = $table->getVar('table_name'); |
|
588
|
|
|
$tableCategory = $table->getVar('table_category'); |
|
|
|
|
|
|
589
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
590
|
|
|
$tableFieldname = $table->getVar('table_fieldname'); |
|
|
|
|
|
|
591
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
592
|
|
|
$ucfTableName = ucfirst($tableName); |
|
593
|
|
|
$ucfTableSoleName = ucfirst($tableSoleName); |
|
|
|
|
|
|
594
|
|
|
$ucfModuleTable = $ucfModuleDirname.$ucfTableName; |
|
595
|
|
|
$ret = <<<EOT |
|
596
|
|
|
/* |
|
597
|
|
|
* Class Object Handler {$ucfModuleDirname}{$ucfTableName} |
|
598
|
|
|
*/ |
|
599
|
|
|
class {$ucfModuleTable}Handler extends XoopsPersistableObjectHandler |
|
600
|
|
|
{ |
|
601
|
|
|
/* |
|
602
|
|
|
* @var mixed |
|
603
|
|
|
*/ |
|
604
|
|
|
private \${$moduleDirname} = null; |
|
605
|
|
|
/* |
|
606
|
|
|
* Constructor |
|
607
|
|
|
* |
|
608
|
|
|
* @param string \$db |
|
609
|
|
|
*/ |
|
610
|
|
|
public function __construct(&\$db) |
|
611
|
|
|
{ |
|
612
|
|
|
parent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}'); |
|
613
|
|
|
\$this->{$moduleDirname} = {$ucfModuleDirname}Helper::getInstance(); |
|
614
|
|
|
}\n\n |
|
615
|
|
|
EOT; |
|
616
|
|
|
|
|
617
|
|
|
return $ret; |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
/** |
|
621
|
|
|
* @public function getClassCreate |
|
622
|
|
|
* |
|
623
|
|
|
* @return string |
|
624
|
|
|
*/ |
|
625
|
|
|
private function getClassCreate() |
|
626
|
|
|
{ |
|
627
|
|
|
$ret = <<<EOT |
|
628
|
|
|
/** |
|
629
|
|
|
* @param bool \$isNew |
|
630
|
|
|
* |
|
631
|
|
|
* @return object |
|
632
|
|
|
*/ |
|
633
|
|
|
public function &create(\$isNew = true) |
|
634
|
|
|
{ |
|
635
|
|
|
return parent::create(\$isNew); |
|
636
|
|
|
}\n\n |
|
637
|
|
|
EOT; |
|
638
|
|
|
|
|
639
|
|
|
return $ret; |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* @public function getClassGet |
|
644
|
|
|
* |
|
645
|
|
|
* @return string |
|
646
|
|
|
*/ |
|
647
|
|
|
private function getClassGet() |
|
648
|
|
|
{ |
|
649
|
|
|
$ret = <<<EOT |
|
650
|
|
|
/** |
|
651
|
|
|
* retrieve a field |
|
652
|
|
|
* |
|
653
|
|
|
* @param int \$i field id |
|
654
|
|
|
* @return mixed reference to the {@link TDMCreateFields} object |
|
655
|
|
|
*/ |
|
656
|
|
|
public function &get(\$i = null, \$fields = null) |
|
657
|
|
|
{ |
|
658
|
|
|
return parent::get(\$i, \$fields); |
|
659
|
|
|
}\n\n |
|
660
|
|
|
EOT; |
|
661
|
|
|
|
|
662
|
|
|
return $ret; |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
/** |
|
666
|
|
|
* @public function getClassGetInsertId |
|
667
|
|
|
* |
|
668
|
|
|
* @return string |
|
669
|
|
|
*/ |
|
670
|
|
|
private function getClassGetInsertId() |
|
671
|
|
|
{ |
|
672
|
|
|
$ret = <<<EOT |
|
673
|
|
|
/** |
|
674
|
|
|
* get inserted id |
|
675
|
|
|
* |
|
676
|
|
|
* @param null |
|
677
|
|
|
* @return integer reference to the {@link TDMCreateFields} object |
|
678
|
|
|
*/ |
|
679
|
|
|
public function &getInsertId() |
|
680
|
|
|
{ |
|
681
|
|
|
return \$this->db->getInsertId(); |
|
682
|
|
|
}\n\n |
|
683
|
|
|
EOT; |
|
684
|
|
|
|
|
685
|
|
|
return $ret; |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
/** |
|
689
|
|
|
* @public function getClassGetIds |
|
690
|
|
|
* |
|
691
|
|
|
* @return string |
|
692
|
|
|
*/ |
|
693
|
|
|
private function getClassGetIds() |
|
694
|
|
|
{ |
|
695
|
|
|
$ret = <<<EOT |
|
696
|
|
|
/** |
|
697
|
|
|
* get IDs of objects matching a condition |
|
698
|
|
|
* |
|
699
|
|
|
* @param object \$criteria {@link CriteriaElement} to match |
|
700
|
|
|
* @return array of object IDs |
|
701
|
|
|
*/ |
|
702
|
|
|
public function &getIds(\$criteria) |
|
703
|
|
|
{ |
|
704
|
|
|
return parent::getIds(\$criteria); |
|
705
|
|
|
}\n\n |
|
706
|
|
|
EOT; |
|
707
|
|
|
|
|
708
|
|
|
return $ret; |
|
709
|
|
|
} |
|
710
|
|
|
|
|
711
|
|
|
/** |
|
712
|
|
|
* @public function getClassInsert |
|
713
|
|
|
* |
|
714
|
|
|
* @return string |
|
715
|
|
|
*/ |
|
716
|
|
|
private function getClassInsert() |
|
717
|
|
|
{ |
|
718
|
|
|
$ret = <<<EOT |
|
719
|
|
|
/** |
|
720
|
|
|
* insert a new field in the database |
|
721
|
|
|
* |
|
722
|
|
|
* @param object \$field reference to the {@link TDMCreateFields} object |
|
723
|
|
|
* @param bool \$force |
|
724
|
|
|
* |
|
725
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
726
|
|
|
*/ |
|
727
|
|
|
public function &insert(&\$field, \$force = false) |
|
728
|
|
|
{ |
|
729
|
|
|
if(!parent::insert(\$field, \$force)) { |
|
730
|
|
|
return false; |
|
731
|
|
|
} |
|
732
|
|
|
return true; |
|
733
|
|
|
}\n\n |
|
734
|
|
|
EOT; |
|
735
|
|
|
|
|
736
|
|
|
return $ret; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
/** |
|
740
|
|
|
* @public function getClassCounter |
|
741
|
|
|
* |
|
742
|
|
|
* @param $tableName |
|
743
|
|
|
* @param $fieldId |
|
744
|
|
|
* @param $fieldMain |
|
745
|
|
|
* |
|
746
|
|
|
* @return string |
|
747
|
|
|
*/ |
|
748
|
|
|
private function getClassCounter($tableName, $fieldId, $fieldMain) |
|
749
|
|
|
{ |
|
750
|
|
|
$ucfTableName = ucfirst($tableName); |
|
751
|
|
|
$ret = <<<EOT |
|
752
|
|
|
/** |
|
753
|
|
|
* Get Count {$ucfTableName} |
|
754
|
|
|
*/ |
|
755
|
|
|
public function getCount{$ucfTableName}(\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC') |
|
756
|
|
|
{ |
|
757
|
|
|
\$criteriaCount{$ucfTableName} = new CriteriaCompo(); |
|
758
|
|
|
\$criteriaCount{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order); |
|
759
|
|
|
return parent::getCount(\$criteriaCount{$ucfTableName}); |
|
760
|
|
|
}\n\n |
|
761
|
|
|
EOT; |
|
762
|
|
|
|
|
763
|
|
|
return $ret; |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
/** |
|
767
|
|
|
* @public function getClassAll |
|
768
|
|
|
* |
|
769
|
|
|
* @param $tableName |
|
770
|
|
|
* @param $fieldId |
|
771
|
|
|
* @param $fieldMain |
|
772
|
|
|
* |
|
773
|
|
|
* @return string |
|
774
|
|
|
*/ |
|
775
|
|
|
private function getClassAll($tableName, $fieldId, $fieldMain) |
|
776
|
|
|
{ |
|
777
|
|
|
$ucfTableName = ucfirst($tableName); |
|
778
|
|
|
$ret = <<<EOT |
|
779
|
|
|
/** |
|
780
|
|
|
* Get All {$ucfTableName} |
|
781
|
|
|
*/ |
|
782
|
|
|
public function getAll{$ucfTableName}(\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC') |
|
783
|
|
|
{ |
|
784
|
|
|
\$criteriaAll{$ucfTableName} = new CriteriaCompo(); |
|
785
|
|
|
\$criteriaAll{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order); |
|
786
|
|
|
return parent::getAll(\$criteriaAll{$ucfTableName}); |
|
787
|
|
|
}\n\n |
|
788
|
|
|
EOT; |
|
789
|
|
|
|
|
790
|
|
|
return $ret; |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
/** |
|
794
|
|
|
* @public function getClassByCategory |
|
795
|
|
|
* |
|
796
|
|
|
* @param $tableName |
|
797
|
|
|
* @param $fieldId |
|
798
|
|
|
* @param $fieldMain |
|
799
|
|
|
* @param $fieldParent |
|
800
|
|
|
* |
|
801
|
|
|
* @return string |
|
802
|
|
|
*/ |
|
803
|
|
|
private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement) |
|
804
|
|
|
{ |
|
805
|
|
|
$ucfTableName = ucfirst($tableName); |
|
806
|
|
|
$fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement); |
|
|
|
|
|
|
807
|
|
|
$fieldElementMid = $fieldElements->getVar('fieldelement_mid'); |
|
|
|
|
|
|
808
|
|
|
$fieldElementTid = $fieldElements->getVar('fieldelement_tid'); |
|
|
|
|
|
|
809
|
|
|
$fieldElementName = $fieldElements->getVar('fieldelement_name'); |
|
810
|
|
|
$fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName))); |
|
811
|
|
|
$topicTableName = str_replace(': ', '', $fieldNameDesc); |
|
812
|
|
|
$lcfTopicTableName = lcfirst($topicTableName); |
|
813
|
|
|
$ret = <<<EOT |
|
814
|
|
|
/** |
|
815
|
|
|
* Get All {$ucfTableName} By {$fieldNameDesc} Id |
|
816
|
|
|
*/ |
|
817
|
|
|
public function getAll{$ucfTableName}By{$fieldNameDesc}Id(\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC') |
|
818
|
|
|
{ |
|
819
|
|
|
\$gpermHandler =& xoops_gethandler('groupperm'); |
|
820
|
|
|
\${$lcfTopicTableName} = \$gpermHandler->getItemIds('{$moduleDirname}_view', \$GLOBALS['xoopsUser']->getGroups(), \$GLOBALS['xoopsModule']->getVar('mid') ); |
|
821
|
|
|
|
|
822
|
|
|
\$criteriaAll{$ucfTableName} = new CriteriaCompo();\n |
|
823
|
|
|
EOT; |
|
824
|
|
|
if (strstr($fieldName, 'status')) { |
|
825
|
|
|
$ret .= <<<EOT |
|
826
|
|
|
\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldName}', 0, '!='));\n |
|
827
|
|
|
EOT; |
|
828
|
|
|
} |
|
829
|
|
|
$ret .= <<<EOT |
|
830
|
|
|
\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldParent}', \${$tableFieldName}Id)); |
|
831
|
|
|
\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldId}', '(' . implode(',', \${$lcfTopicTableName}) . ')','IN')); |
|
832
|
|
|
\$criteriaAll{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order); |
|
833
|
|
|
return parent::getAll(\$criteriaAll{$ucfTableName}); |
|
834
|
|
|
}\n\n |
|
835
|
|
|
EOT; |
|
836
|
|
|
|
|
837
|
|
|
return $ret; |
|
838
|
|
|
} |
|
839
|
|
|
|
|
840
|
|
|
/** |
|
841
|
|
|
* @public function getClassCriteria |
|
842
|
|
|
* |
|
843
|
|
|
* @param $tableName |
|
844
|
|
|
* @param $fieldId |
|
845
|
|
|
* @param $fieldMain |
|
846
|
|
|
* |
|
847
|
|
|
* @return string |
|
848
|
|
|
*/ |
|
849
|
|
|
private function getClassCriteria($tableName) |
|
850
|
|
|
{ |
|
851
|
|
|
$ucfTableName = ucfirst($tableName); |
|
852
|
|
|
$ret = <<<EOT |
|
853
|
|
|
/** |
|
854
|
|
|
* Get {$ucfTableName} Criteria. |
|
855
|
|
|
*/ |
|
856
|
|
|
private function get{$ucfTableName}Criteria(\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order) |
|
857
|
|
|
{ |
|
858
|
|
|
\$criteria{$ucfTableName}->setStart(\$start); |
|
859
|
|
|
\$criteria{$ucfTableName}->setLimit(\$limit); |
|
860
|
|
|
\$criteria{$ucfTableName}->setSort(\$sort); |
|
861
|
|
|
\$criteria{$ucfTableName}->setOrder(\$order); |
|
862
|
|
|
|
|
863
|
|
|
return \$criteria{$ucfTableName}; |
|
864
|
|
|
}\n\n |
|
865
|
|
|
EOT; |
|
866
|
|
|
|
|
867
|
|
|
return $ret; |
|
868
|
|
|
} |
|
869
|
|
|
|
|
870
|
|
|
/** |
|
871
|
|
|
* @public function getClassGetTableSolenameById |
|
872
|
|
|
* |
|
873
|
|
|
* @param $moduleDirname |
|
874
|
|
|
* @param $table |
|
875
|
|
|
* |
|
876
|
|
|
* @return string |
|
877
|
|
|
*/ |
|
878
|
|
|
private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain) |
|
879
|
|
|
{ |
|
880
|
|
|
$tableName = $table->getVar('table_name'); |
|
881
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
882
|
|
|
$ucfTableSoleName = ucfirst($tableSoleName); |
|
883
|
|
|
$ret = <<<EOT |
|
884
|
|
|
/** |
|
885
|
|
|
* Returns the {$ucfTableSoleName} from id |
|
886
|
|
|
* |
|
887
|
|
|
* @return string |
|
888
|
|
|
**/ |
|
889
|
|
|
public function get{$ucfTableSoleName}FromId(\${$tableSoleName}Id) |
|
890
|
|
|
{ |
|
891
|
|
|
\${$tableSoleName}Id = (int) ( \${$tableSoleName}Id ); |
|
892
|
|
|
\${$tableSoleName} = ''; |
|
893
|
|
|
if(\${$tableSoleName}Id > 0) { |
|
894
|
|
|
\${$tableName}Handler = \$this->{$moduleDirname}->getHandler( '{$tableName}' ); |
|
895
|
|
|
\${$tableSoleName}Obj = & \${$tableName}Handler->get( \${$tableSoleName}Id ); |
|
896
|
|
|
if(is_object( \${$tableSoleName}Obj )) { |
|
897
|
|
|
\${$tableSoleName} = \${$tableSoleName}Obj->getVar( '{$fieldMain}' ); |
|
898
|
|
|
} |
|
899
|
|
|
} |
|
900
|
|
|
return \${$tableSoleName}; |
|
901
|
|
|
}\n |
|
902
|
|
|
EOT; |
|
903
|
|
|
|
|
904
|
|
|
return $ret; |
|
905
|
|
|
} |
|
906
|
|
|
|
|
907
|
|
|
/** |
|
908
|
|
|
* @public function getClassEnd |
|
909
|
|
|
*/ |
|
910
|
|
|
private function getClassEnd() |
|
911
|
|
|
{ |
|
912
|
|
|
$ret = <<<EOT |
|
913
|
|
|
}\n |
|
914
|
|
|
EOT; |
|
915
|
|
|
|
|
916
|
|
|
return $ret; |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
/* |
|
920
|
|
|
* @public function renderFile |
|
921
|
|
|
* @param string $filename |
|
922
|
|
|
*/ |
|
923
|
|
|
/** |
|
924
|
|
|
* @param $filename |
|
925
|
|
|
* |
|
926
|
|
|
* @return bool|string |
|
927
|
|
|
*/ |
|
928
|
|
|
public function renderFile($filename) |
|
929
|
|
|
{ |
|
930
|
|
|
$module = $this->getModule(); |
|
931
|
|
|
$table = $this->getTable(); |
|
932
|
|
|
$tableName = $table->getVar('table_name'); |
|
933
|
|
|
$tableFieldName = $table->getVar('table_fieldname'); |
|
934
|
|
|
$tableCategory = $table->getVar('table_category'); |
|
|
|
|
|
|
935
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
936
|
|
|
$fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
|
|
|
|
|
937
|
|
|
$fieldInForm = array(); |
|
938
|
|
|
$fieldParentId = array(); |
|
939
|
|
|
$fieldElementId = array(); |
|
940
|
|
|
foreach (array_keys($fields) as $f) { |
|
941
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
942
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
|
943
|
|
|
$fieldParentId[] = $fields[$f]->getVar('field_parent'); |
|
944
|
|
|
if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) { |
|
945
|
|
|
$fieldId = $fieldName; // $fieldId = fields parameter index field |
|
946
|
|
|
} |
|
947
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
948
|
|
|
$fieldMain = $fieldName; // $fieldMain = fields parameter main field |
|
949
|
|
|
} |
|
950
|
|
|
if (1 == $fields[$f]->getVar('field_parent')) { |
|
951
|
|
|
$fieldParent = $fieldName; // $fieldParent = fields parameter parent field |
|
952
|
|
|
} |
|
953
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
954
|
|
|
// |
|
955
|
|
|
$fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement); |
|
|
|
|
|
|
956
|
|
|
$fieldElementId[] = $fieldElements->getVar('fieldelement_id'); |
|
957
|
|
|
} |
|
958
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
959
|
|
|
$content .= $this->getHeadClass($moduleDirname, $tableName, $fields); |
|
960
|
|
|
if (in_array(1, $fieldInForm)) { |
|
961
|
|
|
$content .= $this->getHeadInForm($module, $table); |
|
962
|
|
|
if (1 == $table->getVar('table_permissions')) { |
|
963
|
|
|
$content .= $this->getPermissionsInForm($moduleDirname, $fieldId); |
|
|
|
|
|
|
964
|
|
|
} |
|
965
|
|
|
$content .= $this->getFootInForm(); |
|
966
|
|
|
} |
|
967
|
|
|
$content .= $this->getValuesInForm($moduleDirname, $table, $fields); |
|
968
|
|
|
$content .= $this->getToArrayInForm($table); |
|
969
|
|
|
if (in_array(5, $fieldElementId) > 1) { |
|
970
|
|
|
$content .= $this->getOptionsCheck($table); |
|
971
|
|
|
} |
|
972
|
|
|
$content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldMain); |
|
|
|
|
|
|
973
|
|
|
$content .= $this->getClassCreate(); |
|
974
|
|
|
$content .= $this->getClassGet(); |
|
975
|
|
|
$content .= $this->getClassGetInsertId(); |
|
976
|
|
|
$content .= $this->getClassGetIds(); |
|
977
|
|
|
$content .= $this->getClassInsert(); |
|
978
|
|
|
$content .= $this->getClassCounter($tableName, $fieldId, $fieldMain); |
|
979
|
|
|
$content .= $this->getClassAll($tableName, $fieldId, $fieldMain); |
|
980
|
|
|
$content .= $this->getClassCriteria($tableName); |
|
981
|
|
|
if (in_array(1, $fieldParentId) && $fieldElement > 15) { |
|
982
|
|
|
$content .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement); |
|
|
|
|
|
|
983
|
|
|
$content .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain); |
|
984
|
|
|
} |
|
985
|
|
|
$content .= $this->getClassEnd(); |
|
986
|
|
|
$this->tdmcfile->create($moduleDirname, 'class', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
|
|
|
|
|
987
|
|
|
|
|
988
|
|
|
return $this->tdmcfile->renderFile(); |
|
|
|
|
|
|
989
|
|
|
} |
|
990
|
|
|
} |
|
991
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.