* Code for task#633.

This commit is contained in:
chencongzhi520@gmail.com
2012-06-13 06:16:07 +00:00
parent 0c0eca75d1
commit dbc7b70792
8 changed files with 85 additions and 91 deletions

View File

@@ -439,7 +439,7 @@ class commonModel extends model
* @access public
* @return void
*/
public function getPreAndNextObject($type, $objectIDs, $objectID)
public function getPreAndNextObject($type, $objectID)
{
$table = '';
switch($type)
@@ -451,6 +451,20 @@ class commonModel extends model
default:break;
}
/* Get objectIDs. */
$queryCondition = $type . 'QueryCondition';
$queryCondition = $this->session->$queryCondition;
$orderBy = $type . 'OrderBy';
$orderBy = $this->session->$orderBy;
$objects = $this->dao->select('*')->from($table)
->beginIF($queryCondition != false)->where($queryCondition)->fi()
->beginIF($orderBy != false)->orderBy($orderBy)->fi()
->fetchAll();
$tmpObjectIDs = array();
foreach($objects as $object) $tmpObjectIDs[$object->id] = $object->id;
$objectIDs = ',' . implode(',', $tmpObjectIDs) . ',';
/* Current object. */
$currentStart = strpos($objectIDs, ',' . $objectID . ',') + 1;
$currentEnd = $currentStart + strlen($objectID) - 1;
@@ -483,4 +497,34 @@ class commonModel extends model
return $preAndNextObject;
}
/**
* Save one executed query.
*
* @param string $sql
* @param string $objectType story|task|bug|testcase
* @access public
* @return void
*/
public function saveQueryCondition($sql, $objectType)
{
/* Set the query condition session. */
$queryCondition = explode('WHERE', $sql);
$queryCondition = explode('ORDER', $queryCondition[1]);
$queryCondition = str_replace('t1.', '', $queryCondition[0]);
$this->session->set($objectType . 'QueryCondition', $queryCondition);
/* Set the query condition session. */
$orderBy = explode('ORDER BY', $sql);
if(isset($orderBy[1]))
{
$orderBy = explode('limit', $orderBy[1]);
$orderBy = str_replace('t1.', '', $orderBy[0]);
$this->session->set($objectType . 'OrderBy', $orderBy);
}
else
{
$this->session->set($objectType . 'OrderBy', '');
}
}
}

View File

@@ -154,7 +154,8 @@ class project extends control
if($this->session->taskQuery == false) $this->session->set('taskQuery', ' 1 = 1');
}
$taskQuery = str_replace("`project` = 'all'", '1', $this->session->taskQuery); // Search all project.
$this->session->set('taskReportCondition', $taskQuery);
$this->session->set('taskQueryCondition', $taskQuery);
$this->session->set('taskOrderBy', $orderBy);
$tasks = $this->project->getSearchTasks($taskQuery, $pager, $orderBy);
}

View File

@@ -131,7 +131,7 @@ class release extends control
$release = $this->release->getById((int)$releaseID, true);
if(!$release) die(js::error($this->lang->notFound) . js::locate('back'));
$stories = $this->dao->select('*')->from(TABLE_STORY)->where('id')->in($release->stories)->fetchAll();
$this->story->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
$bugs = $this->dao->select('*')->from(TABLE_BUG)->where('id')->in($release->bugs)->fetchAll();
$this->commonAction($release->product);

View File

@@ -367,16 +367,6 @@ class story extends control
/* Set the menu. */
$this->product->setMenu($this->product->getPairs(), $product->id);
/* Get the previous and next story. */
$stories = $this->dao->select('*')->from(TABLE_STORY)
->beginIF($this->session->storyQueryCondition != false)->where($this->session->storyQueryCondition)->fi()
->beginIF($this->session->storyOrderBy != false)->orderBy($this->session->storyOrderBy)->fi()
->fetchAll();
$tmpStoryIDs = array();
foreach($stories as $tmpStory) $tmpStoryIDs[$tmpStory->id] = $tmpStory->id;
$storyIDs = ',' . implode(',', $tmpStoryIDs) . ',';
$this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('story', $storyIDs, $storyID);
$header['title'] = $product->name . $this->lang->colon . $this->lang->story->view . $this->lang->colon . $story->title;
$position[] = html::a($this->createLink('product', 'browse', "product=$product->id"), $product->name);
$position[] = $this->lang->story->view;
@@ -393,6 +383,7 @@ class story extends control
$this->view->actions = $this->action->getList('story', $storyID);
$this->view->modulePath = $modulePath;
$this->view->version = $version == 0 ? $story->version : $version;
$this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('story', $storyID);
$this->display();
}

