diff --git a/application/admin/controller/posts/Archives.php b/application/admin/controller/posts/Archives.php index 06d4eaf8..44d2f2a6 100644 --- a/application/admin/controller/posts/Archives.php +++ b/application/admin/controller/posts/Archives.php @@ -50,34 +50,36 @@ class Archives extends Backend /** * 读取栏目列表 */ - private function initForm() + private function initForm($siteId=null) { - //从总后台进入 - if ($this->auth->isSuperAdmin()){ + $where=$first_siteid=''; + if ($this->auth->isSuperAdmin()) { $sitelist = model('Sites')->all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + + //记住下拉列表中第一个网站的ID,添加文章时,只读取对应的栏目等信息 + if ($sitelist && $this->request->action()=='add') { + $first_siteid = $sitelist[0]['id']; + $where = ['site_id' => $first_siteid]; + } } - //从站点后台进入 else { $this->view->assign('siteList', null); $first_siteid = Session::get('user_site_id'); } + if (!is_null($siteId)) $first_siteid=$siteId; + $tree = Tree::instance(); - $tree->init(model('channel')->with('sites')->order('site_id asc,weigh desc,id desc')->select(), 'pid'); + $tree->init(model('channel')->with('sites')->where($where)->order('site_id asc,weigh desc,id desc')->select(), 'pid'); $this->channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); $channeldata = []; //0 => ['mode' => 'default','site_id'=>0, 'name' => __('None')]]; foreach ($this->channellist as $k => $v) { - if(isset($first_siteid) && !is_null($first_siteid) && $v['site_id']!=$first_siteid) { - //do nothing - }else { - $channeldata[$v['id']] = $v; - $channeldata[$v['id']]['disabled'] = 0; - $channeldata[$v['id']]['sitename'] = $v['sites']['name'] == '' ? __('Main site') : $v['sites']['name']; - if ($v['type'] != 'list') { - $channeldata[$v['id']]['disabled'] = 1; - } + $channeldata[$v['id']] = $v; + $channeldata[$v['id']]['disabled'] = 0; + $channeldata[$v['id']]['sitename'] = $v['sites']['name'] == '' ? __('Main site') : $v['sites']['name']; + if ($v['type'] != 'list') { + $channeldata[$v['id']]['disabled'] = 1; } } $this->view->assign("channelList", $channeldata); @@ -113,7 +115,7 @@ class Archives extends Backend ->where($where) //->where('site_id', Session::get('admin.siteid')) ->where('isDelete',0) - ->with('channel') + ->with('sites,channel') ->field('subtitle,content',true, $tablename) ->order($sort, $order) ->limit($offset, $limit) @@ -124,6 +126,7 @@ class Archives extends Backend return json($result); } $this->initForm(); + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -266,7 +269,7 @@ class Archives extends Backend } $this->error(__('Parameter %s can not be empty', '')); } - $this->initForm(); + $this->initForm($row->site_id); $channeldata = []; //0 => ['mode' => 'default','site_id'=>0, 'name' => __('None')]]; foreach ($this->channellist as $k => $v) { diff --git a/application/admin/controller/posts/Channel.php b/application/admin/controller/posts/Channel.php index e5fc2b16..669212c1 100644 --- a/application/admin/controller/posts/Channel.php +++ b/application/admin/controller/posts/Channel.php @@ -19,7 +19,6 @@ class Channel extends Backend { protected $model = null; - protected $channellist = []; protected $noNeedRight = ['check_element_available','getlist']; @@ -29,29 +28,33 @@ class Channel extends Backend $this->request->filter(['strip_tags']); $this->model = model('Channel'); - $tree = Tree::instance(); - $tree->init($this->model->order('weigh desc,id desc')->with('Sites')->with('archives')->select(), 'pid'); - - $this->channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); } - private function initForm(){ - //从总后台进入 + private function initForm($siteId=null) + { + $first_siteid=null; if ($this->auth->isSuperAdmin()){ $sitelist = Sites::all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + if ($sitelist && $this->request->action()=='add') { + $first_siteid = $sitelist[0]['id'] ; + } } - //从站点后台进入 else { $this->view->assign('siteList', null); + $first_siteid = Session::get('user_site_id'); } + if (!is_null($siteId)) $first_siteid=$siteId; + $where = ['site_id'=>$first_siteid]; - + $tree = Tree::instance(); + $tree->init($this->model->order('weigh desc,id desc')->where($where)->with('Sites,archives')->select(), 'pid'); + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); $channeldata = [0 => ['site_id'=>0, 'name' => __('None')]]; - foreach ($this->channellist as $k => $v) + foreach ($channellist as $k => $v) { - if(isset($first_siteid) && !is_null($first_siteid) && $v['site_id']!=$first_siteid) { + //添加&编辑页面, 排除非首选网站的栏目 + if(!is_null($first_siteid) && $v['site_id']!=$first_siteid) { //do nothing }else { $channeldata[$v['id']] = $v; @@ -76,7 +79,7 @@ class Channel extends Backend $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("modelList", model('PostsModelx')->all()); - $ml = Seven::build_langs('row[lang]',null,['siteid'=>Session::get("admin.siteid")]); + $ml = Seven::build_langs('row[lang]',null,['siteid'=>$first_siteid]); $this->view->assign('multilanguage',$ml); } @@ -90,10 +93,18 @@ class Channel extends Backend { $search = $this->request->request("search"); //构造父类select列表选项数据 + + list($where, $sort, $order, $offset, $limit) = $this->buildparams(false, true); + + $tree = Tree::instance(); + $tree->init($this->model->order('weigh desc,id desc')->where($where)->with('Sites,archives')->select(), 'pid'); + + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + $list = []; if ($search) { - foreach ($this->channellist as $k => $v) + foreach ($channellist as $k => $v) { if (stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) { @@ -103,13 +114,18 @@ class Channel extends Backend } else { - $list = $this->channellist; + $list = $channellist; } $total = count($list); $result = array("total" => $total, "rows" => $list); return json($result); } + if ($this->auth->isSuperAdmin()){ + $sitelist = Sites::all(); + $this->view->assign('siteList', $sitelist); + } + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -177,7 +193,7 @@ class Channel extends Backend } $this->error(__('Parameter %s can not be empty', '')); } - $this->initForm(); + $this->initForm($row->site_id); $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'],['siteid'=>$row->site_id])); $this->view->assign("row", $row); return $this->view->fetch(); @@ -186,12 +202,15 @@ class Channel extends Backend /** - * 返回栏目列表,供Ajax调用 + * 返回栏目列表,供文章列表搜索框Ajax调用 */ public function getlist() { if($this->request->isAjax()){ - foreach ($this->channellist as $k => $v){ + $tree = Tree::instance(); + $channellist=$tree->init($this->model->order('weigh desc,id desc')->with('Sites,archives')->select(), 'pid'); + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + foreach ($channellist as $k => $v){ $list[$v['id']]=$v['name']; } return json($list); diff --git a/application/admin/controller/posts/Page.php b/application/admin/controller/posts/Page.php index 40a65c01..ed8cb9c9 100644 --- a/application/admin/controller/posts/Page.php +++ b/application/admin/controller/posts/Page.php @@ -59,6 +59,7 @@ class Page extends Backend return json($result); } + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -68,13 +69,12 @@ class Page extends Backend */ private function initForm() { - //从总后台进入 + $first_siteid=null; if ($this->auth->isSuperAdmin()){ $sitelist = Sites::all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + $first_siteid=$sitelist?$sitelist[0]['id']:$first_siteid; } - //从站点后台进入 else { $this->view->assign('siteList', null); $first_siteid = \think\Session::get('user_site_id'); @@ -149,7 +149,7 @@ class Page extends Backend } $this->view->assign("row", $row); $this->initForm(); - $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'])); + $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'],['siteid'=>$row->site_id])); return $this->view->fetch(); } diff --git a/application/admin/view/posts/archives/index.html b/application/admin/view/posts/archives/index.html index abf96369..c9774211 100644 --- a/application/admin/view/posts/archives/index.html +++ b/application/admin/view/posts/archives/index.html @@ -11,8 +11,8 @@
{:__('Recyclebin')} diff --git a/application/admin/view/posts/channel/add.html b/application/admin/view/posts/channel/add.html index d718c396..5c4e15b5 100644 --- a/application/admin/view/posts/channel/add.html +++ b/application/admin/view/posts/channel/add.html @@ -57,7 +57,7 @@