Skip to content

Commit bc5a960

Browse files
committed
fixed bugs in getXoopsFormSelectFile and getClassGetTableSolenameById
1 parent a275a6f commit bc5a960

13 files changed

Lines changed: 152 additions & 96 deletions

File tree

_TODO.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ I moved files, where I do not know whether they are still needed into folder _ar
99

1010
TODOs:
1111

12-
check getXoopsFormSelectFile
13-
check getClassGetTableSolenameById
12+
implement constants interface
13+
14+
15+
1416

15-
Class PreloadsCore - still needed?
1617

1718
Notifications:
1819
there are too much notification, which are not needed/working

class/Files/Classes/ClassFormElements.php

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private function getXoopsFormHidden($fieldName)
213213

214214
/**
215215
* @private function getXoopsFormImageList
216+
* provides listbox for select image, a preview of image and an upload field
216217
*
217218
* @param $language
218219
* @param $moduleDirname
@@ -264,57 +265,63 @@ private function getXoopsFormImageList($language, $moduleDirname, $fieldName, $r
264265

265266
/**
266267
* @private function getXoopsFormSelectFile
268+
* provides listbox for select file and an upload field
267269
*
268270
* @param $language
269271
* @param $moduleDirname
272+
* @param $tableName
270273
* @param $fieldName
271274
* @param $required
272275
*
273276
* @return string
274277
*/
275-
private function getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $required = 'false')
278+
private function getXoopsFormSelectFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
276279
{
277-
$tf = Tdmcreate\Files\CreateFile::getInstance();
278-
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
279-
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
280-
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
281-
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
282-
$ucfFieldName = $tf->getCamelCase($fieldName, true);
283-
$t = "\t\t\t";
284-
$ret = $pc->getPhpCodeCommentLine('Form Frameworks', 'Image Files ' . $ucfFieldName, "\t\t");
285-
$contentIf = $xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, false, $t);
286-
$contentIf .= $pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '$get' . $ucfFieldName, "'blank.gif'", $t);
287-
$contentIf .= $xc->getXcEqualsOperator('$uploadDirectory', "'/uploads/{$moduleDirname}/images/shots'", null, false, $t);
288-
$contentIf .= $cc->getClassXoopsFormElementTray('imageTray', $language, '<br>', $t);
289-
$sprintf = $pc->getPhpCodeSprintf($language . 'FORM_PATH', '".{$uploadDirectory}/"');
290-
$contentIf .= $cc->getClassXoopsFormSelect('imageSelect', $sprintf, 'selected_image', "\${$moduleDirname}ShotImage", 5, 'false', false, $t);
291-
$contentIf .= $xc->getXcXoopsImgListArray('imageArray', 'XOOPS_ROOT_PATH . $uploadDirectory', $t);
292-
$contForeach = $cc->getClassAddOption('imageSelect', '"{$image1}", $image1', "\t");
293-
$contentIf .= $pc->getPhpCodeForeach('imageArray', false, false, 'image1', $contForeach, $t);
294-
$setExtraParam = "\"onchange='showImgSelected(\\\"imglabel_{$fieldName}\\\", \\\"selected_image\\\", \\\"\".\$uploadDirectory.\"\\\", \\\"\\\", \\\"\".XOOPS_URL.\"\\\")'\"";
295-
$contentIf .= $cc->getClassSetExtra('imageSelect', $setExtraParam, $t);
296-
$contentIf .= $cc->getClassAddElement('imageTray', '$imageSelect, false', $t);
297-
$paramLabel = "\"<br><img src='\".XOOPS_URL.\"/\".\$uploadDirectory.\"/\" . \${$moduleDirname}ShotImage . \"' name='imglabel_{$fieldName}' id='imglabel_{$fieldName}' alt='' style='max-width:100px' />\\\"";
298-
$xoopsFormLabel = $cc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
299-
$contentIf .= $cc->getClassAddElement('imageTray', $xoopsFormLabel, $t);
300-
$contentIf .= $pc->getPhpCodeCommentLine('Form', 'File', "\t\t");
301-
$contentIf .= $cc->getClassXoopsFormElementTray('fileSelectTray', "''", '<br>', $t);
302-
$getConfigFile = $xc->getXcGetConfig('maxuploadsize');
303-
$xoopsFormFile = $cc->getClassXoopsFormFile('', $language . '_FORM_UPLOAD', $fieldName, $getConfigFile, true, '');
304-
$contentIf1 = $cc->getClassAddElement('fileSelectTray', $xoopsFormFile . $required, $t . "\t");
305-
306-
$contentIf .= $cc->getClassAddElement('imageTray', '$fileSelectTray', $t);
307-
$contentIf .= $cc->getClassAddElement('form', "\$imageTray{$required}", $t);
308-
309-
$contentIf = $pc->getPhpCodeConditions('$permissionUpload', ' == ', 'true', $contentIf1, false, $t);
310-
$getConfig = $xc->getXcGetConfig('useshots');
311-
$ret .= $pc->getPhpCodeConditions($getConfig, null, null, $contentIf, false, "\t\t");
280+
$tf = Tdmcreate\Files\CreateFile::getInstance();
281+
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
282+
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
283+
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
284+
$ucfFieldName = $tf->getCamelCase($fieldName, true);
285+
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
286+
$languageShort = substr($language, 0, 4) . mb_strtoupper($moduleDirname) . '_';
287+
$t = "\t\t";
288+
$ret = $pc->getPhpCodeCommentLine('Form', 'File ' . $ucfFieldName, $t);
289+
$ret .= $pc->getPhpCodeCommentLine("Form File {$ucfFieldName}:", 'Select Uploaded File ', $t);
290+
$ret .= $xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, false, $t);
291+
$ret .= $pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '$get' . $ucfFieldName, "'blank.gif'", $t);
292+
$ret .= $xc->getXcEqualsOperator('$fileDirectory', "'/uploads/{$moduleDirname}/files/{$tableName}'", null, false, $t);
293+
$ret .= $cc->getClassXoopsFormElementTray('fileTray', $language, '<br>', $t);
294+
$sprintf = $pc->getPhpCodeSprintf($language . '_UPLOADS', '".{$fileDirectory}/"');
295+
$ret .= $cc->getClassXoopsFormSelect('fileSelect', $sprintf, $fieldName, $ccFieldName, 5, 'false', false, $t);
296+
$ret .= $xc->getXcXoopsImgListArray('fileArray', 'XOOPS_ROOT_PATH . $fileDirectory', $t);
297+
$contForeach = $cc->getClassAddOption('fileSelect', '"{$file1}", $file1', "\t");
298+
$ret .= $pc->getPhpCodeForeach('fileArray', false, false, 'file1', $contForeach, $t);
299+
//TODO: make preview for images or show "no preview possible"
300+
//$setExtraParam = "\"onchange='showImgSelected(\\\"filelabel_{$fieldName}\\\", \\\"{$fieldName}\\\", \\\"\".\$fileDirectory.\"\\\", \\\"\\\", \\\"\".XOOPS_URL.\"\\\")'\"";
301+
//$ret .= $cc->getClassSetExtra('fileSelect', $setExtraParam, $t);
302+
$ret .= $cc->getClassAddElement('fileTray', '$fileSelect, false', $t);
303+
//$paramLabel = "\"<br><img src='\".XOOPS_URL.\"/\".\$fileDirectory.\"/\".\${$ccFieldName}.\"' name='filelabel_{$fieldName}' id='filelabel_{$fieldName}' alt='' style='max-width:100px' />\"";
304+
//$xoopsFormLabel = $cc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
305+
//$ret .= $cc->getClassAddElement('fileTray', $xoopsFormLabel, $t);
306+
$ret .= $pc->getPhpCodeCommentLine("Form File {$ucfFieldName}:", 'Upload new file', $t);
307+
$getConfigSize = $xc->getXcGetConfig('maxsize_file');
308+
$contIf = $xc->getXcEqualsOperator('$maxsize', $getConfigSize,'', '', "\t\t\t");
309+
$xoopsFormFile = $cc->getClassXoopsFormFile('fileTray', "'<br>' . " . $languageShort . 'FORM_UPLOAD_NEW', $fieldName, '$maxsize', true, '');
310+
$contIf .= $cc->getClassAddElement('fileTray', $xoopsFormFile, $t . "\t");
311+
$configText = "(\$maxsize / 1048576) . ' ' . " . $languageShort . 'FORM_UPLOAD_SIZE_MB';
312+
$labelInfo1 = $cc->getClassXoopsFormLabel('', $languageShort . 'FORM_UPLOAD_SIZE', $configText, true, '');
313+
$contIf .= $cc->getClassAddElement('fileTray', $labelInfo1, $t . "\t");
314+
$formHidden = $cc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, $t, true);
315+
$contElse = $cc->getClassAddElement('fileTray', $formHidden, $t . "\t");
316+
$ret .= $pc->getPhpCodeConditions('$permissionUpload', null, null, $contIf, $contElse, "\t\t");
317+
$ret .= $cc->getClassAddElement('form', "\$fileTray, {$required}", $t);
312318