View File

@@ -635,7 +635,7 @@ class storyModel extends model
->andWhere('t1.deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
$this->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
return $stories;
}
@@ -763,7 +763,8 @@ class storyModel extends model
->orderBy($orderBy)
->page($pager)
->fetchAll();
$this->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
return $stories;
}
@@ -830,7 +831,8 @@ class storyModel extends model
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
$this->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
if(!$tmpStories) return array();
@@ -848,36 +850,7 @@ class storyModel extends model
}
return $stories;
}
/**
* Save one executed query.
*
* @param string $sql
* @access public
* @return void
*/
public function saveQueryCondition($sql)
{
/* Set the query condition session. */
$queryCondition = explode('WHERE', $sql);
$queryCondition = explode('ORDER', $queryCondition[1]);
$queryCondition = str_replace('t1.', '', $queryCondition[0]);
$this->session->set('storyQueryCondition', $queryCondition);
/* Set the query condition session. */
$orderBy = explode('ORDER BY', $sql);
if(isset($orderBy[1]))
{
$orderBy = explode('limit', $orderBy[1]);
$orderBy = str_replace('t1.', '', $orderBy[0]);
$this->session->set('storyOrderBy', $orderBy);
}
else
{
$this->session->set('storyOrderBy', '');
}
}
/**
* Get stories list of a project.
*
@@ -939,7 +912,7 @@ class storyModel extends model
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll('id');
$this->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
return $stories;
}
@@ -987,11 +960,11 @@ class storyModel extends model
->beginIF($type == 'closedby')->andWhere('closedby')->eq($this->app->user->account)->fi()
->orderBy($orderBy)->page($pager)->fetchAll();
$this->saveQueryCondition($this->dao->get());
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
return $stories;
}
/**
* Get doing projects' members of a story.
*

View File

@@ -237,7 +237,7 @@ class task extends control
$this->project->setMenu($this->project->getPairs(), $project->id);
/* Get all tasks. */
$allTasks = $this->dao->select('*')->from(TABLE_TASK)->alias('t1')->where($this->session->taskReportCondition)->orderBy($orderBy)->fetchAll('id');
$allTasks = $this->dao->select('*')->from(TABLE_TASK)->alias('t1')->where($this->session->taskQueryCondition)->orderBy($orderBy)->fetchAll('id');
if(!$allTasks) $allTasks = array();
/* Initialize the tasks whose need to edited. */
@@ -343,31 +343,17 @@ class task extends control
$project = $this->project->getById($task->project);
$this->project->setMenu($this->project->getPairs(), $project->id);
/* Get the previous and next task. */
if($this->session->taskReportCondition)
{
$tasks = $this->dao->select('*')->from(TABLE_TASK)->alias('t1')->where($this->session->taskReportCondition)->orderBy($this->session->taskOrderBy)->fetchAll();
$tmpTaskIDs = array();
foreach($tasks as $tmpTask) $tmpTaskIDs[$tmpTask->id] = $tmpTask->id;
$taskIDs = ',' . implode(',', $tmpTaskIDs) . ',';
$this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('task', $taskIDs, $taskID);
}
else
{
$this->view->preAndNext->pre = '';
$this->view->preAndNext->next = '';
}
$header['title'] = $project->name . $this->lang->colon . $this->lang->task->view;
$position[] = html::a($this->createLink('project', 'browse', "projectID=$task->project"), $project->name);
$position[] = $this->lang->task->view;
$this->view->header = $header;
$this->view->position = $position;
$this->view->project = $project;
$this->view->task = $task;
$this->view->actions = $this->loadModel('action')->getList('task', $taskID);
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->header = $header;
$this->view->position = $position;
$this->view->project = $project;
$this->view->task = $task;
$this->view->actions = $this->loadModel('action')->getList('task', $taskID);
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('task', $taskID);
$this->display();
}
@@ -768,7 +754,7 @@ class task extends control
}
/* Get tasks. */
$tasks = $this->dao->select('*')->from(TABLE_TASK)->alias('t1')->where($this->session->taskReportCondition)->orderBy($orderBy)->fetchAll('id');
$tasks = $this->dao->select('*')->from(TABLE_TASK)->alias('t1')->where($this->session->taskQueryCondition)->orderBy($orderBy)->fetchAll('id');
/* Get users and projects. */
$users = $this->loadModel('user')->getPairs('noletter');

View File

