Skip to content

Commit 8dd6958

Browse files
committed
implemented constants for radio on-/offline
1 parent 2bc9475 commit 8dd6958

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

class/Files/Classes/ClassFiles.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,10 @@ private function getValuesInObject($moduleDirname, $table, $fields)
449449
break;
450450
case Constants::FIELD_ELE_RADIO_ONOFFLINE:
451451
$spacer = str_repeat(' ', \max(0, $lenMaxName - 5 - \mb_strlen($rpFieldName)));
452-
$offline = $language . \mb_strtoupper($ucfTableName) . '_' . \mb_strtoupper($rpFieldName) . '_OFFLINE';
453-
$online = $language . \mb_strtoupper($ucfTableName) . '_' . \mb_strtoupper($rpFieldName) . '_ONLINE';
454-
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_text']{$spacer}", "(int)\$this->getVar('{$fieldName}') > 0 ? $online : $offline", false, "\t\t");
452+
$defaultRO = $this->xc->getXcGetConstants('RADIO_OFFLINE');
453+
$offlineRO = $language . \mb_strtoupper($ucfTableName) . '_' . \mb_strtoupper($rpFieldName) . '_OFFLINE';
454+
$onlineRO = $language . \mb_strtoupper($ucfTableName) . '_' . \mb_strtoupper($rpFieldName) . '_ONLINE';
455+
$getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_text']{$spacer}", "(int)\$this->getVar('{$fieldName}') > $defaultRO ? $onlineRO : $offlineRO", false, "\t\t");
455456
break;
456457
case Constants::FIELD_ELE_SELECTUSER:
457458
$spacer = str_repeat(' ', \max(0, $lenMaxName - 5 - \mb_strlen($rpFieldName)));

class/Files/Classes/ClassFormElements.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,10 @@ private function getXoopsFormRadioOnoffline($language, $fieldName, $required = '
743743
$ret = $this->pc->getPhpCodeCommentLine('Form Radio on-/offline', $ccFieldName, $t);
744744
$ret .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '0', "\$this->getVar('{$fieldName}')", $t);
745745
$ret .= $this->cxc->getClassXoopsFormRadio($ccFieldName . 'Select', $language, $fieldName, "{$ccFieldName}", false, $t);
746-
$ret .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'0', {$language}_OFFLINE", $t);
747-
$ret .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'1', {$language}_ONLINE", $t);
746+
$param = $this->xc->getXcGetConstants('RADIO_OFFLINE');
747+
$ret .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "{$param}, {$language}_OFFLINE", $t);
748+
$param = $this->xc->getXcGetConstants('RADIO_ONLINE');
749+
$ret .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "{$param}, {$language}_ONLINE", $t);
748750
$ret .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
749751

750752
return $ret;

class/Files/Classes/ClassSpecialFiles.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace XoopsModules\Modulebuilder\Files\Classes;
44

55
use XoopsModules\Modulebuilder;
6-
use XoopsModules\Modulebuilder\Files;
6+
use XoopsModules\Modulebuilder\{
7+
Files,
8+
Constants
9+
};
710

811
/*
912
You may not change or alter any portion of this comment or credits
@@ -224,11 +227,27 @@ public function renderConstantsInterface()
224227
$module = $this->getModule();
225228
$filename = $this->getFileName();
226229
$tables = $this->getTables();
227-
$tablePermissions = [];
228-
$tableRate = [];
230+
231+
232+
$tablePermissions = [];
233+
$tableRate = [];
234+
$hasRadioOnoffline = false;
235+
$hasSelectStatus = false;
229236
foreach (\array_keys($tables) as $t) {
230237
$tablePermissions[] = $tables[$t]->getVar('table_permissions');
231238
$tableRate[] = $tables[$t]->getVar('table_rate');
239+
$fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id'));
240+
foreach (\array_keys($fields) as $f) {
241+
$fieldElement = $fields[$f]->getVar('field_element');
242+
switch ($fieldElement) {
243+
case Constants::FIELD_ELE_RADIO_ONOFFLINE:
244+
$hasRadioOnoffline = true;
245+
break;
246+
case Constants::FIELD_ELE_SELECTSTATUS:
247+
$hasSelectStatus = true;
248+
break;
249+
}
250+
}
232251
}
233252
$moduleDirname = $module->getVar('mod_dirname');
234253
$namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]);
@@ -243,13 +262,21 @@ public function renderConstantsInterface()
243262
$contentClass .= $this->pc->getPhpCodeConstant('TABLE_' . $stuTableName, $t, "\t", 'public const');
244263
}
245264

246-
$contentClass .= $this->pc->getPhpCodeBlankLine();
247-
$contentClass .= $this->pc->getPhpCodeCommentLine('Constants for status', '', "\t");
248-
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_NONE ', 0, "\t", 'public const');
249-
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_OFFLINE ', 1, "\t", 'public const');
250-
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_SUBMITTED', 2, "\t", 'public const');
251-
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_APPROVED ', 3, "\t", 'public const');
252-
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_BROKEN ', 4, "\t", 'public const');
265+
if ($hasSelectStatus) {
266+
$contentClass .= $this->pc->getPhpCodeBlankLine();
267+
$contentClass .= $this->pc->getPhpCodeCommentLine('Constants for status', '', "\t");
268+
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_NONE ', 0, "\t", 'public const');
269+
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_OFFLINE ', 1, "\t", 'public const');
270+
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_SUBMITTED', 2, "\t", 'public const');
271+
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_APPROVED ', 3, "\t", 'public const');
272+
$contentClass .= $this->pc->getPhpCodeConstant('STATUS_BROKEN ', 4, "\t", 'public const');
273+
}
274+
if ($hasRadioOnoffline) {
275+
$contentClass .= $this->pc->getPhpCodeBlankLine();
276+
$contentClass .= $this->pc->getPhpCodeCommentLine('Constants for radio on-/offline', '', "\t");
277+
$contentClass .= $this->pc->getPhpCodeConstant('RADIO_OFFLINE', 0, "\t", 'public const');
278+
$contentClass .= $this->pc->getPhpCodeConstant('RADIO_ONLINE ', 1, "\t", 'public const');
279+
}
253280
if (\in_array(1, $tablePermissions)) {
254281
$constPerm = $this->pc->getPhpCodeBlankLine();
255282
$constPerm .= $this->pc->getPhpCodeCommentLine('Constants for permissions', '', "\t");

0 commit comments

Comments
 (0)