Esempio n. 1
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);
         }
     }
 }