* Code for review.

This commit is contained in:
liyuchun
2021-09-07 08:54:35 +08:00
parent af08c20f6c
commit eb9911eb1f
2 changed files with 107 additions and 114 deletions
+104 -110
View File
@@ -19,141 +19,135 @@ class productIssueEntry extends entry
$type = $idParams[0];
$id = intval($idParams[1]);
$issue = new stdclass();
$issue = new stdclass();
switch($type)
{
case 'story':
$this->app->loadLang('story');
$storyStatus = array('' => '', 'draft' => 'opened', 'active' => 'opened', 'changed' => 'opened', 'closed' => 'closed');
case 'story':
$this->app->loadLang('story');
$storyStatus = array('' => '', 'draft' => 'opened', 'active' => 'opened', 'changed' => 'opened', 'closed' => 'closed');
$story = $this->dao->select('*')->from(TABLE_STORY)->where('id')->eq($id)->fetch();
if(!$story) $this->send404();
$story = $this->dao->select('*')->from(TABLE_STORY)->where('id')->eq($id)->fetch();
if(!$story) $this->send404();
$issue->id = $issueID;
$issue->title = $story->title;
$issue->labels = array($this->app->lang->story->common, zget($this->app->lang->story->categoryList, $story->category));
$issue->pri = $story->pri;
$issue->openedDate = $story->openedDate;
$issue->openedBy = $story->openedBy;
$issue->lastEditedDate = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedDate : $story->lastEditedDate;
$issue->lastEditedBy = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedBy : $story->lastEditedBy;
$issue->status = $storyStatus[$story->status];
$issue->url = helper::createLink('story', 'view', "storyID=$id");
$issue->id = $issueID;
$issue->title = $story->title;
$issue->labels = array($this->app->lang->story->common, zget($this->app->lang->story->categoryList, $story->category));
$issue->pri = $story->pri;
$issue->openedDate = $story->openedDate;
$issue->openedBy = $story->openedBy;
$issue->lastEditedDate = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedDate : $story->lastEditedDate;
$issue->lastEditedBy = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedBy : $story->lastEditedBy;
$issue->status = $storyStatus[$story->status];
$issue->url = helper::createLink('story', 'view', "storyID=$id");
$storySpec = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('story')->eq($id)->andWhere('version')->eq($story->version)->fetch();
$issue->desc = $storySpec->spec;
$storySpec = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('story')->eq($id)->andWhere('version')->eq($story->version)->fetch();
$issue->desc = $storySpec->spec;
if($story->assignedTo == "")
{
$issue->assignedTo = array();
}
else
{
$issue->assignedTo = array($story->assignedTo);
}
break;
case 'bug':
$this->app->loadLang('bug');
$bugStatus = array('' => '', 'active' => 'opened', 'resolved' => 'opened', 'closed' => 'closed');
$bug = $this->dao->select('*')->from(TABLE_BUG)->where('id')->eq($id)->fetch();
if(!$bug) $this->send404();
$issue->id = $issueID;
$issue->title = $bug->title;
$issue->labels = array($this->app->lang->bug->common, zget($this->app->lang->bug->typeList, $bug->type));
$issue->pri = $bug->pri;
$issue->openedDate = $bug->openedDate;
$issue->openedBy = $bug->openedBy;
$issue->lastEditedDate = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedDate : $bug->lastEditedDate;
$issue->lastEditedBy = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedBy : $bug->lastEditedBy;
$issue->status = $bugStatus[$bug->status];
$issue->url = helper::createLink('bug', 'view', "bugID=$id");
$issue->desc = $bug->steps;
if($bug->assignedTo == "")
{
$issue->assignedTo = array();
}
else
{
$issue->assignedTo = array($bug->assignedTo);
}
break;
case 'task':
$this->app->loadLang('task');
$taskStatus = array('' => '', 'wait' => 'opened', 'doing' => 'opened', 'done' => 'opened', 'pause' => 'opened', 'cancel' => 'opened', 'closed' => 'closed');
$task = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($id)->fetch();
if(!$task) $this->send404();
$issue->id = $issueID;
$issue->title = $task->name;
$issue->labels = array($this->app->lang->task->common, zget($this->app->lang->task->typeList, $task->type));
$issue->pri = $task->pri;
$issue->openedDate = $task->openedDate;
$issue->openedBy = $task->openedBy;
$issue->lastEditedDate = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedDate : $task->lastEditedDate;
$issue->lastEditedBy = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedBy : $task->lastEditedBy;
$issue->status = $taskStatus[$task->status];
$issue->url = helper::createLink('task', 'view', "taskID=$id");
$issue->desc = $task->desc;
/* Get assignees for task, the task object has the type of multiple assign only so far. */
$users = $this->dao->select('account')->from(TABLE_TEAM)
->where('type')->eq('task')
->andWhere('root')->eq($task->id)
->fetchAll();
if($users)
{
foreach($users as $user)
{
$issue->assignedTo[] = $user->account;
}
}
else
{
if($task->assignedTo == "")
if($story->assignedTo == "")
{
$issue->assignedTo = array();
}
else
{
$issue->assignedTo = array($task->assignedTo);
$issue->assignedTo = array($story->assignedTo);
}
}
break;
break;
default:
$this->send404();
case 'bug':
$this->app->loadLang('bug');
$bugStatus = array('' => '', 'active' => 'opened', 'resolved' => 'opened', 'closed' => 'closed');
$bug = $this->dao->select('*')->from(TABLE_BUG)->where('id')->eq($id)->fetch();
if(!$bug) $this->send404();
$issue->id = $issueID;
$issue->title = $bug->title;
$issue->labels = array($this->app->lang->bug->common, zget($this->app->lang->bug->typeList, $bug->type));
$issue->pri = $bug->pri;
$issue->openedDate = $bug->openedDate;
$issue->openedBy = $bug->openedBy;
$issue->lastEditedDate = helper::isZeroDate($bug->lastEditedDate) ? $bug->openedDate : $bug->lastEditedDate;
$issue->lastEditedBy = helper::isZeroDate($bug->lastEditedDate) ? $bug->openedBy : $bug->lastEditedBy;
$issue->status = $bugStatus[$bug->status];
$issue->url = helper::createLink('bug', 'view', "bugID=$id");
$issue->desc = $bug->steps;
if($bug->assignedTo == "")
{
$issue->assignedTo = array();
}
else
{
$issue->assignedTo = array($bug->assignedTo);
}
break;
case 'task':
$this->app->loadLang('task');
$taskStatus = array('' => '', 'wait' => 'opened', 'doing' => 'opened', 'done' => 'opened', 'pause' => 'opened', 'cancel' => 'opened', 'closed' => 'closed');
$task = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($id)->fetch();
if(!$task) $this->send404();
$issue->id = $issueID;
$issue->title = $task->name;
$issue->labels = array($this->app->lang->task->common, zget($this->app->lang->task->typeList, $task->type));
$issue->pri = $task->pri;
$issue->openedDate = $task->openedDate;
$issue->openedBy = $task->openedBy;
$issue->lastEditedDate = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedDate : $task->lastEditedDate;
$issue->lastEditedBy = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedBy : $task->lastEditedBy;
$issue->status = $taskStatus[$task->status];
$issue->url = helper::createLink('task', 'view', "taskID=$id");
$issue->desc = $task->desc;
/* Get assignees for task, the task object has the type of multiple assign only so far. */
$users = $this->dao->select('account')->from(TABLE_TEAM)
->where('type')->eq('task')
->andWhere('root')->eq($task->id)
->fetchAll();
if($users)
{
foreach($users as $user)
{
$issue->assignedTo[] = $user->account;
}
}
else
{
if($task->assignedTo == "")
{
$issue->assignedTo = array();
}
else
{
$issue->assignedTo = array($task->assignedTo);
}
}
break;
default:
$this->send404();
}
$actions = $this->loadModel('action')->getList($type, $id);
$issue->comments = array_values($this->processActions($type, $actions));
/**
* Get all users in issues so that we can bulk get user detail later.
*
*/
/* Get all users in issues so that we can bulk get user detail later. */
$userList = array();
foreach($issue->assignedTo as $user)
{
$userList[] = $user;
}
$userList[] = $issue->openedBy;
$userList[] = $issue->openedBy;
$userList = array_unique($userList);
$userDetails = $this->loadModel('user')->getUserDetailsForAPI($userList);
/**
* Set the user detail to assignedTo and openedBy.
*
*/
/* Set the user detail to assignedTo and openedBy. */
foreach($issue->assignedTo as $index => $user)
{
$issue->assignedTo[$index] = $userDetails[$user];
@@ -166,7 +160,7 @@ class productIssueEntry extends entry
/**
* Process actions of one issue.
*
* @param string $type
* @param string $type bug|task|story
* @param array $actions
* @access public
* @return array
@@ -207,8 +201,8 @@ class productIssueEntry extends entry
}
/* Format user detail and date. */
$accountsList = array_unique($accountsList);
$userDetails = $this->loadModel('user')->getUserDetailsForAPI($accountsList);
$accountsList = array_unique($accountsList);
$userDetails = $this->loadModel('user')->getUserDetailsForAPI($accountsList);
foreach($actions as $action)
{
$action->actor = $userDetails[$action->actor];
+3 -4
View File
@@ -134,7 +134,6 @@ class productIssuesEntry extends entry
}
/* Get bugs. */
/* Get stories. */
if(empty($labelTypes) or in_array('bug', $labelTypes))
{
$query = $this->dao->select($bugFields)->from(TABLE_BUG)
@@ -205,7 +204,7 @@ class productIssuesEntry extends entry
$r->lastEditedBy = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedBy : $task->lastEditedBy;
$r->status = $issue['status'];
$r->url = helper::createLink('task', 'view', "taskID=$task->id");
$r->assignedTo = array();
$r->assignedTo = array();
/* Get assignees for task, the task object has the type of multiple assign only so far. */
$users = $this->dao->select('account')->from(TABLE_TEAM)
@@ -232,7 +231,7 @@ class productIssuesEntry extends entry
}
}
else if($issue['type'] == 'story')
elseif($issue['type'] == 'story')
{
$story = $stories[$issue['id']];
@@ -256,7 +255,7 @@ class productIssuesEntry extends entry
$r->assignedTo = array($story->assignedTo);
}
}
else if($issue['type'] == 'bug')
elseif($issue['type'] == 'bug')
{
$bug = $bugs[$issue['id']];