* rewrite the comments of tree module.
This commit is contained in:
+59
-14
@@ -13,16 +13,25 @@ class tree extends control
|
||||
{
|
||||
const NEW_CHILD_COUNT = 5;
|
||||
|
||||
/* 模块列表。*/
|
||||
/**
|
||||
* Module browse.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $viewType story|bug|case|doc
|
||||
* @param int $currentModuleID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browse($rootID, $viewType, $currentModuleID = 0)
|
||||
{
|
||||
/* 根据视图的不同,获得相应的产品或者文档库。*/
|
||||
/* According to the type, set the module root and modules. */
|
||||
if(strpos('story|bug|case', $viewType) !== false)
|
||||
{
|
||||
$product = $this->loadModel('product')->getById($rootID);
|
||||
$this->view->root = $product;
|
||||
$this->view->productModules = $this->tree->getOptionMenu($rootID, 'story');
|
||||
}
|
||||
/* The viewType is doc. */
|
||||
elseif(strpos($viewType, 'doc') !== false)
|
||||
{
|
||||
$this->loadModel('doc');
|
||||
@@ -43,19 +52,16 @@ class tree extends control
|
||||
|
||||
if($viewType == 'story')
|
||||
{
|
||||
/* 设置菜单。*/
|
||||
$this->product->setMenu($this->product->getPairs(), $rootID, 'story');
|
||||
$this->lang->tree->menu = $this->lang->product->menu;
|
||||
$this->lang->set('menugroup.tree', 'product');
|
||||
|
||||
/* 设置导航。*/
|
||||
$header['title'] = $this->lang->tree->manageProduct . $this->lang->colon . $product->name;
|
||||
$position[] = html::a($this->createLink('product', 'browse', "product=$rootID"), $product->name);
|
||||
$position[] = $this->lang->tree->manageProduct;
|
||||
}
|
||||
elseif($viewType == 'bug')
|
||||
{
|
||||
/* 设置菜单。*/
|
||||
$this->loadModel('bug')->setMenu($this->product->getPairs(), $rootID);
|
||||
$this->lang->tree->menu = $this->lang->bug->menu;
|
||||
$this->lang->set('menugroup.tree', 'qa');
|
||||
@@ -66,7 +72,6 @@ class tree extends control
|
||||
}
|
||||
elseif($viewType == 'case')
|
||||
{
|
||||
/* 设置菜单。*/
|
||||
$this->loadModel('testcase')->setMenu($this->product->getPairs(), $rootID);
|
||||
$this->lang->tree->menu = $this->lang->testcase->menu;
|
||||
$this->lang->set('menugroup.tree', 'qa');
|
||||
@@ -77,7 +82,6 @@ class tree extends control
|
||||
}
|
||||
elseif(strpos($viewType, 'doc') !== false)
|
||||
{
|
||||
/* 设置菜单。*/
|
||||
$this->doc->setMenu($this->doc->getLibs(), $rootID, 'doc');
|
||||
$this->lang->tree->menu = $this->lang->doc->menu;
|
||||
$this->lang->set('menugroup.tree', 'doc');
|
||||
@@ -99,7 +103,13 @@ class tree extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/* 编辑模块。*/
|
||||
/**
|
||||
* Edit a module.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function edit($moduleID)
|
||||
{
|
||||
if(!empty($_POST))
|
||||
@@ -112,14 +122,19 @@ class tree extends control
|
||||
$this->view->optionMenu = $this->tree->getOptionMenu($this->view->module->root, $this->view->module->type);
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noclosed');
|
||||
|
||||
/* 去掉自己和child。*/
|
||||
/* Remove self and childs from the $optionMenu. Because it's parent can't be self or childs. */
|
||||
$childs = $this->tree->getAllChildId($moduleID);
|
||||
foreach($childs as $childModuleID) unset($this->view->optionMenu[$childModuleID]);
|
||||
|
||||
die($this->display());
|
||||
}
|
||||
|
||||
/* 更新排序。*/
|
||||
/**
|
||||
* Update modules' orders.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateOrder()
|
||||
{
|
||||
if(!empty($_POST))
|
||||
@@ -129,7 +144,14 @@ class tree extends control
|
||||
}
|
||||
}
|
||||
|
||||
/* 维护子菜单。*/
|
||||
/**
|
||||
* Manage child modules.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $viewType
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function manageChild($rootID, $viewType)
|
||||
{
|
||||
if(!empty($_POST))
|
||||
@@ -139,7 +161,15 @@ class tree extends control
|
||||
}
|
||||
}
|
||||
|
||||
/* 删除某一个模块。*/
|
||||
/**
|
||||
* Delete a module.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param int $moduleID
|
||||
* @param string $confirm yes|no
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($rootID, $moduleID, $confirm = 'no')
|
||||
{
|
||||
if($confirm == 'no')
|
||||
@@ -154,14 +184,29 @@ class tree extends control
|
||||
}
|
||||
}
|
||||
|
||||
/* ajax请求: 返回某一个产品的模块列表。*/
|
||||
/**
|
||||
* AJAX: Get the option menu of modules.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $viewType
|
||||
* @param int $rootModuleID
|
||||
* @access public
|
||||
* @return string the html select string.
|
||||
*/
|
||||
public function ajaxGetOptionMenu($rootID, $viewType = 'product', $rootModuleID = 0)
|
||||
{
|
||||
$optionMenu = $this->tree->getOptionMenu($rootID, $viewType, $rootModuleID);
|
||||
die( html::select("module", $optionMenu, '', 'onchange=setAssignedTo()'));
|
||||
}
|
||||
|
||||
/* ajax请求: 返回某一个模块的son模块.*/
|
||||
/**
|
||||
* AJAX: get a module's son modules.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @param int $rootID
|
||||
* @access public
|
||||
* @return string json_encoded modules.
|
||||
*/
|
||||
public function ajaxGetSonModules($moduleID, $rootID = 0)
|
||||
{
|
||||
if($moduleID) die(json_encode($this->dao->findByParent($moduleID)->from(TABLE_MODULE)->fetchPairs('id', 'name')));
|
||||
|
||||
+157
-31
@@ -13,16 +13,30 @@
|
||||
<?php
|
||||
class treeModel extends model
|
||||
{
|
||||
/* 通过模块id获取模块信息。*/
|
||||
/**
|
||||
* Get module by ID.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByID($moduleID)
|
||||
{
|
||||
return $this->dao->findById((int)$moduleID)->from(TABLE_MODULE)->fetch();
|
||||
}
|
||||
|
||||
/* 生成查询的sql语句。*/
|
||||
/**
|
||||
* Build the sql query.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $type
|
||||
* @param int $startModule
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function buildMenuQuery($rootID, $type, $startModule)
|
||||
{
|
||||
/* 查找startModule。*/
|
||||
/* Set the start module. */
|
||||
$startModulePath = '';
|
||||
if($startModule > 0)
|
||||
{
|
||||
@@ -38,7 +52,15 @@ class treeModel extends model
|
||||
->get();
|
||||
}
|
||||
|
||||
/* 获取模块的下类列表,用于生成select控件。*/
|
||||
/**
|
||||
* Create an option menu in html.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $type
|
||||
* @param int $startModule
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOptionMenu($rootID, $type = 'story', $startModule = 0)
|
||||
{
|
||||
$treeMenu = array();
|
||||
@@ -95,7 +117,17 @@ class treeModel extends model
|
||||
return $lastMenu;
|
||||
}
|
||||
|
||||
/* 获取树状的模块列表。*/
|
||||
/**
|
||||
* Get the tree menu in html.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $type
|
||||
* @param int $startModule
|
||||
* @param string $userFunc the function used to create link
|
||||
* @param string $extra extra params
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getTreeMenu($rootID, $type = 'root', $startModule = 0, $userFunc, $extra = '')
|
||||
{
|
||||
$treeMenu = array();
|
||||
@@ -128,7 +160,13 @@ class treeModel extends model
|
||||
return $lastMenu;
|
||||
}
|
||||
|
||||
/* 获得系统文档库的树状列表。*/
|
||||
/**
|
||||
* Get the tree menu of system document library.
|
||||
*
|
||||
* @param string $libID product|project
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getSystemDocTreeMenu($libID)
|
||||
{
|
||||
$menu = "<ul id='tree'>";
|
||||
@@ -150,7 +188,7 @@ class treeModel extends model
|
||||
$menu .= '<li>' . html::a(helper::createLink('doc', 'browse', "libID=product&module=$module->id&productID=$productID"), $module->name) . '</li>';
|
||||
}
|
||||
|
||||
/* 如果项目文档模块不为空,则追加项目文档列表。*/
|
||||
/* If $projectModules not emtpy, append the project modules. */
|
||||
if($projectModules)
|
||||
{
|
||||
$menu .= '<li>';
|
||||
@@ -194,21 +232,39 @@ class treeModel extends model
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/* 生成需求链接。*/
|
||||
/**
|
||||
* Create link of a story.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createStoryLink($module)
|
||||
{
|
||||
$linkHtml = html::a(helper::createLink('product', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'");
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 生成文档链接。*/
|
||||
/**
|
||||
* Create link of a doc.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createDocLink($module)
|
||||
{
|
||||
$linkHtml = html::a(helper::createLink('doc', 'browse', "libID={$module->root}&&module={$module->id}"), $module->name, '_self', "id='module{$module->id}'");
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 生成模块编辑链接。*/
|
||||
/**
|
||||
* Create the manage link of a module.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createManageLink($module)
|
||||
{
|
||||
static $users;
|
||||
@@ -222,28 +278,54 @@ class treeModel extends model
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 生成Bug链接。*/
|
||||
/**
|
||||
* Create link of a bug.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createBugLink($module)
|
||||
{
|
||||
$linkHtml = html::a(helper::createLink('bug', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'");
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 生成case链接。*/
|
||||
/**
|
||||
* Create link of a test case.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createCaseLink($module)
|
||||
{
|
||||
$linkHtml = html::a(helper::createLink('testcase', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'");
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 生成测试任务的链接。*/
|
||||
/**
|
||||
* Create link of a test task.
|
||||
*
|
||||
* @param object $module
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function createTestTaskLink($module, $extra)
|
||||
{
|
||||
$linkHtml = html::a(helper::createLink('testtask', 'cases', "taskID=$extra&type=byModule&module={$module->id}"), $module->name, '_self', "id='module{$module->id}'");
|
||||
return $linkHtml;
|
||||
}
|
||||
|
||||
/* 获得某一个模块的直接下级模块。*/
|
||||
/**
|
||||
* Get sons of a module.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param int $moduleID
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getSons($rootID, $moduleID, $type = 'root')
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_MODULE)
|
||||
@@ -254,7 +336,13 @@ class treeModel extends model
|
||||
->fetchAll();
|
||||
}
|
||||
|
||||
/* 获得一个模块的id列表。*/
|
||||
/**
|
||||
* Get id list of a module's childs.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAllChildId($moduleID)
|
||||
{
|
||||
if($moduleID == 0) return array();
|
||||
@@ -262,7 +350,13 @@ class treeModel extends model
|
||||
return $this->dao->select('id')->from(TABLE_MODULE)->where('path')->like($module->path . '%')->fetchPairs();
|
||||
}
|
||||
|
||||
/* 获得一个模块的所有上级模块。*/
|
||||
/**
|
||||
* Get parents of a module.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getParents($moduleID)
|
||||
{
|
||||
if($moduleID == 0) return array();
|
||||
@@ -272,7 +366,13 @@ class treeModel extends model
|
||||
return $this->dao->select('*')->from(TABLE_MODULE)->where('id')->in($path)->orderBy('grade')->fetchAll();
|
||||
}
|
||||
|
||||
/* 更新排序信息。*/
|
||||
/**
|
||||
* Update modules' order.
|
||||
*
|
||||
* @param array $orders
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateOrder($orders)
|
||||
{
|
||||
foreach($orders as $moduleID => $order)
|
||||
@@ -281,7 +381,16 @@ class treeModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
/* 更新某一个模块的子模块。*/
|
||||
/**
|
||||
* Manage childs of a module.
|
||||
*
|
||||
* @param int $rootID
|
||||
* @param string $type
|
||||
* @param int $parentModuleID
|
||||
* @param array $childs
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function manageChild($rootID, $type, $parentModuleID, $childs)
|
||||
{
|
||||
$parentModule = $this->getByID($parentModuleID);
|
||||
@@ -300,10 +409,10 @@ class treeModel extends model
|
||||
{
|
||||
if(empty($moduleName)) continue;
|
||||
|
||||
/* 新增模块。*/
|
||||
/* The new modules. */
|
||||
if(is_numeric($moduleID))
|
||||
{
|
||||
$module->root = $rootID;
|
||||
$module->root = $rootID;
|
||||
$module->name = $moduleName;
|
||||
$module->parent = $parentModuleID;
|
||||
$module->grade = $grade;
|
||||
@@ -323,7 +432,13 @@ class treeModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
/* 编辑一个模块。*/
|
||||
/**
|
||||
* Update a module.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function update($moduleID)
|
||||
{
|
||||
$module = fixer::input('post')->specialChars('name')->get();
|
||||
@@ -338,15 +453,21 @@ class treeModel extends model
|
||||
$this->fixModulePath();
|
||||
}
|
||||
|
||||
/* 删除一个模块。*/
|
||||
/**
|
||||
* Delete a module.
|
||||
*
|
||||
* @param int $moduleID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($moduleID)
|
||||
{
|
||||
$module = $this->getById($moduleID);
|
||||
$childs = $this->getAllChildId($moduleID);
|
||||
|
||||
$this->dao->update(TABLE_MODULE)->set('grade = grade - 1')->where('id')->in($childs)->exec(); // 更新所有的下级模块的grade。
|
||||
$this->dao->update(TABLE_MODULE)->set('parent')->eq($module->parent)->where('parent')->eq($moduleID)->exec(); // 更新直接下级的parent。
|
||||
$this->dao->delete()->from(TABLE_MODULE)->where('id')->eq($moduleID)->exec(); // 删除自己。
|
||||
$this->dao->update(TABLE_MODULE)->set('grade = grade - 1')->where('id')->in($childs)->exec(); // Update grade of all childs.
|
||||
$this->dao->update(TABLE_MODULE)->set('parent')->eq($module->parent)->where('parent')->eq($moduleID)->exec(); // Update the parent of sons to my parent.
|
||||
$this->dao->delete()->from(TABLE_MODULE)->where('id')->eq($moduleID)->exec(); // Delete my self.
|
||||
$this->fixModulePath();
|
||||
|
||||
if($module->type == 'story') $this->dao->update(TABLE_STORY)->set('module')->eq($module->parent)->where('module')->eq($moduleID)->exec();
|
||||
@@ -354,17 +475,22 @@ class treeModel extends model
|
||||
if($module->type == 'case') $this->dao->update(TABLE_CASE)->set('module')->eq($module->parent)->where('module')->eq($moduleID)->exec();
|
||||
}
|
||||
|
||||
/* 修正modulePath字段。*/
|
||||
/**
|
||||
* Fix fieilds of all module, grade, parent, pathes and so on.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function fixModulePath()
|
||||
{
|
||||
/* 获得最大的级别。*/
|
||||
/* Get the max grade. */
|
||||
$maxGrade = $this->dao->select('MAX(grade) AS grade')->from(TABLE_MODULE)->fetch('grade');
|
||||
$modules = array();
|
||||
|
||||
/* 依次处理每个级别的模块。*/
|
||||
/* Cycle ervery grade. */
|
||||
for($grade = 1; $grade <= $maxGrade; $grade ++)
|
||||
{
|
||||
/* 当前级别的模块。*/
|
||||
/* Modules of current grade. */
|
||||
$gradeModules = $this->dao->select('id, parent, grade')->from(TABLE_MODULE)->where('grade')->eq($grade)->fetchAll('id');
|
||||
foreach($gradeModules as $moduleID => $module)
|
||||
{
|
||||
@@ -374,7 +500,7 @@ class treeModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 取parent模块的path。*/
|
||||
/* Get the parent module to compute path and grade of my self. */
|
||||
if(isset($modules[$module->parent]))
|
||||
{
|
||||
$module->path = $modules[$module->parent]->path . "$moduleID,";
|
||||
@@ -385,7 +511,7 @@ class treeModel extends model
|
||||
$modules += $gradeModules;
|
||||
}
|
||||
|
||||
/* 最后更新每一个模块。*/
|
||||
/* Save modules to database. */
|
||||
foreach($modules as $moduleID => $module)
|
||||
{
|
||||
$this->dao->update(TABLE_MODULE)->data($module)->where('id')->eq($module->id)->limit(1)->exec();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* The edit view of product module of ZenTaoPMS.
|
||||
* The edit view of tree module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2010 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
|
||||
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
|
||||
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
|
||||
* @package product
|
||||
* @package tree
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user