/** * add menu */ public function add() { if ($_POST) { //标签过滤 tool::filter_strip_tags($_POST); $target = $this->input->post('target'); $parent_id = $this->input->post('parent_id'); $data = Mymenu::instance()->get_by_target($target); if ($data['id']) { remind::set(Kohana::lang('o_manage.menu_has_exist'), 'manage/menu/add'); } if ($parent_id > 0) { $parent_menu = Mymenu::instance($parent_id)->get(); if ($parent_menu['level_depth'] >= 3) { remind::set(Kohana::lang('o_manage.menu_can_not_add_level'), 'manage/menu/add'); } } if (Mymenu::instance()->add($_POST)) { $cache = Mycache::instance(); $tag = "admin/menu"; $data = $cache->delete($tag); remind::set(Kohana::lang('o_global.add_success'), 'manage/menu', 'success'); } else { remind::set(Kohana::lang('o_global.add_error'), 'manage/menu/add'); } } $menus = Mymenu::instance()->menus(); $actions = Myaction::instance()->actions(); $this->template->content = new View("manage/menu_add"); $this->template->content->menus = $menus; $this->template->content->actions = $actions; }
/** * 构建用户操作资源的多维数组 * * @return Array */ public static function get() { $actions = array(); $cache = Mycache::instance('tt'); $tag = "admin/action"; if (!($data = $cache->get($tag))) { $model = self::models(); foreach ($model as $model_key => $model_value) { $actions[$model_value['flag']] = self::actions($model_value['id'], TRUE); } } else { $actions = $data; } return $actions; }
/** * 依照id得到文件夹的一条数据 * * @param Int $id * @return Array */ public function get($id) { $cache = Mycache::instance(); $cache_key = $this->object_name . '_' . $id; $cache_data = $cache->get($cache_key); if (!is_array($cache_data)) { $cache_data = $this->read(array('id' => $id)); if (!empty($cache_data)) { //可写性 $cache_data['writable'] = isset($cache_data['is_writable']) ? $cache_data['is_writable'] : TRUE; //可读性 $cache_data['readable'] = isset($cache_data['is_readable']) ? $cache_data['is_readable'] : TRUE; //可删除 $cache_data['removable'] = TRUE; $cache->set($cache_key, $cache_data); } } return $cache_data; }
/** * 依照folder_id得到文件信息 */ public function get_files($folder_id) { $cache = Mycache::instance(); $cache_key = $this->object_name . '_' . $folder_id; $cache_data = $cache->get($cache_key); //if(!is_array($cache_data)) //{ $folder = Mykc_folder::instance()->get($folder_id); $cache_data = $this->lists(array('where' => array('site_id' => $folder['site_id'], 'kc_folder_id' => $folder['id']))); if (!empty($cache_data)) { foreach ($cache_data as $key_cache_data => $_cache_data) { //扩充 $cache_data[$key_cache_data]['readable'] = TRUE; $cache_data[$key_cache_data]['writable'] = isset($_cache_data['writable']) ? $_cache_data['writable'] : true; $cache_data[$key_cache_data]['big_icon'] = isset($_cache_data['big_icon']) ? $_cache_data['big_icon'] : true; $cache_data[$key_cache_data]['small_icon'] = isset($_cache_data['small_icon']) ? $_cache_data['small_icon'] : true; $cache_data[$key_cache_data]['thumb'] = isset($_cache_data['thumb']) ? $_cache_data['thumb'] : true; $cache_data[$key_cache_data]['small_thumb'] = isset($_cache_data['small_thumb']) ? $_cache_data['small_thumb'] : false; } $cache->set($cache_key, $cache_data); } //} return $cache_data; }
/** * 得到所有菜单项(父子项的关系) */ public function get_level_menus($orderby = array('order' => 'DESC')) { $cache = Mycache::instance(); $tag = "admin/menu"; $data = $cache->get($tag); $list = array(); if (!$data) { $menus = ORM::factory('menu')->where('parent_id', 0)->where('active', 1)->orderby($orderby)->find_all(); foreach ($menus as $item) { $value = $item->as_array(); $sub_menus = self::sub_menus($value['id']); foreach ($sub_menus as $sub_menu_key => $sub_menu_value) { $sub_menus[$sub_menu_key]['children'] = self::sub_menus($sub_menu_value['id']); } $value['children'] = $sub_menus; $list[] = $value; } $cache->set($tag, $list); } else { $list = $data; } return $list; }
/** * 得到用户所有权限资源 * @param Int $manager_id manager id * @param Boolean $type 读取缓存数据还是更新缓存数据 * @return Array */ public static function manager_actions($manager_id = NULL, $type = false) { if (is_null($manager_id)) { $manager = self::get_manager(); } else { $manager = Mymanager::instance($manager_id)->get(); } $manager_id = $manager['id']; $cache = Mycache::instance(); $tag = "admin/actions/" . $manager_id; $data = $cache->get($tag); if ($type) { $data = false; } if ($data) { if (!is_array($data)) { return unserialize($data); } else { return $data; } } else { //帐号名称为超级管理员root,获得全部的资源和权限 zhu modify if (self::is_root($manager['username'])) { $actions = Myaction::instance()->get_actions(); } else { //zhu modify get acl //$manager = Mymanager::instance($manager_id)->get(); //$role = Mymanager::instance($manager_id)->role(); //$actions = Myrole::instance($role['id'])->actions(); $acl = Mymanager::instance($manager_id)->acl(); $actions = Myacl::instance($acl['id'])->actions(); //d($actions); } $cache->set($tag, $actions, self::$expire); return $actions; } }