public function show($config) { if (empty($config['view'])) { throw new \Exception(__METHOD__ . '. View parameter not defined.'); } if (empty($config['name'])) { throw new \Exception(__METHOD__ . '. Javascript tree variable name not defined.'); } $this->layout->content = \View::make($config['view'])->with(['tv' => Tree::create($config)]); }
public function run() { // clear our database ------------------------------------------ DB::table('bears')->delete(); DB::table('fish')->delete(); DB::table('picnics')->delete(); DB::table('trees')->delete(); DB::table('bears_picnics')->delete(); // seed our bears table ----------------------- // we'll create three different bears // bear 1 is named Lawly. She is extremely dangerous. Especially when hungry. $bearLawly = Bear::create(array('name' => 'Lawly', 'type' => 'Grizzly', 'danger_level' => 8)); // bear 2 is named Cerms. He has a loud growl but is pretty much harmless. $bearCerms = Bear::create(array('name' => 'Cerms', 'type' => 'Black', 'danger_level' => 4)); // bear 3 is named Adobot. He is a polar bear. He drinks vodka. $bearAdobot = Bear::create(array('name' => 'Adobot', 'type' => 'Polar', 'danger_level' => 3)); $this->command->info('The bears are alive!'); // seed our fish table ------------------------ // our fish wont have names... because theyre going to be eaten // we will use the variables we used to create the bears to get their id $fishOne = Fish::create(array('weight' => 5, 'bear_id' => $bearLawly->id)); $fishTwo = Fish::create(array('weight' => 12, 'bear_id' => $bearCerms->id)); $fishThree = Fish::create(array('weight' => 4, 'bear_id' => $bearAdobot->id)); $this->command->info('They are eating fish!'); // seed our trees table --------------------- // give two trees to lawly Tree::create(array('type' => 'Redwood', 'age' => 500, 'bear_id' => $bearLawly->id)); Tree::create(array('type' => 'Oak', 'age' => 400, 'bear_id' => $bearLawly->id)); $this->command->info('Climb bears! Be free!'); // seed our picnics table --------------------- // we will create one picnic and apply all bears to this one picnic $picnicYellowstone = Picnic::create(array('name' => 'Yellowstone', 'taste_level' => 6)); $picnicGrandCanyon = Picnic::create(array('name' => 'Grand Canyon', 'taste_level' => 5)); // link our bears to picnics --------------------- // for our purposes we'll just add all bears to both picnics for our many to many relationship $bearLawly->picnics()->attach($picnicYellowstone->id); $bearLawly->picnics()->attach($picnicGrandCanyon->id); $bearCerms->picnics()->attach($picnicYellowstone->id); $bearCerms->picnics()->attach($picnicGrandCanyon->id); $bearAdobot->picnics()->attach($picnicYellowstone->id); $bearAdobot->picnics()->attach($picnicGrandCanyon->id); $this->command->info('They are terrorizing picnics!'); }
public function access() { $rid = $this->_param('3'); import('ORG.Util.Tree'); $node = M('Node')->order('sort')->select(); $node = Tree::create($node); $data = array(); //$data用于存放最新数组,里面包含当前用户组是否有没一个权限 $access = M('Access'); foreach ($node as $value) { $count = $access->where('role_id=' . $rid . ' and node_id=' . $value['id'])->count(); if ($count) { $value['access'] = 1; } else { $value['access'] = 0; } $data[] = $value; } $this->nodelist = $data; $this->rid = $rid; //不知道干什么用 $this->role = M('Role')->getFieldById($rid, 'name'); $this->display(); }
/** * 编辑 * Enter description here ... */ public function edit() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { $Area_id = $this->input->post('Area_id'); $dataArray = array('title' => $this->input->post('title'), 'level' => $this->input->post('level'), 'pid' => $this->input->post('pid')); $result = $this->AreaModel->edit($dataArray, 'id=' . $Area_id); if ($result) { $totalResult = $this->AreaModel->getListByWhere(''); //更新XML文件开始 $tree = new Tree(); $treeResult = $tree->create($totalResult, 1); //大树 $file = fopen("../uploadfile/Area/Area.xml", "w"); $xml = new XML(); $res = $xml->xml_serialize($treeResult, 0, null); fwrite($file, $res); //将序列化的字符写进文件 //print_r($res); fclose($file); show_error('index.php/Area/index', 500, '提示信息:地区修改成功!'); } else { show_error('index.php/Area/index', 500, '提示信息:地区修改失败!'); } } else { $Area_id = $this->input->get('id'); if ($Area_id) { $Area = $this->AreaModel->get('id=' . $Area_id); $parent = $this->AreaModel->getListByWhere(''); $tree = new Tree(); $this->load->view('Area/edit', array('Area' => $Area, 'parent' => $tree->create($parent))); } else { show_error('index.php/Area/index', 500, '提示信息:参数错误!'); } } }
/** * 编辑用户 * Enter description here ... */ public function edit() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { $id = $this->input->post('id'); $model = $this->UserModel->getUser('id=' . $id); if ($model) { $dataArray = array(); if ($this->input->post('password') == $model['password']) { $dataArray = array('username' => $this->input->post('username'), 'role_id' => $this->input->post('role_id'), 'status' => $this->input->post('status')); } else { $dataArray = array('username' => $this->input->post('username'), 'password' => md5($this->input->post('password')), 'role_id' => $this->input->post('role_id'), 'status' => $this->input->post('status')); } $result = $this->UserModel->editUser($dataArray, 'id=' . $id); if ($result) { show_error('index.php/User/index', 500, '提示信息:管理员修改成功!'); } else { show_error('index.php/User/edit', 500, '提示信息:管理员修改失败!'); } } else { show_error('index.php/User/edit', 500, '提示信息:管理员帐号或已被删除!'); } } else { $id = $this->input->get('id'); if ($id) { $model = $this->UserModel->getUser('id=' . $id); if ($model) { $user = $this->user; $role = $this->RoleModel->getRole('id=' . $user['role_id']); $level = $role['level']; //用户角色等级 $roles = $this->RoleModel->getListByWhere('status=1 AND (level>' . $level . ' OR id=' . $role['id'] . ')'); $tree = new Tree(); $this->load->view('User/edit', array('roles' => $tree->create($roles, $role['pid']), 'model' => $model)); } else { show_error('index.php/User/edit', 500, '提示信息:管理员帐号或已被删除!'); } } else { show_error('index.php/User/edit', 500, '提示信息:参数错误!'); } } }
/** * 权限配置 * Enter description here ... */ public function access() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { $access = $this->input->post('access'); //接受到的权限 $role_id = $this->input->post('role_id'); if (!$role_id) { show_error('index.php/Role/list', 500, '提示信息:参数错误!'); } $role = $this->RoleModel->getRole('id=' . $role_id); if (!$role) { show_error('index.php/Role/list', 500, '提示信息:参数错误!'); } $this->AccessModel->delAccess('role_id=' . $role['id']); //删除现有权限 $flag = 0; if ($access) { $dataArray = array(); foreach ($access as $value) { $tmp = explode('_', $value); $dataArray = array('role_id' => $role['id'], 'node_id' => $tmp[0], 'level' => $tmp[1]); $flag += $this->AccessModel->addAccess($dataArray); } if ($flag > 0) { show_error('index.php/Role/access?id=' . $role_id, 500, '提示信息:角色权限配置成功!'); } else { show_error('index.php/Role/access?id=' . $role_id, 500, '提示信息:角色权限配置失败!'); } } else { show_error('index.php/Role/access?id=' . $role_id, 500, '提示信息:请为用户组选择权限!'); } } else { if (!$this->input->get('id')) { show_error('index.php/Role/index', 500, '提示信息:参数错误!'); } $role = $this->RoleModel->getRole('id=' . $this->input->get('id')); if (!$role) { show_error('index.php/Role/index', 500, '提示信息:参数错误!'); } $user = $this->user; //登录用户 $nodes = $this->NodeModel->getListByWhere('status=1'); //所有权限节点 $right = array(); //存放用户当前拥有的权限 if ($user['username'] == 'jooli') { //超级管理员加载所有权限 foreach ($nodes as $value) { $access = $this->AccessModel->getAccess('role_id=' . $role['id'] . ' AND node_id=' . $value['id']); if ($access) { $value['access'] = 1; } else { $value['access'] = 0; } $right[] = $value; } } else { //加载自己有的权限 foreach ($nodes as $value) { $access = $this->AccessModel->getAccess('role_id=' . $user['id'] . ' AND node_id=' . $value['id']); //查询登录用户是否有此权限 if ($access) { $ac = $this->AccessModel->getAccess('role_id=' . $role['id'] . ' AND node_id=' . $value['id']); //查询要分配的角色是否有此权限 if ($ac) { $value['access'] = 1; } else { $value['access'] = 0; } $right[] = $value; } } } $tree = new Tree(); $data['role'] = $role; $data['nodes'] = $tree->create($right); $this->load->view('Role/access', $data); } }
/** * 编辑 * Enter description here ... */ public function edit() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { $Area_id = $this->input->post('Area_id'); $dataArray = array('title' => $this->input->post('title'), 'level' => $this->input->post('level'), 'pid' => $this->input->post('pid')); $result = $this->AreaModel->edit($dataArray, 'id=' . $Area_id); if ($result) { show_error('index.php/Area/index', 500, '提示信息:地区修改成功!'); } else { show_error('index.php/Area/index', 500, '提示信息:地区修改失败!'); } } else { $Area_id = $this->input->get('id'); if ($Area_id) { $Area = $this->AreaModel->get('id=' . $Area_id); $parent = $this->AreaModel->getListByWhere(''); $tree = new Tree(); $this->load->view('Area/edit', array('Area' => $Area, 'parent' => $tree->create($parent))); } else { show_error('index.php/Area/index', 500, '提示信息:参数错误!'); } } }
/** * 编辑权限 * Enter description here ... */ public function edit() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { $node_id = $this->input->post('node_id'); $dataArray = array('name' => $this->input->post('name'), 'title' => $this->input->post('title'), 'level' => $this->input->post('level'), 'pid' => $this->input->post('pid'), 'sort' => $this->input->post('sort'), 'remark' => $this->input->post('remark'), 'type' => $this->input->post('type'), 'status' => $this->input->post('status')); $result = $this->NodeModel->editNode($dataArray, 'id=' . $node_id); if ($result) { show_error('index.php/Node/index', 500, '提示信息:用户权限修改成功!'); } else { show_error('index.php/Node/edit', 500, '提示信息:用户权限修改失败!'); } } else { $node_id = $this->input->get('id'); if ($node_id) { $node = $this->NodeModel->getNode('id=' . $node_id); if ($node) { $user = $this->user; $role = $this->RoleModel->getRole('id=' . $user['role_id']); //取出当前登录用户所有模块权限(英文名称)及操作权限(ID) $accessList = $this->AccessModel->getListByWhere('role_id=' . $user['role_id']); $node_id = ''; //所有权限ID foreach ($accessList as $access) { $node_id .= $access['node_id'] . ','; } $parent = $this->NodeModel->getListByWhere('status=1 AND level<3 AND id IN (' . rtrim($node_id, ',') . ')'); $tree = new Tree(); $this->load->view('Node/edit', array('node' => $node, 'parent' => $tree->create($parent), 'level' => $role['level'])); } else { show_error('index.php/Node/index', 500, '提示信息:参数错误!'); } } else { show_error('index.php/Node/index', 500, '提示信息:权限不存在!'); } } }