313319
return $ret;
314320
}
315321

316322
/**
317323
* @private function getXoopsFormUrlFile
324+
* provides textbox with last uploaded url and an upload field
318325
*
319326
* @param $language
320327
* @param $moduleDirname
@@ -349,6 +356,7 @@ private function getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fie
349356

350357
/**
351358
* @private function getXoopsFormUploadImage
359+
* provides listbox for select image, a preview of image and an upload field
352360
*
353361
* @param $language
354362
* @param $moduleDirname
@@ -384,7 +392,7 @@ private function getXoopsFormUploadImage($language, $moduleDirname, $tableName,
384392
$paramLabel = "\"<br><img src='\".XOOPS_URL.\"/\".\$imageDirectory.\"/\".\${$ccFieldName}.\"' name='imglabel_{$fieldName}' id='imglabel_{$fieldName}' alt='' style='max-width:100px' />\"";
385393
$xoopsFormLabel = $cc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
386394
$ret .= $cc->getClassAddElement('imageTray', $xoopsFormLabel, $t);
387-
$ret .= $pc->getPhpCodeCommentLine("Form Image {$ucfFieldName}:", 'Upload Image', $t);
395+
$ret .= $pc->getPhpCodeCommentLine("Form Image {$ucfFieldName}:", 'Upload new image', $t);
388396
$getConfigSize = $xc->getXcGetConfig('maxsize_image');
389397
$contIf = $xc->getXcEqualsOperator('$maxsize', $getConfigSize,'', '', "\t\t\t");
390398
$xoopsFormFile = $cc->getClassXoopsFormFile('imageTray', "'<br>' . " . $languageShort . 'FORM_UPLOAD_NEW', $fieldName, '$maxsize', true, '');
@@ -401,13 +409,14 @@ private function getXoopsFormUploadImage($language, $moduleDirname, $tableName,
401409
$formHidden = $cc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, $t, true);
402410
$contElse = $cc->getClassAddElement('imageTray', $formHidden, $t . "\t");
403411
$ret .= $pc->getPhpCodeConditions('$permissionUpload', null, null, $contIf, $contElse, "\t\t");
404-
$ret .= $cc->getClassAddElement('form', "\$imageTray{$required}", $t);
412+
$ret .= $cc->getClassAddElement('form', "\$imageTray, {$required}", $t);
405413

406414
return $ret;
407415
}
408416

409417
/**
410418
* @private function getXoopsFormUploadFile
419+
* provides label with last uploaded file and an upload field
411420
*
412421
* @param $language
413422
* @param $moduleDirname
@@ -416,7 +425,7 @@ private function getXoopsFormUploadImage($language, $moduleDirname, $tableName,
416425
*
417426
* @return string
418427
*/
419-
private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName)
428+
private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
420429
{
421430
$tf = Tdmcreate\Files\CreateFile::getInstance();
422431
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
@@ -441,7 +450,7 @@ private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $
441450
$configText = "(\$maxsize / 1048576) . ' ' . " . $languageShort . 'FORM_UPLOAD_SIZE_MB';
442451
$labelInfo1 = $cc->getClassXoopsFormLabel('', $languageShort . 'FORM_UPLOAD_SIZE', $configText, true, '');
443452
$uForm .= $cc->getClassAddElement('fileUploadTray', $labelInfo1, $t );
444-
$uForm .= $cc->getClassAddElement('form', '$fileUploadTray', $t);
453+
$uForm .= $cc->getClassAddElement('form', "\$fileUploadTray, {$required}", $t);
445454
$formHidden = $cc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, "\t\t", true);
446455
$contElse = $cc->getClassAddElement('form', $formHidden, $t);
447456

