public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' ADD `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(get::__class_name($this), $source_module->table_name); } $res = db::select('_cms_field')->retrieve('MAX(position) AS pos')->filter_field('mid', $this->mid)->execute()->fetchObject(); $insert = db::insert('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('mid', $this->mid)->add_value('position', $res->pos + 1); if ($field->title == 'link' || $field->title == 'mlink') { $insert->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field); } $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
public function do_submit() { $module = new _cms_module([], $this->mid); if ($module->table_name != $this->table_name) { db::rename_table($module->table_name, $this->table_name); } if ($module->primary_key != $this->primary_key) { db::rename_column($this->table_name, $module->primary_key, $this->primary_key); } \classes\table::rebuild_modules(); $module->set_from_request(); $module->do_save(); }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $old_field = new _cms_field([], $this->fid); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' MODIFY `' . $old_field->field_name . '` `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink' && $old_field->type !== 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(\classes\get::__class_name($this), $source_module->table_name); } $insert = db::update('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field)->filter_field('fid', $this->fid); $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
public function do_submit() { db::query('CREATE TABLE IF NOT EXISTS `' . $this->table_name . '` ( `' . $this->primary_key . '` int(4) NOT NULL AUTO_INCREMENT, `parent_' . $this->primary_key . '` int(4) NOT NULL DEFAULT "0", `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `cms_created` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00", `live` tinyint(1) NOT NULL DEFAULT "0", `deleted` tinyint(1) NOT NULL DEFAULT "0", `position` int(6) NOT NULL DEFAULT "0", `' . get::fn($this->title_label) . '` varchar(255) NOT NULL, PRIMARY KEY (`' . $this->primary_key . '`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;'); $mid = db::insert('_cms_module')->add_value('gid', $this->gid)->add_value('primary_key', $this->primary_key)->add_value('title', $this->title)->add_value('table_name', $this->table_name)->add_value('namespace', $this->namespace)->execute(); $id_field = db::insert('_cms_field')->add_value('field_name', $this->primary_key)->add_value('title', 'ID')->add_value('type', 'int')->add_value('mid', $mid)->add_value('required', false)->add_value('list', false)->add_value('editable', false)->add_value('filter', false)->execute(); db::insert('_cms_field')->add_value('field_name', 'parent_' . $this->primary_key)->add_value('title', 'Parent ID')->add_value('type', 'link')->add_value('mid', $mid)->add_value('link_module', $mid)->add_value('link_field', (int) $id_field + 2)->add_value('required', false)->add_value('list', false)->execute(); db::insert('_cms_field')->add_value('field_name', get::fn($this->title_label))->add_value('title', $this->title_label)->add_value('type', 'string')->add_value('mid', $mid)->execute(); $file = null; if (!$this->namespace) { if (!is_dir(root . '/inc/object/')) { mkdir(root . '/inc/object/'); } if (!file_exists(root . '/inc/object/' . $this->table_name)) { $file = root . '/inc/object/' . $this->table_name; } } else { if (!is_dir(root . '/inc/module/')) { mkdir(root . '/inc/module/'); } if (!is_dir(root . '/inc/module/' . $this->namespace)) { mkdir(root . '/inc/module/' . $this->namespace); } if (!is_dir(root . '/inc/module/' . $this->namespace . '/object/')) { mkdir(root . '/inc/module/' . $this->namespace . '/object'); } if (!file_exists(root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name)) { $file = root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name; } } if ($file) { $class_name = ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object\\' . $this->table_name; file_put_contents($file . '.php', '<?php namespace ' . ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object; use classes\\table; use traits\\table_trait; class ' . $this->table_name . ' extends ' . (class_exists('\\core\\' . $class_name) ? '\\core\\' . $class_name : 'table') . ' { use table_trait; /** @var string */ public $' . get::fn($this->title_label) . '; /** @var int */ public $' . get::fn($this->primary_key) . '; }'); } \classes\table::rebuild_modules(); ajax::add_script('window.location = window.location'); }