From af9f3f8d372e19f5efb2d82b1cc801ca31605913 Mon Sep 17 00:00:00 2001 From: chenfeiCF Date: Wed, 2 Mar 2016 14:24:49 +0800 Subject: [PATCH] * refactor browse method for doc module. --- module/doc/control.php | 67 ++------------------------ module/doc/model.php | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 62 deletions(-) diff --git a/module/doc/control.php b/module/doc/control.php index 83fcc27e3d..41f976594f 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -76,72 +76,15 @@ class doc extends control /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); - /* Get docs. */ - $modules = 0; - $docs=array(); - if($browseType == "bymodule") - { - if($moduleID) $modules = $this->tree->getAllChildID($moduleID); - $docs = $this->doc->getDocs($libID, $productID, $projectID, $modules, $sort, $pager); - } - elseif($browseType == "bysearch") - { - if($queryID) - { - $query = $this->search->getQuery($queryID); - if($query) - { - $this->session->set('docQuery', $query->sql); - $this->session->set('docForm', $query->form); - } - else - { - $this->session->set('docQuery', ' 1 = 1'); - } - } - else - { - if($this->session->docQuery == false) $this->session->set('docQuery', ' 1 = 1'); - } - $docQuery = str_replace("`product` = 'all'", '1', $this->session->docQuery); // Search all producti. - $docQuery = str_replace("`project` = 'all'", '1', $docQuery); // Search all project. - $docs = $this->dao->select('*')->from(TABLE_DOC)->where($docQuery) - ->andWhere('deleted')->eq(0) - ->orderBy($sort)->page($pager)->fetchAll(); - } + /* Get docs by browse type. */ + $docs = $this->doc->getDocsByBrowseType($productID, $projectID, $browseType, $libID, $queryID, $moduleID, $sort, $pager); /* Get the tree menu. */ - if($libID == 'product') - { - $moduleTree = $this->tree->getProductDocTreeMenu(); - } - elseif($libID == 'project') - { - $moduleTree = $this->tree->getProjectDocTreeMenu(); - } - else - { - $moduleTree = $this->tree->getTreeMenu($libID, $viewType = 'customdoc', $startModuleID = 0, array('treeModel', 'createDocLink')); - } + $moduleTree = $this->doc->getDocTreeMenu($libID); /* Build the search form. */ - $this->config->doc->search['actionURL'] = $this->createLink('doc', 'browse', "libID=$libID&moduleID=$moduleID&procuctID=$productID&projectID=$projectID&browseType=bySearch&queryID=myQueryID"); - $this->config->doc->search['queryID'] = $queryID; - $this->config->doc->search['params']['product']['values'] = array(''=>'') + $this->product->getPairs('nocode') + array('all'=>$this->lang->doc->allProduct); - $this->config->doc->search['params']['project']['values'] = array(''=>'') + $this->project->getPairs('nocode') + array('all'=>$this->lang->doc->allProject); - $this->config->doc->search['params']['lib']['values'] = array(''=>'') + $this->libs; - $this->config->doc->search['params']['type']['values'] = array(''=>'') + $this->config->doc->search['params']['type']['values']; - - /* Get the modules. */ - if($libID == 'product' or $libID == 'project') - { - $moduleOptionMenu = $this->tree->getOptionMenu(0, $libID . 'doc', $startModuleID = 0); - } - else - { - $moduleOptionMenu = $this->tree->getOptionMenu($libID, 'customdoc', $startModuleID = 0); - } - $this->config->doc->search['params']['module']['values'] = $moduleOptionMenu; + $actionURL = $this->createLink('doc', 'browse', "libID=$libID&moduleID=$moduleID&procuctID=$productID&projectID=$projectID&browseType=bySearch&queryID=myQueryID"); + $this->doc->buildSearchForm($libID, $this->libs, $queryID, $actionURL); $this->search->setSearchParams($this->config->doc->search); $this->view->libID = $libID; diff --git a/module/doc/model.php b/module/doc/model.php index 6a645bd278..15051e2584 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -106,6 +106,57 @@ class docModel extends model if(!dao::isError()) return common::createChanges($oldLib, $lib); } + /** + * Get docs by browse type. + * + * @param int $productID + * @param int $projectID + * @param string $browseType + * @param string $libID + * @param int $queryID + * @param int $moduleID + * @param string $sort + * @param object $pager + * @access public + * @return array + */ + public function getDocsByBrowseType($productID, $projectID, $browseType, $libID, $queryID, $moduleID, $sort, $pager) + { + if($browseType == "bymodule") + { + $modules = 0; + if($moduleID) $modules = $this->loadModel('tree')->getAllChildId($moduleID); + $docs = $this->getDocs($libID, $productID, $projectID, $modules, $sort, $pager); + } + elseif($browseType == "bysearch") + { + if($queryID) + { + $query = $this->loadModel('search')->getQuery($queryID); + if($query) + { + $this->session->set('docQuery', $query->sql); + $this->session->set('docForm', $query->form); + } + else + { + $this->session->set('docQuery', ' 1 = 1'); + } + } + else + { + if($this->session->docQuery == false) $this->session->set('docQuery', ' 1 = 1'); + } + $docQuery = str_replace("`product` = 'all'", '1', $this->session->docQuery); // Search all producti. + $docQuery = str_replace("`project` = 'all'", '1', $docQuery); // Search all project. + $docs = $this->dao->select('*')->from(TABLE_DOC)->where($docQuery)->andWhere('deleted')->eq(0)->orderBy($sort)->page($pager)->fetchAll(); + } + + if($docs) return $docs; + + return array(); + } + /** * Get docs. * @@ -243,6 +294,37 @@ class docModel extends model ->exec(); if(!dao::isError()) return common::createChanges($oldDoc, $doc); } + + /** + * Build search form. + * + * @param string $libID + * @param array $libs + * @param int $queryID + * @param string $actionURL + * @access public + * @return void + */ + public function buildSearchForm($libID, $libs, $queryID, $actionURL) + { + $this->config->doc->search['actionURL'] = $actionURL; + $this->config->doc->search['queryID'] = $queryID; + $this->config->doc->search['params']['product']['values'] = array(''=>'') + $this->loadModel('product')->getPairs('nocode') + array('all'=>$this->lang->doc->allProduct); + $this->config->doc->search['params']['project']['values'] = array(''=>'') + $this->loadModel('project')->getPairs('nocode') + array('all'=>$this->lang->doc->allProject); + $this->config->doc->search['params']['lib']['values'] = array(''=>'') + $libs; + $this->config->doc->search['params']['type']['values'] = array(''=>'') + $this->config->doc->search['params']['type']['values']; + + /* Get the modules. */ + if($libID == 'product' or $libID == 'project') + { + $moduleOptionMenu = $this->loadModel('tree')->getOptionMenu(0, $libID . 'doc', $startModuleID = 0); + } + else + { + $moduleOptionMenu = $this->loadModel('tree')->getOptionMenu($libID, 'customdoc', $startModuleID = 0); + } + $this->config->doc->search['params']['module']['values'] = $moduleOptionMenu; + } /** * Get docs of a product. @@ -296,6 +378,31 @@ class docModel extends model return $this->dao->findByType('projectdoc')->from(TABLE_MODULE)->andWhere('type')->eq('projectdoc')->fetchPairs('id', 'name'); } + /** + * Get doc tree menu. + * + * @param string $libID + * @access public + * @return array + */ + public function getDocTreeMenu($libID) + { + if($libID == 'product') + { + $moduleTree = $this->loadModel('tree')->getProductDocTreeMenu(); + } + elseif($libID == 'project') + { + $moduleTree = $this->loadModel('tree')->getProjectDocTreeMenu(); + } + else + { + $moduleTree = $this->loadModel('tree')->getTreeMenu($libID, $viewType = 'customdoc', $startModuleID = 0, array('treeModel', 'createDocLink')); + } + + return $moduleTree; + } + /** * Extract css styles for tables created in kindeditor. *