@@ -748,7 +757,7 @@ public function renderElements()
748757
$ret .= $this->getXoopsFormImageList($language, $moduleDirname, $fieldName, $required);
749758
break;
750759
case 11:
751-
$ret .= $this->getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $required);
760+
$ret .= $this->getXoopsFormSelectFile($language, $moduleDirname, $tableName, $fieldName, $required);
752761
break;
753762
case 12:
754763
$ret .= $this->getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $required);

class/Files/Classes/ClassHandlerFiles.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,16 @@ private function getClassGetTableSolenameById($table, $fieldMain)
307307
$tableSoleName = $table->getVar('table_solename');
308308
$ucfTableSoleName = ucfirst($tableSoleName);
309309
$ccTableSoleName = $this->getCamelCase($tableSoleName, true);
310+
310311
$ret = $pc->getPhpCodeCommentMultiLine(['Returns the' => $ucfTableSoleName . ' from id', '' => '', '@return' => 'string'], "\t");
311312
$soleName = $xc->getXcEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t");
312313
$soleName .= $xc->getXcEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t");
313-
314-
$contentIf = $xc->getXoopsHandlerLine($tableName, "\t\t\t");
315-
$contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
316-
$getVar = $xc->getXcGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
317-
$contentIf .= $pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
318-
319-
$soleName .= $pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t");
320-
$soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
314+
$contentIf = $xc->getXoopsHandlerLine($tableName, "\t\t\t");
315+
$contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
316+
$getVar = $xc->getXcGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
317+
$contentIf .= $pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
318+
$soleName .= $pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf, false, "\t\t");
319+
$soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
321320