@@ -537,8 +537,6 @@ class taskModel extends model
*/
public function getProjectTasks($projectID, $type = 'all', $orderBy = 'status_asc, id_desc', $pager = null)
{
$this->session->set('taskOrderBy', $orderBy);
$orderBy = str_replace('status', 'statusCustom', $orderBy);
$type = strtolower($type);
$tasks = $this->dao->select('t1.*, t2.id AS storyID, t2.title AS storyTitle, t2.version AS latestStoryVersion, t2.status AS storyStatus, t3.realname AS assignedToRealName')
@@ -556,9 +554,7 @@ class taskModel extends model
->page($pager)
->fetchAll();
$sql = explode('WHERE', $this->dao->get());
$sql = explode('ORDER', $sql[1]);
$this->session->set('taskReportCondition', $sql[0]);
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'task');
if($tasks) return $this->processTasks($tasks);
return array();
@@ -617,6 +613,9 @@ class taskModel extends model
->beginIF($limit > 0)->limit($limit)->fi()
->page($pager)
->fetchAll();
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'task');
if($tasks) return $this->processTasks($tasks);
return array();
}
@@ -656,7 +655,7 @@ class taskModel extends model
*/
public function getStoryTaskPairs($storyID, $projectID = 0)
{
return $this->dao->select('id, name')
return $this->dao->select('id, name')
->from(TABLE_TASK)
->where('story')->eq((int)$storyID)
->andWhere('deleted')->eq(0)
@@ -798,7 +797,7 @@ class taskModel extends model
{
$datas = $this->dao->select('project as name, count(*) as value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('project')
->orderBy('value DESC')
->fetchAll('name');
@@ -818,7 +817,7 @@ class taskModel extends model
{
$datas = $this->dao->select('assignedTo AS name, count(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('assignedTo')
->orderBy('value DESC')
->fetchAll('name');
@@ -838,7 +837,7 @@ class taskModel extends model
{
$datas = $this->dao->select('type AS name, count(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('type')
->orderBy('value DESC')
->fetchAll('name');
@@ -857,7 +856,7 @@ class taskModel extends model
{
return $this->dao->select('pri AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('pri')
->orderBy('value DESC')
->fetchAll('name');
@@ -873,7 +872,7 @@ class taskModel extends model
{
return $this->dao->select('deadline AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('deadline')
->orderBy('value DESC')
->fetchAll('name');
@@ -889,7 +888,7 @@ class taskModel extends model
{
return $this->dao->select('estimate AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('estimate')
->orderBy('value DESC')
->fetchAll('name');
@@ -905,7 +904,7 @@ class taskModel extends model
{
return $this->dao->select('`left` AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('`left`')
->orderBy('value DESC')
->fetchAll('name');
@@ -921,7 +920,7 @@ class taskModel extends model
{
return $this->dao->select('consumed AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('consumed')
->orderBy('value DESC')
->fetchAll('name');
@@ -937,7 +936,7 @@ class taskModel extends model
{
$datas = $this->dao->select('finishedBy AS name, COUNT(finishedBy) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->andWhere('finishedBy')->ne('')
->groupBy('finishedBy')
->orderBy('value DESC')
@@ -958,7 +957,7 @@ class taskModel extends model
{
$datas = $this->dao->select('closedReason AS name, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('closedReason')
->orderBy('value DESC')
->fetchAll('name');
@@ -983,7 +982,7 @@ class taskModel extends model
{
$datas= $this->dao->select('DATE_FORMAT(finishedDate, "%Y-%m-%d") AS date, COUNT(*) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('date')
->having('date != "0000-00-00"')
->orderBy('finishedDate')
@@ -1008,7 +1007,7 @@ class taskModel extends model
{
$datas = $this->dao->select('status AS name, COUNT(status) AS value')
->from(TABLE_TASK)->alias('t1')
->where($this->session->taskReportCondition)
->where($this->session->taskQueryCondition)
->groupBy('status')
->orderBy('value DESC')
->fetchAll('name');

View File

@@ -40,7 +40,7 @@
}
if($preAndNext->next)
{
echo "<abbr id='next' title={$preAndNext->next->id}{$lang->colon}{$preAndNext->pre->name}>" . html::a($this->inLink('view', "taskID={$preAndNext->next->id}"), '>') . "</abbr>";
echo "<abbr id='next' title={$preAndNext->next->id}{$lang->colon}{$preAndNext->next->name}>" . html::a($this->inLink('view', "taskID={$preAndNext->next->id}"), '>') . "</abbr>";
}
?>
</div>