Пример #1
0
 public function build()
 {
     db::create_table_json(module::create('_cms_group'));
     db::create_table_json(module::create('_cms_module'));
     db::create_table_json(module::create('_cms_field'));
     db::create_table_json(module::create('field_type'));
     /** @var module[] $modules_json */
     $modules_json[] = module::create('_cms_field');
     $modules_json[] = module::create('_cms_module');
     $modules_json[] = module::create('_cms_group');
     $modules_json[] = module::create('field_type');
     // Create base _cms_modules
     foreach ($modules_json as $structure) {
         $this->create_module_base($structure);
     }
     // Create basic fields
     foreach ($modules_json as &$structure) {
         $cnt = 0;
         foreach ($structure->fieldset as $key => &$field) {
             if (!$field->is_default) {
                 $this->create_field_base($structure, $key, $field, $cnt++);
             }
         }
     }
     // Reset pointers
     unset($structure);
     unset($field);
     // Create joins
     foreach ($modules_json as &$structure) {
         foreach ($structure->fieldset as $key => &$field) {
             if ($field->type == 'link') {
                 $this->create_field_base_link($structure, $key, $field);
             }
         }
     }
     // Add base field types
     $field_types = ['int', 'boolean', 'date', 'datetime', 'email', 'file', 'float', 'link', 'multi_select', 'password', 'radio', 'textarea', 'string', 'time', 'button', 'file'];
     foreach ($field_types as $field) {
         $field_type = new field_type();
         $field_type->title = $field;
         $field_type->do_save();
     }
     table::reload_table_definitions();
 }
Пример #2
0
 public function set_from_object($object, $change_target = true)
 {
     parent::set_from_object($object, $change_target);
     if (isset($object->type)) {
         $fields = field_type::get_all(['title']);
         /** @var field_type $field */
         foreach ($fields as $field) {
             if ($field->title == $object->type) {
                 $this->type = $field->get_primary_key();
                 break;
             }
         }
     }
 }