+ add the feature of delete to project module.

This commit is contained in:
wangchunsheng
2010-04-12 08:49:09 +00:00
parent bda1c07d67
commit dc2c5d677c
3 changed files with 108 additions and 88 deletions

View File

@@ -45,6 +45,7 @@ class project extends control
{
$this->locate($this->createLink($this->moduleName, 'task', "projectID=$projectID"));
}
/* task, story, bug等方法的一些公共操作。*/
private function commonAction($projectID = 0)
{
@@ -86,8 +87,10 @@ class project extends control
$projectID = $project->id;
/* 记录用户当前选择的列表。*/
$this->app->session->set('taskList', $this->app->getURI(true));
$this->app->session->set('storyList', $this->app->getURI(true));
$uri = $this->app->getURI(true);
$this->app->session->set('taskList', $uri);
$this->app->session->set('storyList', $uri);
$this->app->session->set('projectList', $uri);
/* 设定header和position信息。*/
$this->view->header->title = $project->name . $this->lang->colon . $this->lang->project->task;
@@ -337,6 +340,7 @@ class project extends control
{
$projectID = $this->project->create();
if(dao::isError()) die(js::error(dao::getError()));
$this->loadModel('action')->create('project', $projectID, 'opened');
die(js::locate($this->createLink('project', 'browse', "projectID=$projectID"), 'parent'));
}
@@ -356,8 +360,10 @@ class project extends control
$browseProjectLink = $this->createLink('project', 'browse', "projectID=$projectID");
if(!empty($_POST))
{
$this->project->update($projectID);
$changes = $this->project->update($projectID);
if(dao::isError()) die(js::error(dao::getError()));
$actionID = $this->loadModel('action')->create('project', $projectID, 'edited');
$this->action->logHistory($actionID, $changes);
die(js::locate($this->createLink('project', 'view', "projectID=$projectID"), 'parent'));
}
@@ -389,14 +395,21 @@ class project extends control
public function view($projectID)
{
/* 公共的操作。*/
$project = $this->commonAction($projectID);
$project = $this->project->getById($projectID);
if(!$project) die(js::error($this->lang->notFound) . js::locate('back'));
$header['title'] = $this->lang->project->view;
$position[] = $header['title'];
/* 设置菜单。*/
$this->project->setMenu($this->projects, $project->id);
$this->view->header->title = $this->lang->project->view;
$this->view->position[] = $this->view->header->title;
$this->view->project = $project;
$this->view->products = $this->project->getProducts($project->id);
$this->view->groups = $this->loadModel('group')->getPairs();
$this->view->actions = $this->loadModel('action')->getList('project', $projectID);
$this->view->users = $this->loadModel('user')->getPairs();
$this->assign('header', $header);
$this->assign('position', $position);
$this->assign('groups', $this->loadModel('group')->getPairs());
$this->display();
}
@@ -410,9 +423,9 @@ class project extends control
}
else
{
$this->project->delete($projectID);
echo js::locate($this->createLink('project', 'browse'), 'parent');
exit;
$this->project->delete(TABLE_PROJECT, $projectID);
$this->session->set('project', ''); // 清除session。
die(js::locate(inlink('index'), 'parent'));
}
}

View File

