/** * @param $fid * @return __cms_field */ public static function get_field_from_fid($fid) { if (!isset(self::$cms_fields)) { $cms_fields = __cms_field::get_all([]); $cms_fields->iterate(function ($object) { self::$cms_fields[$object->fid] = $object; }); } return isset(self::$cms_fields[$fid]) ? self::$cms_fields[$fid] : false; }
public function get_link_fields() { if (is_numeric($this->link_field)) { if ($this->link_field) { $this->link_field = _cms_field::get_field_from_fid($this->link_field)->field_name; } else { $this->link_field = 'title'; } } if (is_array($this->link_field)) { $fields = $this->link_field; } else { $fields = [$this->link_field]; } return $fields; }
/** Add user level management * ---CMS User * ---CMS User level * ---CMS User --> CMS Module * */ public function patch_v4() { if (!db::table_exists('_cms_user')) { self::create_from_structure('_cms_user'); table::reload_table_definitions(); $user_level = new _cms_user_level(); $user_level->title = 'User'; $user_level->do_save(); $user_level->ulid = 0; $user_level->title = 'Webmaster'; $user_level->do_save(); $user_level->ulid = 0; $user_level->title = 'Admin'; $user_level->do_save(); $cms_user = new _cms_user(); $cms_user->title = 'admin'; $cms_user->password = '******'; $cms_user->ulid = 3; $cms_user->do_save(); $_module = new _cms_module(); $_module->do_retrieve([], ['where_equals' => ['table_name' => '_cms_module']]); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_view']]); static::modify_link_field($_field, '_cms_user_level', 'title'); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_add']]); static::modify_link_field($_field, '_cms_user_level', 'title'); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_delete']]); static::modify_link_field($_field, '_cms_user_level', 'title'); } }
/** * */ public function do_reorder_fields() { if (isset($_REQUEST['mid']) && isset($_REQUEST['fid'])) { $this->set_from_mid($_REQUEST['mid']); $fields = object\_cms_field::get_all([], ['where_equals' => ['mid' => $_REQUEST['mid']]]); $reverse = false; if (isset($_REQUEST['dir']) && $_REQUEST['dir'] == 'down') { $reverse = true; $fields->reverse(); } $cnt = $reverse ? count($fields) + 1 : 0; /** @var object\_cms_field $previous */ $previous = $fields[0]; $fields->iterate(function (object\_cms_field $field) use(&$previous, $reverse, &$cnt) { $cnt += $reverse ? -1 : 1; $field->position = $cnt; $field->position = $cnt; if ($field->fid == $_REQUEST['fid']) { $field->position = $previous->position; $previous->position = $cnt; } $previous = $field; }); if ($reverse) { $fields->reverse(); } $fields->uasort(function (object\_cms_field $a, object\_cms_field $b) { return $a->position - $b->position; }); $cnt = 1; $fields->iterate(function (object\_cms_field $field) use(&$cnt) { db::update('_cms_field')->add_value('position', $cnt++)->filter_field('fid', $field->fid)->execute(); }); table::reset_module_fields($this->module->mid); ajax::update($this->module->get_fields_list()->get()); } }
public static function rebuild_modules() { $modules = _cms_module::get_all(_cms_module::$default_fields); $fields = _cms_field::get_all(_cms_field::$default_fields); $json = []; $modules->iterate(function (_cms_module $row) use(&$json) { $result = []; foreach (_cms_module::$default_fields as $field) { $result[$field] = $row->{$field}; } $json[$row->mid] = $result; }); $fields->iterate(function (_cms_field $row) use(&$json) { $result = []; foreach (_cms_field::$default_fields as $field) { $result[$field] = $row->{$field}; } $json[$row->mid]['fields'][$row->field_name] = $result; }); file_put_contents(root . '/.cache/.modules.json', json_encode($json)); }