Example #1
0
 private static function combineParamsFromDB($table, array $order_keys)
 {
     // Fields from DB
     $fields = $types = SQL::getFieldsWithAllData($table);
     unset($fields['id']);
     // Sort to match defined order for form
     $sorted = $not_sorted = [];
     foreach ($fields as $k => $v) {
         if (($key = array_search($k, $order_keys)) !== false) {
             $sorted[$key] = $k;
         } else {
             $not_sorted[] = $k;
         }
     }
     ksort($sorted);
     $fields = array_merge($sorted, $not_sorted);
     $params = [];
     foreach ($fields as $v) {
         $field = [];
         $type = $types[$v]['Type'];
         if (strpos($type, 'text') !== false) {
             $field['type'] = 'textarea';
         }
         if (strpos($type, 'enum') !== false) {
             $field['type'] = 'select';
             $field['options'] = SQL::getEnumPairs($table, $types[$v]['Field']);
         }
         $field['name'] = Converter::symb2Ttl($v);
         $params[$v] = $field;
     }
     return $params;
 }
 public function __settings_form($data = NULL)
 {
     /** @var CustomSetting $data */
     $form_array = ['title' => $data ? __('Edit custom setting') : __('Add custom setting'), 'data' => $data, 'action' => '?p=' . P . '&do=_add', 'button' => 'Add', 'fields' => ['module' => ['type' => 'datalist', 'options' => ModuleManager::getListOfCustomModuleNames()], 'key' => ['required' => true], 'input_type' => ['options' => SQL::getEnumPairs(ModuleSettings::$tables['settings'], 'input_type')], 'input_options' => ['type' => 'checkbox_list', 'options' => ['editor_wysiwyg' => 'Wysiwyg', 'editor_files' => 'Filemanager', 'editor_pages' => 'Pages', 'require' => 'Required', 'is_digit' => 'Digit', 'alphanum' => 'Alphanumeric', 'url' => 'URL', 'email' => 'email']]]];
     return CmsFormHelper::outputForm(ModuleSettings::$tables['settings'], $form_array);
 }