Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
0
 public static function create_from_structure($database)
 {
     $json = module::create($database);
     db::create_table_json($json);
     foreach ($json->dependencies as $dependant) {
         if (!db::table_exists($dependant)) {
             static::create_from_structure($dependant);
         }
     }
     $_group_id = _cms_group::create($json->group)->get_primary_key();
     $module_id = _cms_module::create($json->title, $json->tablename, $json->primary_key, $_group_id, $json->namespace)->get_primary_key();
     $cnt = 0;
     foreach ($json->fieldset as $field => $structure) {
         if (!$structure->is_default) {
             $cnt++;
             _cms_field::create($field, $structure, $module_id);
         }
     }
     foreach ($json->fieldset as $field => $structure) {
         if ($structure->module && $structure->field) {
             $cms_field = new _cms_field();
             $cms_field->do_retrieve([], ['where' => '(mid = :mid OR mid = 0) AND field_name = :field_name', 'parameters' => ['mid' => $module_id, 'field_name' => $field]]);
             if ($structure->type == 'mlink') {
                 if (!db::table_exists($database . '_link_' . $structure->module)) {
                     db::create_table_join($database, $structure->module);
                 }
             }
             static::modify_link_field($cms_field, $structure->module, $structure->field);
         }
     }
 }