322321
$ret .= $pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t");
323322

class/Files/Classes/ClassSpecialFiles.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,47 @@ public function renderConstants()
249249

250250
return $this->renderFile();
251251
}
252+
/*
253+
public function renderConstantsTestInterface()
254+
{
255+
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
256+
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
257+
258+
$module = $this->getModule();
259+
$filename = $this->getFileName();
260+
$tables = $this->getTables();
261+
$tablePermissions = [];
262+
foreach (array_keys($tables) as $t) {
263+
$tablePermissions[] = $tables[$t]->getVar('table_permissions');
264+
}
265+
$moduleDirname = $module->getVar('mod_dirname');
266+
$namespace = $pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]);
267+
$contentFile = $this->getHeaderFilesComments($module, $this->className, null, $namespace);
268+
$contentFile .= $pc->getPhpCodeDefined();
269+
$contentFile .= $pc->getPhpCodeCommentMultiLine(['Interface ' => $this->className]);
270+
$contentClass = '';
271+
if (in_array(1, $tablePermissions)) {
272+
$constPerm = $pc->getBlankLine();
273+
$constPerm .= $pc->getPhpCodeCommentLine('Constants for permissions', '', "\t");
274+
$constPerm .= $pc->getPhpCodeConstant("PERM_GLOBAL_NONE ", 0, 'protected static',"\t");
275+
$constPerm .= $pc->getPhpCodeConstant("PERM_GLOBAL_VIEW ", 1, 'protected static',"\t");
276+
$constPerm .= $pc->getPhpCodeConstant("PERM_GLOBAL_SUBMIT ", 2, 'protected static',"\t");
277+
$constPerm .= $pc->getPhpCodeConstant("PERM_GLOBAL_APPROVE", 3, 'protected static',"\t");
278+
$contentClass .= $constPerm;
279+
}
280+
$contentClass .= $pc->getBlankLine();
281+
$func = $pc->getPhpCodeCommentLine('trigger a warning if invalid "constant" requested', '', "\t\t");
282+
$if = $pc->getPhpCodeTriggerError("\"Invalid Constant requested ('{\$val}')\"", 'E_USER_WARNING', "\t\t\t");
283+
$if .= $this->getSimpleString("return false;", "\t\t\t");
284+
$func .= $pc->getPhpCodeConditions('!isset($$val)', null, null, $if, false, "\t\t");
285+
$func .= $this->getSimpleString('return self::$$val;', "\t");
286+
$contentClass .= $pc->getPhpCodeFunction('getConstant', '$val', $func, 'final public static ', false, "\t");
287+
288+
$contentFile .= $pc->getPhpCodeInterface($this->className, $contentClass);
289+
290+
$this->create($moduleDirname, 'class', $filename, $contentFile, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
291+
292+
return $this->renderFile();
293+
}
294+
*/
252295
}

