* adjust code for task #536.

This commit is contained in:
shiyangyangwork@yahoo.cn
2011-10-29 03:35:05 +00:00
parent 7b7c7497f0
commit 7781f1cbca
13 changed files with 323 additions and 325 deletions
+252
View File
@@ -295,6 +295,206 @@ class project extends control
$this->display();
}
/**
* Import from Bug.
*
* @param int $projectID
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function importBug($projectID = 0, $pager = '', $recTotal = 0, $recPerPage = 30, $pageID = 1)
{
if(!empty($_POST))
{
$mails = $this->project->importBug($projectID);
if(dao::isError()) die(js::error(dao::getError()));
foreach($mails as $mail)
{
$this->sendmail($mail->taskID, $mail->actionID);
}
/* Locate the browser. */
die(js::locate($this->createLink('project', 'task', "projectID=$projectID"), 'parent'));
}
$this->loadModel('bug');
$projects = $this->project->getPairs();
$users = $this->project->getTeamMemberPairs($projectID, 'nodeleted');
/* Load pager and get tasks. */
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->project->setMenu($projects, $projectID);
$header['title'] = $projects[$projectID] . $this->lang->colon . $this->lang->project->importBug;
$position[] = html::a($this->createLink('project', 'task', "projectID=$projectID"), $projects[$projectID]);
$position[] = $this->lang->project->importBug;
$bugs = $this->bug->getActiveBugs($pager);
$this->view->header = $header;
$this->view->pager = $pager;
$this->view->bugs = $bugs;
$this->view->users = $users;
$this->view->projectID = $projectID;
$this->display();
}
/* task#536.
public function importFromBug($projectID = 0, $browseType = 'noclosed', $param = 0, $orderBy = '', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->products = $this->loadModel('product')->getPairs();
if(empty($this->products))
{
//echo js::alert($this->lang->product->errorNoProduct);
//die(js::locate($this->createLink('product', 'create')));
}
$this->view->products = $this->products;
$projects = $this->project->getPairs('all');
/* Set browseType and queryID. /
$browseType = strtolower($browseType);
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
/* Set menu and save session. /
$this->project->setMenu($this->project->getPairs(), $projectID);
$this->session->set('bugList', $this->app->getURI(true));
/* Process the order by field. /
if(!$orderBy) $orderBy = $this->cookie->qaBugOrder ? $this->cookie->qaBugOrder : 'id_desc';
setcookie('qaBugOrder', $orderBy, $this->config->cookieLife, $this->config->webRoot);
/* Load pager. /
$this->app->loadClass('pager', $static = true);
$pager = pager::init($recTotal, $recPerPage, $pageID);
$bugs = array();
if($browseType == 'all')
{
$bugs = $this->dao->select('*')->from(TABLE_BUG)->where('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'assigntome')
{
$bugs = $this->dao->findByAssignedTo($this->app->user->account)->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'openedbyme')
{
$bugs = $this->dao->findByOpenedBy($this->app->user->account)->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'resolvedbyme')
{
$bugs = $this->dao->findByResolvedBy($this->app->user->account)->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'assigntonull')
{
$bugs = $this->dao->findByAssignedTo('')->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'unresolved')
{
$bugs = $this->dao->findByStatus('active')->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'longlifebugs')
{
$bugs = $this->dao->findByLastEditedDate("<", date(DT_DATE1, strtotime('-7 days')))->from(TABLE_BUG)->andWhere('product')->eq($productID)
->andWhere('openedDate')->lt(date(DT_DATE1,strtotime('-7 days')))
->andWhere('deleted')->eq(0)
->andWhere('status')->ne('closed')->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'postponedbugs')
{
$bugs = $this->dao->findByResolution('postponed')->from(TABLE_BUG)->andWhere('product')->eq($productID)
->orderBy($orderBy)->page($pager)->fetchAll();
}
elseif($browseType == 'needconfirm')
{
$bugs = $this->dao->select('t1.*, t2.title AS storyTitle')->from(TABLE_BUG)->alias('t1')->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')
->where("t2.status = 'active'")
->andWhere('t1.deleted')->eq(0)
->andWhere('t2.version > t1.storyVersion')
->orderBy($orderBy)
->fetchAll();
}
elseif($browseType == 'bysearch')
{
if($queryID)
{
$query = $this->loadModel('search')->getQuery($queryID);
if($query)
{
$this->session->set('bugQuery', $query->sql);
$this->session->set('bugForm', $query->form);
}
else
{
$this->session->set('bugQuery', ' 1 = 1');
}
}
else
{
if($this->session->bugQuery == false) $this->session->set('bugQuery', ' 1 = 1');
}
$bugQuery = str_replace("`product` = 'all'", '1', $this->session->bugQuery); // Search all product.
$bugs = $this->dao->select('*')->from(TABLE_BUG)->where($bugQuery)
->andWhere('deleted')->eq(0)
->orderBy($orderBy)->page($pager)->fetchAll();
}
/ Process the sql, get the conditon partion, save it to session. Thus the report page can use the same condition. /
if($browseType != 'needconfirm')
{
$sql = explode('WHERE', $this->dao->get());
$sql = explode('ORDER', $sql[1]);
$this->session->set('bugReportCondition', $sql[0]);
}
/ Build the search form. /
$this->config->bug->search['actionURL'] = $this->createLink('bug', 'browse', "productID=$productID&browseType=bySearch&queryID=myQueryID");
$this->config->bug->search['queryID'] = $queryID;
$this->config->bug->search['params']['product']['values'] = array($productID => $this->products[$productID], 'all' => $this->lang->bug->allProduct);
$this->config->bug->search['params']['module']['values'] = $this->tree->getOptionMenu($productID, $viewType = 'bug', $startModuleID = 0);
$this->config->bug->search['params']['project']['values'] = $this->product->getProjectPairs($productID);
$this->config->bug->search['params']['openedBuild']['values'] = $this->loadModel('build')->getProductBuildPairs($productID);
$this->config->bug->search['params']['resolvedBuild']['values'] = $this->build->getProductBuildPairs($productID);
$this->view->searchForm = $this->fetch('search', 'buildForm', $this->config->bug->search);
$users = $this->loadModel('user')->getPairs('noletter');
$header['title'] = $projects[$projectID] . $this->lang->colon . $this->lang->task->common;
$position[] = html::a($this->createLink('project', 'task', "projectID=$projectID"), $projects[$projectID]);
$position[] = $this->lang->task->common;
$this->view->header = $header;
$this->view->position = $position;
$this->view->projectID = $projectID;
$this->view->projectName = $projects[$projectID];
$this->view->browseType = $browseType;
$this->view->bugs = $bugs;
$this->view->users = $users;
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->display();
}
*/
/**
* Browse stories of a project.
*
@@ -664,6 +864,58 @@ class project extends control
}
}
/**
* Send email.
*
* @param int $taskID
* @param int $actionID
* @access private
* @return void
*/
private function sendmail($taskID, $actionID)
{
/* Set toList and ccList. */
$task = $this->loadModel('task')->getById($taskID);
$projectName = $this->project->getById($task->project)->name;
$toList = $task->assignedTo;
$ccList = trim($task->mailto, ',');
if($toList == '')
{
if($ccList == '') return;
if(strpos($ccList, ',') === false)
{
$toList = $ccList;
$ccList = '';
}
else
{
$commaPos = strpos($ccList, ',');
$toList = substr($ccList, 0, $commaPos);
$ccList = substr($ccList, $commaPos + 1);
}
}
elseif(strtolower($toList) == 'closed')
{
$toList = $task->finishedBy;
}
/* Get action info. */
$action = $this->loadModel('action')->getById($actionID);
$history = $this->action->getHistory($actionID);
$action->history = isset($history[$actionID]) ? $history[$actionID] : array();
/* Create the email content. */
$this->view->task = $task;
$this->view->action = $action;
$this->clear();
$mailContent = $this->parse($this->moduleName, 'sendmail');
/* Send emails. */
$this->loadModel('mail')->send($toList, $projectName . ':' . 'TASK#' . $task->id . $this->lang->colon . $task->name, $mailContent, $ccList);
if($this->mail->isError()) echo js::error($this->mail->getError());
}
/**
* Manage products.
*