* Refactor the getStats method under the project.
This commit is contained in:
+2
-211
@@ -240,7 +240,7 @@ class projectModel extends model
|
||||
{
|
||||
$orderBy = $project->model == 'waterfall' ? 'id_asc' : 'id_desc';
|
||||
$pager = $project->model == 'waterfall' ? null : new pager(0, 1, 1);
|
||||
$project->executions = $this->getStats($projectID, 'undone', 0, 0, 30, $orderBy, $pager);
|
||||
$project->executions = $this->loadModel('execution')->getStatData($projectID, 'undone', 0, 0, false, '', $orderBy, $pager);
|
||||
$project->teamCount = isset($teams[$projectID]) ? $teams[$projectID]->count : 0;
|
||||
$project->estimate = isset($estimates[$projectID]) ? round($estimates[$projectID]->estimate, 2) : 0;
|
||||
$project->parentName = $this->getParentProgram($project);
|
||||
@@ -2263,215 +2263,6 @@ class projectModel extends model
|
||||
->fetchAll('account');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get project stats.
|
||||
*
|
||||
* @param int $projectID
|
||||
* @param string $status
|
||||
* @param int $productID
|
||||
* @param int $branch
|
||||
* @param int $itemCounts
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @param bool $withTasks
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getStats($projectID = 0, $status = 'undone', $productID = 0, $branch = 0, $itemCounts = 30, $orderBy = 'id_asc', $pager = null, $withTasks = false, $queryID = 0)
|
||||
{
|
||||
if(empty($productID))
|
||||
{
|
||||
$myExecutionIDList = array();
|
||||
$query = '';
|
||||
if($status == 'bySearch')
|
||||
{
|
||||
$status = 'all';
|
||||
if($queryID)
|
||||
{
|
||||
$query = $this->loadModel('search')->getQuery($queryID);
|
||||
if($query)
|
||||
{
|
||||
$this->session->set('executionQuery', $query->sql);
|
||||
$this->session->set('executionForm', $query->form);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session->set('executionQuery', ' 1 = 1');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->session->executionQuery == false) $this->session->set('executionQuery', ' 1 = 1');
|
||||
}
|
||||
$query = $this->session->executionQuery;
|
||||
$allProject = "`project` = 'all'";
|
||||
|
||||
if(strpos($query, $allProject) !== false) $query = str_replace($allProject, '1', $query);
|
||||
$query = preg_replace('/(`\w*`)/', 't1.$1',$query);
|
||||
}
|
||||
|
||||
if($status == 'involved')
|
||||
{
|
||||
$myExecutionIDList = $this->dao->select('root')->from(TABLE_TEAM)
|
||||
->where('account')->eq($this->app->user->account)
|
||||
->andWhere('type')->eq('execution')
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
$executions = $this->dao->select('t1.*,t2.name projectName, t2.model as projectModel')->from(TABLE_EXECUTION)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
|
||||
->where('t1.type')->in('sprint,stage,kanban')
|
||||
->beginIF(!empty($query))->andWhere($query)->fi()
|
||||
->beginIF($projectID != 0)->andWhere('t1.project')->eq($projectID)->fi()
|
||||
->beginIF($projectID == 0 and $this->config->vision)->andWhere('t1.vision')->eq($this->config->vision)->fi()
|
||||
->beginIF(!empty($myExecutionIDList))->andWhere('t1.id')->in(array_keys($myExecutionIDList))->fi()
|
||||
->beginIF($status == 'undone')->andWhere('t1.status')->notIN('done,closed')->fi()
|
||||
->beginIF(!in_array($status, array('all', 'undone', 'involved', 'review'), true))->andWhere('t1.status')->eq($status)->fi()
|
||||
->beginIF($status == 'review')
|
||||
->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)")
|
||||
->andWhere('t1.reviewStatus')->eq('doing')
|
||||
->fi()
|
||||
->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->sprints)->fi()
|
||||
->andWhere('t1.vision')->eq($this->config->vision)
|
||||
->andWhere('t1.deleted')->eq('0')
|
||||
->orderBy($orderBy)
|
||||
->page($pager)
|
||||
->fetchAll('id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$executions = $this->dao->select('t2.*,t3.name projectName, t3.model as projectModel')->from(TABLE_PROJECTPRODUCT)->alias('t1')
|
||||
->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.project=t2.id')
|
||||
->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id')
|
||||
->where('t1.product')->eq($productID)
|
||||
->beginIF($projectID)->andWhere('t2.project')->eq($projectID)->fi()
|
||||
->beginIF($status == 'undone')->andWhere('t2.status')->notIN('done,closed')->fi()
|
||||
->beginIF($status != 'all' and $status != 'undone')->andWhere('t2.status')->eq($status)->fi()
|
||||
->beginIF(!$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->sprints)->fi()
|
||||
->andWhere('t2.deleted')->eq('0')
|
||||
->andWhere('t2.vision')->eq($this->config->vision)
|
||||
->orderBy($orderBy)
|
||||
->page($pager)
|
||||
->fetchAll('id');
|
||||
}
|
||||
|
||||
$hours = $this->computerProgress($executions);
|
||||
$emptyHour = array('totalEstimate' => 0, 'totalConsumed' => 0, 'totalLeft' => 0, 'progress' => 0);
|
||||
|
||||
/* Get burndown charts datas. */
|
||||
$burns = $this->dao->select('execution, date AS name, `left` AS value')
|
||||
->from(TABLE_BURN)
|
||||
->where('execution')->in(array_keys($executions))
|
||||
->andWhere('task')->eq(0)
|
||||
->orderBy('date desc')
|
||||
->fetchGroup('execution', 'name');
|
||||
|
||||
$this->loadModel('execution');
|
||||
foreach($burns as $executionID => $executionBurns)
|
||||
{
|
||||
/* If executionBurns > $itemCounts, split it, else call processBurnData() to pad burns. */
|
||||
$begin = $executions[$executionID]->begin;
|
||||
$end = $executions[$executionID]->end;
|
||||
if(helper::isZeroDate($begin)) $begin = $executions[$executionID]->openedDate;
|
||||
$executionBurns = $this->execution->processBurnData($executionBurns, $itemCounts, $begin, $end);
|
||||
|
||||
/* Shorter names. */
|
||||
foreach($executionBurns as $executionBurn)
|
||||
{
|
||||
$executionBurn->name = substr($executionBurn->name, 5);
|
||||
unset($executionBurn->execution);
|
||||
}
|
||||
|
||||
ksort($executionBurns);
|
||||
$burns[$executionID] = $executionBurns;
|
||||
}
|
||||
|
||||
if($withTasks)
|
||||
{
|
||||
$executionTasks = $this->dao->select('*')->from(TABLE_TASK)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('status')->notin('closed,cancel')
|
||||
->andWhere('execution')->in(array_keys($executions))
|
||||
->orderBy('id_asc')
|
||||
->fetchGroup('execution', 'id');
|
||||
|
||||
foreach($executionTasks as $executionID => $tasks)
|
||||
{
|
||||
foreach($tasks as $task)
|
||||
{
|
||||
if($task->parent > 0)
|
||||
{
|
||||
if(isset($executionTasks[$executionID][$task->parent]))
|
||||
{
|
||||
$executionTasks[$executionID][$task->parent]->children[$task->id] = $task;
|
||||
unset($executionTasks[$executionID][$task->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Process executions. */
|
||||
$parents = array();
|
||||
$children = array();
|
||||
foreach($executions as $key => $execution)
|
||||
{
|
||||
/* Process the end time. */
|
||||
$execution->end = date(DT_DATE1, strtotime($execution->end));
|
||||
|
||||
/* Judge whether the execution is delayed. */
|
||||
if($execution->status != 'done' and $execution->status != 'closed' and $execution->status != 'suspended')
|
||||
{
|
||||
$delay = helper::diffDate(helper::today(), $execution->end);
|
||||
if($delay > 0) $execution->delay = $delay;
|
||||
}
|
||||
|
||||
/* Process the burns. */
|
||||
$execution->burns = array();
|
||||
$burnData = isset($burns[$execution->id]) ? $burns[$execution->id] : array();
|
||||
foreach($burnData as $data) $execution->burns[] = $data->value;
|
||||
|
||||
/* Process the hours. */
|
||||
$execution->hours = isset($hours[$execution->id]) ? $hours[$execution->id] : (object)$emptyHour;
|
||||
|
||||
$execution->children = array();
|
||||
$execution->grade == 1 ? $parents[$execution->id] = $execution : $children[$execution->parent][] = $execution;
|
||||
if(isset($executionTasks) and isset($executionTasks[$execution->id]))
|
||||
{
|
||||
$tasks = array_chunk($executionTasks[$execution->id], 50, true);
|
||||
$execution->tasks = $tasks[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* In the case of the waterfall model, calculate the sub-stage. */
|
||||
if($projectID == 0)
|
||||
{
|
||||
foreach($executions as $key => $execution)
|
||||
{
|
||||
if($execution->type == 'stage')
|
||||
{
|
||||
$execution->children = isset($children[$execution->id]) ? $children[$execution->id] : array();
|
||||
unset($children[$execution->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$project = $this->getByID($projectID);
|
||||
if($project and $project->model == 'waterfall')
|
||||
{
|
||||
foreach($parents as $id => $execution)
|
||||
{
|
||||
$execution->children = isset($children[$id]) ? $children[$id] : array();
|
||||
unset($children[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
$orphan = array();
|
||||
foreach($children as $child) $orphan = array_merge($child, $orphan);
|
||||
|
||||
return array_merge($parents, $orphan);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats for project kanban.
|
||||
*
|
||||
@@ -2483,7 +2274,7 @@ class projectModel extends model
|
||||
$this->loadModel('program');
|
||||
|
||||
$projects = $this->program->getProjectStats(0, 'all', 0, 'order_asc');
|
||||
$executions = $this->getStats(0, 'doing');
|
||||
$executions = $this->loadModel('execution')->getStatData(0, 'doing');
|
||||
|
||||
$doingExecutions = array();
|
||||
$latestExecutions = array();
|
||||
|
||||
Reference in New Issue
Block a user