@@ -108,6 +108,7 @@ class projectModel extends model
/* 更新一个项目。*/
public function update($projectID)
{
$oldProject = $this->getById($projectID);
$this->lang->project->team = $this->lang->project->teamname;
$projectID = (int)$projectID;
$project = fixer::input('post')
@@ -128,27 +129,16 @@ class projectModel extends model
->where('id')->eq($projectID)
->limit(1)
->exec();
}
/* 删除一个项目。*/
public function delete($projectID)
{
return $this->dao->delete()->from(TABLE_PROJECT)->where('id')->eq((int)$projectID)->limit(1)->exec();
}
/* 获得项目目录列表。*/
public function getCats()
{
$cats = array();
$stmt = $this->dbh->query("SELECT id, name FROM " . TABLE_PROJECT . " WHERE isCat = '1'");
while($cat = $stmt->fetch()) $cats[$cat->id] = $cat->name;
return $cats;
if(!dao::isError()) return common::createChanges($oldProject, $project);
}
/* 获得项目id=>name列表。*/
public function getPairs()
{
$projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('iscat')->eq(0)->orderBy('status, end desc')->fetchAll();
$projects = $this->dao->select('*')->from(TABLE_PROJECT)
->where('iscat')->eq(0)
->andWhere('deleted')->eq(0)
->orderBy('status, end desc')->fetchAll();
$pairs = array();
foreach($projects as $project)
{
@@ -162,6 +152,7 @@ class projectModel extends model
{
return $this->dao->select('*')->from(TABLE_PROJECT)->where('iscat')->eq(0)
->onCaseOf($status != 'all')->andWhere('status')->in($status)->endcase()
->andWhere('deleted')->eq(0)
->orderBy('status, end DESC')
->fetchAll();
}
@@ -193,7 +184,12 @@ class projectModel extends model
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$projectID)->exec();
if(!isset($_POST['products'])) return;
$products = array_unique($_POST['products']);
foreach($products as $productID) $this->dao->insert(TABLE_PROJECTPRODUCT)->set('project')->eq((int)$projectID)->set('product')->eq((int)$productID)->exec();
foreach($products as $productID)
{
$data->project = $projectID;
$data->product = $productID;
$this->dao->insert(TABLE_PROJECTPRODUCT)->data($data)->exec();
}
}
/* 获得相关项目列表。*/
@@ -207,6 +203,7 @@ class projectModel extends model
->on('t1.id = t2.project')
->where('t2.product')->in($products)
->andWhere('t1.id')->ne((int)$projectID)
->andWhere('t1.deleted')->eq(0)
->orderBy('t1.id')
->fetchPairs();
}
@@ -293,6 +290,7 @@ class projectModel extends model
public function linkStory($projectID)
{
if($this->post->stories == false) return false;
$this->loadModel('action');
$versions = $this->loadModel('story')->getVersions($this->post->stories);
foreach($this->post->stories as $key => $storyID)
{
@@ -303,6 +301,7 @@ class projectModel extends model
$data->version = $versions[$storyID];
$this->dao->insert(TABLE_PROJECTSTORY)->data($data)->exec();
$this->story->setStage($storyID);
$this->action->create('story', $storyID, 'linked2project', '', $projectID);
}
}
@@ -311,6 +310,7 @@ class projectModel extends model
{
$this->dao->delete()->from(TABLE_PROJECTSTORY)->where('project')->eq($projectID)->andWhere('story')->eq($storyID)->limit(1)->exec();
$this->loadModel('story')->setStage($storyID);
$this->loadModel('action')->create('story', $storyID, 'unlinkedfromproject', '', $projectID);
}
/* 获取团队成员。*/
@@ -383,7 +383,10 @@ class projectModel extends model
public function computeBurn()
{
$today = helper::today();
$projects = $this->dao->select('id')->from(TABLE_PROJECT)->where("end >= '$today'")->orWhere('end')->eq('0000-00-00')->fetchPairs();
$projects = $this->dao->select('id')->from(TABLE_PROJECT)
->where("end >= '$today'")
->orWhere('end')->eq('0000-00-00')
->fetchPairs();
$burns = $this->dao->select("project, '$today' AS date, sum(`left`) AS `left`, SUM(consumed) AS `consumed`")
->from(TABLE_TASK)
->where('project')->in($projects)
@@ -421,7 +424,7 @@ class projectModel extends model
}
else
{
$sets = $sql->orderBy('date')->fetchAll('name');
$sets = $sql->orderBy('date')->fetchAll('name');
$current = $project->begin;
$end = $project->end;
if($sets)

View File

@@ -25,62 +25,66 @@
<?php include '../../common/view/header.html.php';?>
<div class='yui-d0'>
<table align='center' class='table-1'>
<caption><?php echo $project->name;?></caption>
<tr>
<th class='rowhead'><?php echo $lang->project->name;?></th>
<td><?php echo $project->name;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->code;?></th>
<td><?php echo $project->code;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->beginAndEnd;?></th>
<td><?php echo $project->begin . ' ~ ' . $project->end;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->goal;?></th>
<td><?php echo nl2br($project->goal);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->desc;?></th>
<td><?php echo nl2br($project->desc);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->status;?></th>
<td class='<?php echo $project->status;?>'><?php $lang->show($lang->project->statusList, $project->status);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->lblStats;?></th>
<td><?php printf($lang->project->stats, $project->totalEstimate, $project->totalConsumed, $project->totalLeft, 10)?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->products;?></th>
<td>
<?php foreach($products as $productID => $productName) echo html::a($this->createLink('product', 'browse', "productID=$productID"), $productName) . '<br />';?>
</td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->acl;?></th>
<td><?php echo $lang->project->aclList[$project->acl];?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->whitelist;?></th>
<td>
<?php
$whitelist = explode(',', $project->whitelist);
foreach($whitelist as $groupID) if(isset($groups[$groupID])) echo $groups[$groupID] . '&nbsp;';
?>
</td>
</tr>
<tr>
<td colspan='2' class='a-center'>
<?php
common::printLink('project', 'edit', "projectID=$project->id", $lang->project->edit);
common::printLink('project', 'delete', "projectID=$project->id", $lang->project->delete, 'hiddenwin');
?>
</td>
</tr>
</table>
<caption><?php echo $project->name;?></caption>
<tr>
<th class='rowhead'><?php echo $lang->project->name;?></th>
<td class='<?php if($project->deleted) echo 'deleted';?>'><?php echo $project->name;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->code;?></th>
<td><?php echo $project->code;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->beginAndEnd;?></th>
<td><?php echo $project->begin . ' ~ ' . $project->end;?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->goal;?></th>
<td><?php echo nl2br($project->goal);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->desc;?></th>
<td><?php echo nl2br($project->desc);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->status;?></th>
<td class='<?php echo $project->status;?>'><?php $lang->show($lang->project->statusList, $project->status);?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->lblStats;?></th>
<td><?php printf($lang->project->stats, $project->totalEstimate, $project->totalConsumed, $project->totalLeft, 10)?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->products;?></th>
<td>
<?php foreach($products as $productID => $productName) echo html::a($this->createLink('product', 'browse', "productID=$productID"), $productName) . '<br />';?>
</td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->acl;?></th>
<td><?php echo $lang->project->aclList[$project->acl];?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->project->whitelist;?></th>
<td>
<?php
$whitelist = explode(',', $project->whitelist);
foreach($whitelist as $groupID) if(isset($groups[$groupID])) echo $groups[$groupID] . '&nbsp;';
?>
</td>
</tr>
</table>
<div class='a-center f-16px strong'>
<?php
$browseLink = $this->session->projectList ? $this->session->projectList : inlink('task', "projectID=$project->id");
if(!$project->deleted)
{
common::printLink('project', 'edit', "projectID=$project->id", $lang->project->edit);
common::printLink('project', 'delete', "projectID=$project->id", $lang->project->delete, 'hiddenwin');
}
echo html::a($browseLink, $lang->goback);
?>
</div>
<?php include '../../common/view/action.html.php';?>
</div>
<?php include '../../common/view/footer.html.php';?>