$level1Setting) {
if (!empty($level1Setting)) {
$content0[] = genLevel1($level1Setting, $appView);
} else {
$content0[] = __('No Settings available yet');
}
}
$tabsOptions0 = [
// 'vertical' => true,
// 'vertical-size' => 2,
'card' => false,
'pills' => false,
'justify' => 'center',
'content-class' => ['mt-2'],
'data' => [
'navs' => $level0,
'content' => $content0
]
];
$table0 = $appView->Bootstrap->tabs($tabsOptions0);
return $table0;
}
function genLevel1($level1Setting, $appView)
{
$content1 = [];
$nav1 = [];
foreach ($level1Setting as $level2Name => $level2Setting) {
if (!empty($level2Setting)) {
$content1[] = genLevel2($level2Name, $level2Setting, $appView);
} else {
$content1[] = '';
}
$nav1[$level2Name] = array_filter( // only show grouped settings
array_keys($level2Setting),
function ($settingGroupName) use ($level2Setting) {
return !isLeaf($level2Setting[$settingGroupName]);
}
);
}
$contentHtml = implode('', $content1);
$scrollspyNav = genScrollspyNav($nav1);
$mainPanelHeight = 'calc(100vh - 8px - 42px - 1rem - 56px - 38px - 1rem)';
$container = '';
$container .= "
{$scrollspyNav}
";
$container .= "
{$contentHtml}
";
$container .= '
';
return $container;
}
function genLevel2($level2Name, $level2Setting, $appView)
{
foreach ($level2Setting as $level3Name => $level3Setting) {
if (!empty($level3Setting)) {
$level3 = genLevel3($level2Name, $level3Name, $level3Setting, $appView);
$content2[] = sprintf('%s
', sprintf('sp-%s', h($level2Name)), $level3);
} else {
$content2[] = '';
}
}
return implode('', $content2);
}
function genLevel3($level2Name, $settingGroupName, $setting, $appView)
{
$settingGroup = '';
if (isLeaf($setting)) {
$tmp = genSingleSetting($settingGroupName, $setting, $appView);
$settingGroup = "{$tmp}
";
} else {
$tmpID = sprintf('sp-%s-%s', h($level2Name), h($settingGroupName));
$settingGroup .= sprintf('', $tmpID, $tmpID, h($settingGroupName));
foreach ($setting as $singleSettingName => $singleSetting) {
$tmp = genSingleSetting($singleSettingName, $singleSetting, $appView);
$settingGroup .= sprintf('%s
', $tmp);
}
$settingGroup = $appView->Bootstrap->genNode('div', [
'class' => ['shadow', 'p-2', 'mb-4', 'rounded', ($appView->get('darkMode') ? 'bg-dark' : 'bg-light')],
], $settingGroup);
}
return $settingGroup;
}
function genSingleSetting($settingName, $setting, $appView)
{
$label = $appView->Bootstrap->genNode('label', [
'class' => ['font-weight-bolder', 'mb-0'],
'for' => $settingName
], h($setting['name']));
$description = '';
if (!empty($setting['description'])) {
$description = $appView->Bootstrap->genNode('small', [
'class' => ['form-text', 'text-muted', 'mt-0'],
'id' => "{$settingName}Help"
], h($setting['description']));
}
$inputGroup = '';
if (empty($setting['type'])) {
$setting['type'] = 'string';
}
if ($setting['type'] == 'string') {
$input = genInputString($settingName, $setting, $appView);
} elseif ($setting['type'] == 'boolean') {
$input = genInputCheckbox($settingName, $setting, $appView);
$description = '';
} elseif ($setting['type'] == 'integer') {
$input = genInputInteger($settingName, $setting, $appView);
} elseif ($setting['type'] == 'select') {
$input = genInputSelect($settingName, $setting, $appView);
} elseif ($setting['type'] == 'multi-select') {
$input = genInputMultiSelect($settingName, $setting, $appView);
} else {
$input = genInputString($settingName, $setting, $appView);
}
$container = $appView->Bootstrap->genNode('div', [
'class' => ['form-group', 'mb-2']
], implode('', [$label, $input, $description]));
return $container;
}
function genInputString($settingName, $setting, $appView)
{
return $appView->Bootstrap->genNode('input', [
'class' => [
'form-control'
],
'type' => 'text',
'id' => $settingName,
'value' => isset($setting['value']) ? $setting['value'] : "",
'aria-describedby' => "{$settingName}Help"
]);
}
function genInputCheckbox($settingName, $setting, $appView)
{
$switch = $appView->Bootstrap->genNode('input', [
'class' => [
'custom-control-input'
],
'type' => 'checkbox',
'value' => !empty($setting['value']) ? 1 : 0,
'checked' => !empty($setting['value']) ? 'checked' : '',
'id' => $settingName,
]);
$label = $appView->Bootstrap->genNode('label', [
'class' => [
'custom-control-label'
],
'for' => $settingName,
], h($setting['description']));
$container = $appView->Bootstrap->genNode('div', [
'class' => [
'custom-control',
'custom-switch',
],
], implode('', [$switch, $label]));
return $container;
}
function genInputInteger($settingName, $setting, $appView)
{
return $appView->Bootstrap->genNode('input', [
'class' => [
'form-control'
],
'params' => [
'type' => 'integer',
'id' => $settingName,
'aria-describedby' => "{$settingName}Help"
]
]);
}
function genInputSelect($settingName, $setting, $appView)
{
}
function genInputMultiSelect($settingName, $setting, $appView)
{
}
function genScrollspyNav($nav1)
{
$nav = '';
return $nav;
}
function isLeaf($setting)
{
return !empty($setting['name']) && !empty($setting['type']);
}
?>