Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion class/Files/CreateXoopsCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -1800,22 +1800,26 @@ public function getXcCommonPagesNew($tableName, string $t = ''): string
/**
* @public function getXcCommonPagesClone
* @param $tableName
* @param $fieldId
* @param $ccFieldId
* @param string $t
* @param string $language
* @return string
*/
public function getXcCommonPagesClone($tableName, $ccFieldId, string $t = '', string $language = ''): string
public function getXcCommonPagesClone($tableName, $fieldId, $ccFieldId, string $t = '', string $language = ''): string
{
$pc = Modulebuilder\Files\CreatePhpCode::getInstance();
$xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
$cf = Modulebuilder\Files\CreateFile::getInstance();

$ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t");
$ret .= $xc->getXcHandlerGet($tableName, $ccFieldId . 'Source', 'ObjSource', $tableName . 'Handler', false, $t);
$tablenameObj = $pc->getPhpCodeIsobject($tableName . 'ObjSource');
$redirectError = $xc->getXcRedirectHeader($tableName, '', '3', "{$language}INVALID_PARAM", true, $t . "\t");
$ret .= $pc->getPhpCodeConditions('!' . $tablenameObj, '', '', $redirectError, false, $t);
$ret .= $xc->getXcEqualsOperator('$' . $tableName . 'Obj', '$' . $tableName . 'ObjSource->xoopsClone()', null, $t);
$ret .= $cf->getSimpleString('$' . $tableName . 'Obj->setNew();', "\t\t");
$ret .= $this->getXcSetVarObj($tableName, $fieldId, 0, "\t\t");
Comment on lines +1813 to +1822
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instantiating the heavy CreateFile class just to call getSimpleString() (which simply appends a newline) is highly inefficient. Instead, we can use direct string interpolation. Additionally, the indentation parameter $t should be used instead of hardcoding "\t\t" to ensure consistent code generation.

        $ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t");
        $ret .= $xc->getXcHandlerGet($tableName, $ccFieldId . 'Source', 'ObjSource', $tableName . 'Handler', false, $t);
        $tablenameObj       = $pc->getPhpCodeIsobject($tableName . 'ObjSource');
        $redirectError      = $xc->getXcRedirectHeader($tableName, '', '3', "{$language}INVALID_PARAM", true, $t . "\t");
        $ret                .= $pc->getPhpCodeConditions('!' . $tablenameObj, '', '', $redirectError, false, $t);
        $ret .= $xc->getXcEqualsOperator('$' . $tableName . 'Obj', '$' . $tableName . 'ObjSource->xoopsClone()', null, $t);
        $ret .= "{$t}\${$tableName}Obj->setNew();\n";
        $ret .= $this->getXcSetVarObj($tableName, $fieldId, 0, $t);

$ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
$ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);

Expand Down
2 changes: 1 addition & 1 deletion class/Files/User/UserPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public function getUserPagesClone($tableName, $tableSoleName, $tablePermissions,
$ret .= $this->pc->getPhpCodeCommentLine('Check params', '', $t);
$contIf = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
$ret .= $this->pc->getPhpCodeConditions("\${$ccFieldId}Source", ' == ', '0', $contIf, false, $t);
$ret .= $this->xc->getXcCommonPagesClone($tableName, $ccFieldId, $t, $language);
$ret .= $this->xc->getXcCommonPagesClone($tableName, $fieldId, $ccFieldId, $t, $language);

return $ret;
}
Expand Down
2 changes: 1 addition & 1 deletion class/Files/admin/AdminPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private function getAdminPagesClone($moduleDirname, $tableName, $tableSoleName,
$contIf = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
$ret .= $this->pc->getPhpCodeConditions("\${$ccFieldId}Source", ' === ', '0', $contIf, false, $t);

$ret .= $this->xc->getXcCommonPagesClone($tableName, $ccFieldId, $t, $language);
$ret .= $this->xc->getXcCommonPagesClone($tableName, $fieldId, $ccFieldId, $t, $language);

return $ret;
}
Expand Down