diff --git a/lib/yform/value/integer.php b/lib/yform/value/integer.php index 29484dfa..e5410f9f 100644 --- a/lib/yform/value/integer.php +++ b/lib/yform/value/integer.php @@ -49,8 +49,8 @@ public function getDefinitions() 'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')], ], 'description' => rex_i18n::msg('yform_values_integer_description'), - 'dbtype' => 'int', - 'null' => true, + 'db_type' => ['int'], + 'db_null' => true, ]; } diff --git a/lib/yform/value/text.php b/lib/yform/value/text.php index a9ecfe8e..f8e324f2 100644 --- a/lib/yform/value/text.php +++ b/lib/yform/value/text.php @@ -46,7 +46,7 @@ public function getDefinitions() 'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')], ], 'description' => rex_i18n::msg('yform_values_text_description'), - 'dbtype' => 'text', + 'db_type' => ['varchar(191)', 'text'], 'famous' => true, ]; } diff --git a/plugins/manager/install.php b/plugins/manager/install.php index 4f424e9c..5a6a9c52 100644 --- a/plugins/manager/install.php +++ b/plugins/manager/install.php @@ -37,6 +37,7 @@ ->ensureColumn(new rex_sql_column('prio', 'int(11)')) ->ensureColumn(new rex_sql_column('type_id', 'varchar(191)')) ->ensureColumn(new rex_sql_column('type_name', 'varchar(191)')) + ->ensureColumn(new rex_sql_column('db_type', 'varchar(191)')) ->ensureColumn(new rex_sql_column('list_hidden', 'tinyint(1)')) ->ensureColumn(new rex_sql_column('search', 'tinyint(1)')) ->ensureColumn(new rex_sql_column('name', 'text')) diff --git a/plugins/manager/lang/de_de.lang b/plugins/manager/lang/de_de.lang index 83e47b5c..cc881b26 100644 --- a/plugins/manager/lang/de_de.lang +++ b/plugins/manager/lang/de_de.lang @@ -275,4 +275,7 @@ yform_values_prio_scope = Beschränkung yform_values_prio_default = Am Anfang yform_is = ist -yform_will_set_to = wird \ No newline at end of file +yform_will_set_to = wird + +yform_field_add = Feld hinzufügen +yform_field_update = Feld aktualisieren diff --git a/plugins/manager/lib/yform/manager.php b/plugins/manager/lib/yform/manager.php index f4ce5711..9c82e1ef 100644 --- a/plugins/manager/lib/yform/manager.php +++ b/plugins/manager/lib/yform/manager.php @@ -1044,7 +1044,7 @@ public function getFieldPage() } break; - case 'no_db': +/* case 'no_db': if (!isset($v['values'])) { $v['values'] = [0,1]; } @@ -1052,7 +1052,7 @@ public function getFieldPage() $v['default'] = 0; } $yform->setValueField('checkbox', ['name' => $k_field, 'label' => rex_i18n::msg('yform_donotsaveindb'), 'values' => 'no_db', 'default' => $v['default']]); - break; + break;*/ case 'boolean': if (!isset($v['values'])) { @@ -1132,7 +1132,7 @@ public function getFieldPage() $yform->setObjectparams('main_table', rex_yform_manager_field::table()); if ($func == 'edit') { - $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_save')); + $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_field_update')); $yform->setHiddenField('field_id', $field_id); $yform->setActionField('manage_db', [rex_yform_manager_field::table(), "id=$field_id"]); $yform->setObjectparams('main_id', $field_id); @@ -1150,11 +1150,16 @@ public function getFieldPage() $yform->setObjectparams('sql_object', $sql); $yform->setObjectparams('getdata', true); } elseif ($func == 'add') { - $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_add')); + $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_field_add')); $yform->setActionField('manage_db', [rex_yform_manager_field::table()]); } if ($type_id == 'value') { + + $db_choices = $field->getDBTypes(); + $default = $field->getDBDefaultType(); + $yform->setValueField('choice', ['name' => 'db_type', 'label' => rex_i18n::msg('yform_db_type'), 'choices' => $db_choices, 'default' => $default]); + if (!$field->isHiddenInListDisabled()) { $yform->setValueField('checkbox', ['name' => 'list_hidden', 'label' => rex_i18n::msg('yform_hideinlist'), 'default' => '1']); } @@ -1162,6 +1167,7 @@ public function getFieldPage() if (!$field->isSearchableDisabled()) { $yform->setValueField('checkbox', ['name' => 'search', 'label' => rex_i18n::msg('yform_useassearchfieldalidatenamenotempty'), 'default' => '1']); } + } elseif ($type_id == 'validate') { $yform->setValueField('hidden', ['list_hidden', 1]); $yform->setValueField('hidden', ['search', 0]); diff --git a/plugins/manager/lib/yform/manager/field.php b/plugins/manager/lib/yform/manager/field.php index 3d3392b4..5b5d14f0 100644 --- a/plugins/manager/lib/yform/manager/field.php +++ b/plugins/manager/lib/yform/manager/field.php @@ -73,10 +73,49 @@ public function getElement($k) public function getDBType() { - if (!isset($this->definitions['dbtype'])) { - return 'none'; + if (!isset($this->value['db_type'])) { + return $this->getDBDefaultType(); } - return $this->definitions['dbtype']; + return $this->value['db_type']; + } + + public function getDBTypes() + { + $db_types = []; + if (isset($this->definitions['dbtype'])) { + $this->definitions['db_type'] = [$this->definitions['dbtype']]; + } + + if (!isset($this->definitions['db_type'])) { + $this->definitions['db_type'] = []; + } else if (!is_array($this->definitions['db_type'])) { + $this->definitions['db_type'] = [$this->definitions['db_type']]; + } + foreach($this->definitions['db_type'] as $db_type){ + $db_types[$db_type] = $db_type; + } + $db_types['none'] = '[none]'; + return $db_types; + } + + public function getDBDefaultType() + { + $db_types = $this->getDBTypes(); + reset($db_types); + return key($db_types); + } + + public function getDBNull() + { + if (isset($this->definitions['db_null']) && $this->definitions['db_null']) { + return true; + } + return false; + } + + public function getHooks() + { + return (isset($this->definitions['hooks'])) ? $this->definitions['hooks'] : []; } public function isSearchableDisabled() diff --git a/plugins/manager/lib/yform/manager/table_api.php b/plugins/manager/lib/yform/manager/table_api.php index cc060e8d..3a0b7c93 100644 --- a/plugins/manager/lib/yform/manager/table_api.php +++ b/plugins/manager/lib/yform/manager/table_api.php @@ -543,48 +543,45 @@ public static function generateTablesAndFields($delete_old = false) { rex_yform_manager_table::deleteCache(); - $types = rex_yform::getTypeArray(); foreach (rex_yform_manager_table::getAll() as $table) { + $c = rex_sql::factory(); $c->setDebug(self::$debug); - $c->setQuery('CREATE TABLE IF NOT EXISTS `' . $table['table_name'] . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;'); - $c->setQuery('ALTER TABLE `' . $table['table_name'] . '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'); + $c->setQuery('CREATE TABLE IF NOT EXISTS `' . $table->getTableName() . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;'); + $c->setQuery('ALTER TABLE `' . $table->getTableName() . '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'); // remember fields, create and in case delete - $c->setQuery('SHOW COLUMNS FROM `' . $table['table_name'] . '`'); - $saved_columns = $c->getArray(); + $savedColumns = $table->getColumns(); - $EnsureTable = rex_sql_table::get($table['table_name']); + $EnsureTable = rex_sql_table::get($table->getTableName()); foreach ($table->getFields() as $field) { - $type_name = $field['type_name']; - $type_id = $field['type_id']; - if ($type_id == 'value') { - $type_label = $field['name']; - $dbtype = $types[$type_id][$type_name]['dbtype']; + if ($field->getType() == 'value') { + $db_type = $field->getDBType(); + + if ($db_type != 'none' && $db_type != '') { - if ($dbtype != 'none' && $dbtype != '') { - if (isset($types[$type_id][$type_name]['hooks']['preCreate'])) { - $result = call_user_func($types[$type_id][$type_name]['hooks']['preCreate'], $field); + $hooks = $field->getHooks(); + if (isset($hooks['preCreate'])) { + $result = call_user_func($hooks['preCreate'], $field); if (false === $result) { continue; } if (is_string($result)) { - $dbtype = $result; + $db_type = $result; } } - foreach ($saved_columns as $uu => $vv) { - if ($vv['Field'] == $type_label) { - unset($saved_columns[$uu]); + foreach ($savedColumns as $savedColumn) { + if ($savedColumn['name'] == $field->getName()) { + unset($savedColumns[$savedColumn['name']]); break; } } - $null = isset($types[$type_id][$type_name]['null']) && $types[$type_id][$type_name]['null']; $EnsureTable - ->ensureColumn(new rex_sql_column($type_label, $dbtype, $null)) + ->ensureColumn(new rex_sql_column($field->getName(), $db_type, $field->getDBNull())) ->ensure(); } @@ -593,9 +590,9 @@ public static function generateTablesAndFields($delete_old = false) } if ($delete_old === true) { - foreach ($saved_columns as $uu => $vv) { - if ($vv['Field'] != 'id') { - $c->setQuery('ALTER TABLE `' . $table['table_name'] . '` DROP `' . $vv['Field'] . '` '); + foreach ($savedColumns as $savedColumn) { + if ($savedColumn['name'] != 'id') { + $c->setQuery('ALTER TABLE `' . $table->getTableName() . '` DROP `' . $savedColumn['name'] . '` '); } } }