diff --git a/module/doc/control.php b/module/doc/control.php index f566d451e0..05c9b37eb0 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -85,14 +85,10 @@ class doc extends control $projectID = 0; if($libID) { - $type = 'custom'; - $lib = $this->doc->getLibByID($libID); - if($lib->product or $lib->project) - { - $type = $lib->product ? 'product' : 'project'; - $productID = $lib->product; - $projectID = $lib->project; - } + $lib = $this->doc->getLibByID($libID); + $type = $lib->type; + $productID = $lib->product; + $projectID = $lib->project; } $this->libs = $this->doc->getLibs($type); @@ -317,7 +313,7 @@ class doc extends control } $lib = $this->doc->getLibByID($libID); - $type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom'); + $type = $lib->type; /* According the from, set menus. */ if($this->from == 'product') @@ -393,8 +389,8 @@ class doc extends control if($doc->contentType == 'markdown') $this->config->doc->markdown->edit = array('id' => 'content', 'tools' => 'toolbar'); - $lib = $this->doc->getLibByID($libID); - $type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom'); + $lib = $this->doc->getLibByID($libID); + $type = $lib->type; $this->doc->setMenu($type, $libID, $doc->module, $lib->product, $lib->project); $this->view->title = $lib->name . $this->lang->colon . $this->lang->doc->edit; @@ -431,7 +427,7 @@ class doc extends control /* Check priv when lib is product or project. */ $lib = $this->doc->getLibByID($doc->lib); - $type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom'); + $type = $lib->type; /* Set menu. */ $this->doc->setMenu($type, $doc->lib, $doc->module, $lib->product, $lib->project); @@ -626,7 +622,7 @@ class doc extends control { setcookie('product', $product, $this->config->cookieLife, $this->config->webRoot); - $libName = isset($this->lang->doc->systemLibs[$type]) ? $this->lang->doc->systemLibs[$type] : $this->lang->doc->customAB; + $libName = $this->lang->doc->libTypeList[$type]; $crumb = html::a(inlink('allLibs', "type=$type&product=$product"), $libName); if($product and $type == 'project') $crumb = $this->doc->getProductCrumb($product); @@ -646,7 +642,10 @@ class doc extends control $subLibs = $this->doc->getSubLibGroups($type, array_keys($libs)); if($this->cookie->browseType == 'bylist') $this->view->users = $this->loadModel('user')->getPairs('noletter'); } - if($type == 'custom') $this->view->itemCounts = $this->doc->statLibCounts(array_keys($libs)); + else + { + $this->view->itemCounts = $this->doc->statLibCounts(array_keys($libs)); + } $this->view->type = $type; $this->view->libs = $libs; diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index dc5d8f1c40..de40b1fb92 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -100,6 +100,10 @@ $lang->doc->libTypeList['product'] = $lang->productCommon . '文档库'; $lang->doc->libTypeList['project'] = $lang->projectCommon . '文档库'; $lang->doc->libTypeList['custom'] = '自定义文档库'; +$lang->doc->libIconList['product'] = 'icon-cube'; +$lang->doc->libIconList['project'] = 'icon-stack'; +$lang->doc->libIconList['custom'] = 'icon-folder-o'; + $lang->doc->systemLibs['product'] = $lang->productCommon; $lang->doc->systemLibs['project'] = $lang->projectCommon; diff --git a/module/doc/model.php b/module/doc/model.php index 1e256f99d6..c46f9c8af0 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -43,13 +43,10 @@ class docModel extends model die(js::locate('back')); } - $type = $lib->product ? 'product' : 'custom'; - $type = $lib->project ? 'project' : $type; + $type = $lib->type; } - $mainLib = $type == 'custom' ? $this->lang->doc->customAB : $mainLib; - $mainLib = $type == 'product' ? $this->lang->productCommon : $mainLib; - $mainLib = $type == 'project' ? $this->lang->projectCommon : $mainLib; + $mainLib = isset($this->lang->doc->libTypeList[$type]) ? $this->lang->doc->libTypeList[$type] : $mainLib; $selectHtml .= "
"; $selectHtml .= "
"; @@ -61,17 +58,19 @@ class docModel extends model $selectHtml .= '
  • ' . html::a($link, " {$fastMenu}") . '
  • '; } $selectHtml .= "
  • "; - $selectHtml .= '
  • ' . html::a(helper::createLink('doc', 'allLibs', "type=product"), " {$this->lang->productCommon}") . '
  • '; - $selectHtml .= '
  • ' . html::a(helper::createLink('doc', 'allLibs', "type=project"), " {$this->lang->projectCommon}") . '
  • '; - $selectHtml .= '
  • ' . html::a(helper::createLink('doc', 'allLibs', "type=custom"), " {$this->lang->doc->customAB}") . '
  • '; + foreach($this->lang->doc->libTypeList as $libType => $libName) + { + $selectHtml .= '
  • ' . html::a(helper::createLink('doc', 'allLibs', "type=$libType"), " {$this->lang->doc->libTypeList[$libType]}") . '
  • '; + } $selectHtml .='
    '; $currentLib = 0; if(strpos('product,project,custom', $type) !== false) { - if($type == 'custom') $currentLib = $libID; if($type == 'product') $currentLib = $productID; if($type == 'project') $currentLib = $projectID; + if($type != 'product' and $type != 'project') $currentLib = $libID; + if($currentLib) { $allLibGroups = $this->getAllLibGroups(); @@ -82,93 +81,31 @@ class docModel extends model $selectHtml .= "
    "; $selectHtml .= "" . $currentLibName . ' '; $selectHtml .='
    '; } } - $actions = ''; - $customMenuKey = $this->config->global->flow . '_doc'; - if(isset($this->config->customMenu->{$customMenuKey})) - { - $customMenu = json_decode($this->config->customMenu->{$customMenuKey}, true); - $menuLibIdList = array(); - foreach($customMenu as $i => $menu) - { - if(strpos($menu['name'], 'custom') === 0) - { - $menuLibID = (int)substr($menu['name'], 6); - if($menuLibID) $menuLibIdList[$i] = $menuLibID; - } - } - - $productIdList = array(); - $projectIdList = array(); - if($menuLibIdList) - { - $libs = $this->dao->select('id,name,product,project')->from(TABLE_DOCLIB)->where('id')->in($menuLibIdList)->fetchAll('id'); - foreach($libs as $lib) - { - if($lib->product) $productIdList[] = $lib->product; - if($lib->project) $projectIdList[] = $lib->project; - } - } - $products = $productIdList ? $this->dao->select('id,name')->from(TABLE_PRODUCT)->where('id')->in($productIdList)->fetchPairs('id', 'name') : array(); - $projects = $projectIdList ? $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchPairs('id', 'name') : array(); - foreach($menuLibIdList as $i => $menuLibID) - { - $lib = $libs[$menuLibID]; - $libName = ''; - if($lib->product) $libName = isset($products[$lib->product]) ? '[' . $products[$lib->product] . ']' : ''; - if($lib->project) $libName = isset($projects[$lib->project]) ? '[' . $projects[$lib->project] . ']' : ''; - $libName .= $lib->name; - $customMenu[$i]['link'] = "{$libName}|doc|browse|libID={$menuLibID}"; - } - - foreach($customMenu as $menu) - { - if(isset($menu['link'])) - { - list($menuLabel, $module, $method, $vars) = explode('|', $menu['link']); - $actions .= html::a(helper::createLink($module, $method, $vars), $menuLabel, '', "class='btn'"); - } - } - } - + $actions = ''; $actions .= common::hasPriv('doc', 'createLib') ? html::a(helper::createLink('doc', 'createLib', "type={$type}&objectID={$currentLib}"), " " . $this->lang->doc->createLib, '', "class='btn btn-secondary iframe'") : ''; if($libID and common::hasPriv('doc', 'create')) $actions .= html::a(helper::createLink('doc', 'create', "libID=$libID"), " " . $this->lang->doc->create, '', "class='btn btn-primary'"); @@ -215,7 +152,10 @@ class docModel extends model } else { - $stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('product')->eq('0')->andWhere('project')->eq(0)->orderBy('`order`, id desc')->query(); + $stmt = $this->dao->select('*')->from(TABLE_DOCLIB) + ->where('deleted')->eq(0) + ->beginIF($type)->andWhere('type')->eq($type)->fi() + ->orderBy('`order`, id desc')->query(); } $libPairs = array(); @@ -957,7 +897,7 @@ class docModel extends model } else { - $stmt = $stmt->andWhere('project')->eq(0)->andWhere('product')->eq(0); + $stmt = $stmt->andWhere('type')->eq($type); } if(isset($projects)) $stmt = $stmt->andWhere('project')->in($projects); @@ -986,7 +926,7 @@ class docModel extends model public function getAllLibGroups() { $libs = $this->getLibs('all'); - $stmt = $this->dao->select("id,product,project,name")->from(TABLE_DOCLIB) + $stmt = $this->dao->select("id,type,product,project,name")->from(TABLE_DOCLIB) ->where('deleted')->eq(0) ->andWhere("id")->in(array_keys($libs)) ->orderBy("product desc,project desc, `order` asc, id asc") @@ -995,21 +935,24 @@ class docModel extends model $customLibs = array(); $productLibs = array(); $projectLibs = array(); + + $otherLibs = array(); while($lib = $stmt->fetch()) { - if($lib->product) + if($lib->type == 'product') { $productLibs[$lib->product][$lib->id] = $lib->name; } - elseif($lib->project) + elseif($lib->type == 'project') { $projectLibs[$lib->project][$lib->id] = $lib->name; } else { - $customLibs[$lib->id] = $lib->name; + $otherLibs[$lib->type][$lib->id] = $lib->name; } } + $productIdList = array_keys($productLibs); $products = $this->dao->select('id,name,status')->from(TABLE_PRODUCT)->where('id')->in($productIdList)->andWhere('deleted')->eq('0')->orderBy('`order`_desc')->fetchAll(); if($this->config->global->flow == 'onlyStory' or $this->config->global->flow == 'onlyTest') @@ -1058,7 +1001,7 @@ class docModel extends model } } - return array('product' => $productOrderLibs, 'project' => $projectOrderLibs, 'custom' => $customLibs); + return array('product' => $productOrderLibs, 'project' => $projectOrderLibs) + $otherLibs; } /** @@ -1085,7 +1028,7 @@ class docModel extends model } else { - $stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('project')->eq(0)->andWhere('product')->eq(0)->orderBy('`order`, id desc')->query(); + $stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('type')->eq($type)->orderBy('`order`, id desc')->query(); } $i = 1; @@ -1389,58 +1332,6 @@ class docModel extends model return $node; } - /** - * Get crumbs. - * - * @param int $libID - * @param int $moduleID - * @param int $docID - * @access public - * @return string - */ - public function getCrumbs($libID, $moduleID = 0) - { - if(empty($libID)) return ''; - - $lib = $this->getLibById($libID); - if(!$this->checkPrivLib($lib)) - { - echo(js::alert($this->lang->doc->accessDenied)); - $loginLink = $this->config->requestType == 'GET' ? "?{$this->config->moduleVar}=user&{$this->config->methodVar}=login" : "user{$this->config->requestFix}login"; - if(strpos($this->server->http_referer, $loginLink) !== false) die(js::locate(inlink('index'))); - die(js::locate('back')); - } - - $type = $lib->product ? 'product' : 'custom'; - $type = $lib->project ? 'project' : $type; - - $mainLib = $type == 'product' ? $this->lang->productCommon : $this->lang->doc->customAB; - $mainLib = $type == 'project' ? $this->lang->projectCommon : $mainLib; - - $crumb = ''; - $productID = $this->cookie->product ? $this->cookie->product : '0'; - if($productID and $type == 'project' and $this->config->global->flow != 'onlyTask') - { - $crumb .= $this->getProductCrumb($productID, $lib->project); - } - else - { - $crumb .= html::a(helper::createLink('doc', 'allLibs', "type=$type&product=$productID"), $mainLib) . $this->lang->doc->separator; - } - if($lib->product or $lib->project) - { - $table = $lib->product ? TABLE_PRODUCT : TABLE_PROJECT; - $objectID = $lib->product ? $lib->product : $lib->project; - $object = $this->dao->select('id,name')->from($table)->where('id')->eq($objectID)->fetch(); - if($object) $crumb .= html::a(helper::createLink('doc', 'objectLibs', "type=$type&objectID=$objectID"), $object->name) . $this->lang->doc->separator; - } - - $parents = $moduleID ? $this->loadModel('tree')->getParents($moduleID) : array(); - $crumb .= html::a(helper::createLink('doc', 'browse', "libID=$libID&browseType=all¶m=0&orderBy=id_desc"), $lib->name); - foreach($parents as $module) $crumb .= $this->lang->doc->separator . html::a(helper::createLink('doc', 'browse', "libID=$libID&browseType=byModule¶m=$module->id&orderBy=id_desc"), $module->name); - return $crumb; - } - /** * Get product crumb. * diff --git a/module/doc/view/alllibs.html.php b/module/doc/view/alllibs.html.php index 24f0b7e758..51f5b0171a 100644 --- a/module/doc/view/alllibs.html.php +++ b/module/doc/view/alllibs.html.php @@ -23,9 +23,7 @@
    - doc->custom;?> - productCommon;?> - projectCommon;?> + doc->libTypeList[$type];?>