/** * 取回登录所保存的权限信息并生成树形结构 */ protected function generalData() { $this->list = SC::getUserPermissionSession(); foreach ($this->list as $key => $value) { if ($value['display'] == self::DISABLE_NONE) { unset($this->list[$key]); } } $this->menuTree = (array) Tree::genTree($this->list); return $this; }
/** * 递归select中的option下拉表单,用于权限增加和编辑 * * @param array $datas 数据源 * @param mixed $prefix 下拉表单的线,只能传false * @return html 返回组装好的option代码 */ public function acllist(array $datas, $pid, $prefix = false) { $html = ''; if (!$this->son) { $this->son = \App\Services\Admin\Tree::getSonKey(); } foreach ($datas as $key => $value) { if ($prefix === false) { if ($pid != $value['id'] && $pid != 'all') { continue; } } $line = ($prefix === false ? '' : $prefix) . '┆┄'; $html .= view('admin.acl.list', compact('value', 'prefix')); if (isset($value[$this->son]) && is_array($value[$this->son])) { $html .= $this->acllist($value[$this->son], $pid, $line); } } return $html; }
/** * 编辑分类 * * @access public */ public function edit(ProductCategory $pcModel) { if (Request::method() == 'POST') { return $this->editShopCategory(); } Session::flashInput(['http_referer' => Session::getOldInput('http_referer')]); $id = Request::input('id'); if (!$id or !is_numeric($id)) { return Js::error(Lang::get('common.illegal_operation'), true); } $info = $pcModel->getShopCategoryById(intval($id)); if (empty($info)) { return Js::error(Lang::get('shopcategory.not_found'), true); } $formUrl = route('shop.category.edit'); $select = Tree::dropDownSelect(Tree::genTree($pcModel->getAllForDropDownTag()), $info['category_pid']); return view('admin.shopcategory.add', compact('select', 'info', 'formUrl', 'id')); }
/** * 编辑权限功能 * * @access public */ public function edit(PermissionModel $permissionModel) { if (Request::method() == 'POST') { return $this->updatePermission(); } Session::flashInput(['http_referer' => Session::getOldInput('http_referer')]); $id = Request::input('id'); $permissionId = url_param_decode($id); if (!$permissionId or !is_numeric($permissionId)) { return Js::error(Lang::get('common.illegal_operation'), true); } $list = (array) Tree::genTree($permissionModel->getAllAccessPermission()); $permissionInfo = $permissionModel->getOnePermissionById(intval($permissionId)); if (empty($permissionInfo)) { return Js::error(Lang::get('acl.acl_not_found'), true); } $select = Tree::dropDownSelect($list, $permissionInfo['pid']); $formUrl = route('foundation.acl.edit'); return view('admin.acl.add', compact('select', 'permissionInfo', 'formUrl', 'id')); }
/** * 返回内容区域的菜单 */ protected function getContentMenu() { $this->list = SC::getUserPermissionSession(); foreach ($this->list as $key => $value) { if ($value['display'] == self::DISABLE_NONE) { unset($this->list[$key]); } } $this->menuTree = (array) Tree::genTree($this->list); $son = \App\Services\Admin\Tree::getSonKey(); $mcaName = \App\Services\Admin\MCAManager::MAC_BIND_NAME; $MCA = app()->make($mcaName); foreach ($this->menuTree as $key => $value) { if (isset($value[$son]) and is_array($value[$son])) { foreach ($value[$son] as $skey => $svalue) { if (!$MCA->matchSecondMenu($svalue['module'], $svalue['class'], $svalue['action'])) { continue; } if (isset($svalue[$son]) and is_array($svalue[$son])) { return $svalue[$son]; } } } } return []; }