class/Files/CreatePhpCode.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,27 @@ public function getPhpCodeVariableClass($type = 'private', $name = null, $assign
278278
return "{$t}{$type} \${$name} = {$assign};\n";
279279
}
280280

281+
/**
282+
* @public function getPhpCodeInstance
283+
* @param $name
284+
* @param $content
285+
* @param $extends
286+
* @param $type
287+
*
288+
* @return string
289+
*/
290+
public function getPhpCodeInterface($name = null, $content = null, $extends = null, $type = null)
291+
{
292+
$typ = (null != $type) ? "{$type} " : '';
293+
$ext = (null != $extends) ? " extends {$extends}" : '';
294+
$ret = "{$typ}interface {$name}{$ext}\n";
295+
$ret .= '{';
296+
$ret .= $content;
297+
$ret .= "}\n";
298+
299+
return $ret;
300+
}
301+
281302
/**
282303
* @public function getPhpCodeFunction
283304
* @param $name
@@ -801,8 +822,22 @@ public function getBlankLine()
801822
* @param string $t
802823
* @return string
803824
*/
804-
public function getPhpCodeConstant($const, $value, $t ='')
825+
public function getPhpCodeConstant($const, $value, $t = '', $type = 'const')
826+
{
827+
return "{$t}{$type} {$const} = {$value};\n";
828+
}
829+
830+
/**
831+
* @public function getPhpCodeTriggerError
832+
*
833+
* @param $msg
834+
* @param $type
835+
* @param string $t
836+
* @return string
837+
*/
838+
public function getPhpCodeTriggerError($msg, $type, $t ='')
805839
{
806-
return "{$t}const {$const} = {$value};\n";
840+
$ret = "{$t}trigger_error($msg, {$type});\n";
841+
return $ret;
807842
}
808843
}

class/Files/CreateXoopsCode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,10 @@ public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $f
14421442
$ret .= $axCodeSaveElements->getAxcImageListSetVar($tableName, $fieldName, $t, $countUploader);
14431443
$countUploader++;
14441444
break;
1445+
case 11:
1446+
$ret .= $axCodeSaveElements->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain);
1447+
$countUploader++;
1448+
break;
14451449
case 12:
14461450
$ret .= $axCodeSaveElements->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName, true, $t, $countUploader, $fieldMain);
14471451
$countUploader++;

0 commit comments

Comments
 (0)