* Fix dynamic logic.

This commit is contained in:
zhujinyong
2021-03-24 14:51:28 +08:00
parent 534f2a947b
commit 4c237e2601
16 changed files with 83 additions and 55 deletions
+56 -34
View File
@@ -58,10 +58,11 @@ class actionModel extends model
if($autoDelete) $this->file->autoDelete($this->post->uid);
}
/* Get product and project for this object. */
$productAndProject = $this->getProductAndProject($action->objectType, $objectID);
$action->product = $productAndProject['product'];
$action->execution = $actionType == 'unlinkedfromproject' ? (int)$extra : (int)$productAndProject['project'];
/* Get product project and execution for this object. */
$relation = $this->getRelatedFields($action->objectType, $objectID);
$action->product = $relation['product'];
$action->project = $relation['project'];
$action->execution = $actionType == 'unlinkedfromproject' ? (int)$extra : (int)$relation['execution'];
$this->dao->insert(TABLE_ACTION)->data($action)->autoCheck()->exec();
$actionID = $this->dbh->lastInsertID();
@@ -136,25 +137,42 @@ class actionModel extends model
}
/**
* Get product and project of an object.
* Get product, project, execution of the object.
*
* @param string $objectType
* @param int $objectID
* @access public
* @return array
*/
public function getProductAndProject($objectType, $objectID)
public function getRelatedFields($objectType, $objectID)
{
$emptyRecord = array('product' => ',0,', 'project' => 0);
$emptyRecord = array('product' => ',0,', 'project' => 0, 'execution' => 0);
/* If objectType is product or project, return the objectID. */
if($objectType == 'product') return array('product' => ",$objectID,", 'project' => 0);
if($objectType == 'program') return array('product' => "", 'project' => $objectID);
if($objectType == 'project')
/* If objectType is program, return empty record. */
if($objectType == 'program') return $emptyRecord;
/* If objectType is product or execution, return the objectID. */
if($objectType == 'product') return array('product' => ",$objectID,", 'project' => 0, 'execution' => 0);
/* If objectType is project or execution, return objectID products and project. */
if($objectType == 'project' or $objectType == 'execution')
{
$products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($objectID)->fetchPairs('product');
$productList = ',' . join(',', array_keys($products)) . ',';
return array('project' => $objectID, 'product' => $productList);
$relation = array($objectType => $objectID, 'product' => $productList);
if($objectType == 'execution')
{
$project = $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($objectID)->fetch('project');
$relation['project'] = $project;
}
else
{
$relation['execution'] = 0;
}
return $relation;
}
/* Only process these object types. */
@@ -164,9 +182,9 @@ class actionModel extends model
/* Set fields to fetch. */
if(strpos('story, productplan, case', $objectType) !== false) $fields = 'product';
if(strpos('build, bug, testtask, doc', $objectType) !== false) $fields = 'product, project';
if(strpos('build, bug, testtask, doc', $objectType) !== false) $fields = 'product, project, execution';
if($objectType == 'release') $fields = 'product, build';
if($objectType == 'task') $fields = 'project, story';
if($objectType == 'task') $fields = 'project, execution, story';
$record = $this->dao->select($fields)->from($this->config->objectTables[$objectType])->where('id')->eq($objectID)->fetch();
@@ -182,7 +200,7 @@ class actionModel extends model
}
else
{
$products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($record->project)->fetchPairs('product');
$products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($record->execution)->fetchPairs('product');
$record->product = join(',', array_keys($products));
}
}
@@ -192,6 +210,7 @@ class actionModel extends model
$record = (array)$record;
$record['product'] = isset($record['product']) ? ',' . $record['product'] . ',' : ',0,';
if(!isset($record['project'])) $record['project'] = 0;
if(!isset($record['execution'])) $record['execution'] = 0;
return $record;
}
@@ -640,13 +659,14 @@ class actionModel extends model
* @param string $orderBy
* @param object $pager
* @param string|int $productID all|int(like 123)|notzero all => include zero, notzero, greater than 0
* @param string|int $projectID same as productID
* @param string|int $projectID same as productID
* @param string|int $executionID same as productID
* @param string $date
* @param string $direction
* @access public
* @return array
*/
public function getDynamic($account = 'all', $period = 'all', $orderBy = 'date_desc', $pager = null, $productID = 'all', $projectID = 'all', $date = '', $direction = 'next')
public function getDynamic($account = 'all', $period = 'all', $orderBy = 'date_desc', $pager = null, $productID = 'all', $projectID = 'all', $executionID = 'all', $date = '', $direction = 'next')
{
/* Computer the begin and end date of a period. */
$beginAndEnd = $this->computeBeginAndEnd($period);
@@ -654,29 +674,29 @@ class actionModel extends model
/* Build has priv condition. */
$condition = 1;
if($productID == 'all') $products = $this->app->user->view->products;
if($projectID == 'all') $projects = $this->app->user->view->projects;
if($productID == 'all') $products = $this->app->user->view->products;
if($projectID == 'all') $projects = $this->app->user->view->projects;
if($executionID == 'all') $executions = $this->app->user->view->sprints;
if($productID == 'all' or $projectID == 'all')
{
$projectCondition = $projectID == 'all' ? "execution " . helper::dbIN($projects) : '';
$productCondition = $productID == 'all' ? "INSTR('," . $products . ",', product) > 0" : '';
if(is_numeric($productID)) $productCondition = "product like'%,$productID,%' or product='$productID'";
if(is_numeric($projectID)) $projectCondition = "execution='$projectID'";
$productCondition = $productID == 'all' ? "INSTR('," . $products . ",', product) > 0" : '';
$projectCondition = $projectID == 'all' ? "project " . helper::dbIN($projects) : '';
$executionCondition = $executionID == 'all' ? "execution " . helper::dbIN($executions) : '';
if(is_numeric($productID)) $productCondition = "product like '%,$productID,%' or product = '$productID'";
if(is_numeric($projectID)) $projectCondition = "project = '$projectID'";
if(is_numeric($executionID)) $executionCondition = "execution = '$executionID'";
$condition = "(product =',0,' AND execution = '0')";
if($projectCondition) $condition .= ' OR ' . $projectCondition;
if($productCondition) $condition .= ' OR ' . $productCondition;
$condition = "(product =',0,' AND project = '0' AND execution = 0)";
if($productCondition) $condition .= ' OR ' . $productCondition;
if($projectCondition) $condition .= ' OR ' . $projectCondition;
if($executionCondition) $condition .= ' OR ' . $executionCondition;
if($this->app->user->admin) $condition = 1;
}
/* If is project, select its related. */
$executions = array();
if(is_numeric($projectID))
{
$project = $this->loadModel('project')->getByID($projectID);
if(isset($project->type) and $project->type == 'project') $executions = $this->loadModel('execution')->getPairs($projectID);
}
if(is_numeric($projectID)) $executions = $this->loadModel('execution')->getPairs($projectID);
$this->loadModel('doc');
$libs = $this->doc->getLibs('all');
@@ -695,12 +715,14 @@ class actionModel extends model
->andWhere()
->markLeft(1)
->where(1)
->beginIF(is_numeric($projectID))->orWhere('execution')->eq($projectID)->fi()
->beginIF(is_numeric($projectID))->andWhere('project')->eq($projectID)->fi()
->beginIF(!empty($executions))->orWhere('execution')->in(array_keys($executions))->fi()
->beginIF(is_numeric($executionID))->andWhere('execution')->eq($executionID)->fi()
->markRight(1)
->beginIF($productID == 'notzero')->andWhere('product')->gt(0)->andWhere('product')->notlike('%,0,%')->fi()
->beginIF($projectID == 'notzero')->andWhere('execution')->gt(0)->fi()
->beginIF($projectID == 'all' or $productID == 'all')->andWhere("IF((objectType!= 'doc' && objectType!= 'doclib'), ($condition), '1=1')")->fi()
->beginIF($projectID == 'notzero')->andWhere('project')->gt(0)->fi()
->beginIF($executionID == 'notzero')->andWhere('execution')->gt(0)->fi()
->beginIF($productID == 'all' or $projectID == 'all' or $executionID == 'all')->andWhere("IF((objectType!= 'doc' && objectType!= 'doclib'), ($condition), '1=1')")->fi()
->beginIF($docs and !$this->app->user->admin)->andWhere("IF(objectType != 'doc', '1=1', objectID " . helper::dbIN($docs) . ")")->fi()
->beginIF($libs and !$this->app->user->admin)->andWhere("IF(objectType != 'doclib', '1=1', objectID " . helper::dbIN(array_keys($libs)) . ') ')->fi()
->beginIF($actionCondition)->andWhere("($actionCondition)")->fi()
+2 -1
View File
@@ -203,6 +203,7 @@ class company extends control
if($user) $account = $user->account;
}
$product = $browseType == 'product' ? $param : 'all';
$project = $browseType == 'project' ? $param : 'all';
$execution = $browseType == 'execution' ? $param : 'all';
$period = ($browseType == 'account' or $browseType == 'product' or $browseType == 'execution') ? 'all' : $browseType;
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
@@ -233,7 +234,7 @@ class company extends control
/* Get actions. */
if($browseType != 'bysearch')
{
$actions = $this->action->getDynamic($account, $period, $sort, $pager, $product, $execution, $date, $direction);
$actions = $this->action->getDynamic($account, $period, $sort, $pager, $product, $project, $execution, $date, $direction);
}
else
{
+2 -2
View File
@@ -1737,7 +1737,7 @@ class execution extends control
$this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), '', $linkedBranches);
$this->view->planGroups = $this->execution->getPlans($products);
$this->view->actions = $this->loadModel('action')->getList('execution', $executionID);
$this->view->dynamics = $this->loadModel('action')->getDynamic('all', 'all', 'date_desc', $pager, 'all', $executionID);
$this->view->dynamics = $this->loadModel('action')->getDynamic('all', 'all', 'date_desc', $pager, 'all', 'all', $executionID);
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->teamMembers = $this->execution->getTeamMembers($executionID);
$this->view->docLibs = $this->loadModel('doc')->getLibsByObject('execution', $executionID);
@@ -2455,7 +2455,7 @@ class execution extends control
}
$period = $type == 'account' ? 'all' : $type;
$date = empty($date) ? '' : date('Y-m-d', $date);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', $executionID, $date, $direction);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', 'all', $executionID, $date, $direction);
/* The header and position. */
$execution = $this->execution->getByID($executionID);
+1 -1
View File
@@ -932,7 +932,7 @@ class my extends control
$this->view->position[] = $this->lang->my->dynamic;
$date = empty($date) ? '' : date('Y-m-d', $date);
$actions = $this->loadModel('action')->getDynamic($this->app->user->account, $type, $sort, $pager, 'all', 'all', $date, $direction);
$actions = $this->loadModel('action')->getDynamic($this->app->user->account, $type, $sort, $pager, 'all', 'all', 'all', $date, $direction);
/* Assign. */
$this->view->type = $type;
+1 -1
View File
@@ -739,7 +739,7 @@ class product extends control
}
$period = $type == 'account' ? 'all' : $type;
$date = empty($date) ? '' : date('Y-m-d', $date);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, $productID, 'all', $date, $direction);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, $productID, 'all', 'all', $date, $direction);
/* The header and position. */
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->product->dynamic;
+1 -1
View File
@@ -257,7 +257,7 @@ class program extends control
if(!empty($_POST))
{
$changes = $this->project->start($programID);
$changes = $this->project->start($programID, 'program');
if(dao::isError()) die(js::error(dao::getError()));
if($this->post->comment != '' or !empty($changes))
+1
View File
@@ -51,6 +51,7 @@ $lang->program->endGreaterParent = "Parent end date: %s, end date should
$lang->program->beginGreateChild = "Child earliest begin: %s, parent begin date < = child earliest begin date.";
$lang->program->endLetterChild = "Child latest end: %s, parent end date > = child latest end date.";
$lang->program->closeErrorMessage = 'There are subprograms or projects that are not closed';
$lang->program->confirmDelete = "Do you want to delete it?";
$lang->program->stakeholderTypeList['inside'] = 'Inside';
$lang->program->stakeholderTypeList['outside'] = 'Outside';
+1
View File
@@ -51,6 +51,7 @@ $lang->program->endGreaterParent = "Parent end date: %s, end date should
$lang->program->beginGreateChild = "Child earliest begin: %s, parent begin date < = child earliest begin date.";
$lang->program->endLetterChild = "Child latest end: %s, parent end date > = child latest end date.";
$lang->program->closeErrorMessage = 'There are subprograms or projects that are not closed';
$lang->program->confirmDelete = "Do you want to delete it?";
$lang->program->stakeholderTypeList['inside'] = 'Inside';
$lang->program->stakeholderTypeList['outside'] = 'Outside';
+1
View File
@@ -51,6 +51,7 @@ $lang->program->endGreaterParent = "Parent end date: %s, end date should
$lang->program->beginGreateChild = "Child earliest begin: %s, parent begin date < = child earliest begin date.";
$lang->program->endLetterChild = "Child latest end: %s, parent end date > = child latest end date.";
$lang->program->closeErrorMessage = 'There are subprograms or projects that are not closed';
$lang->program->confirmDelete = "Do you want to delete it?";
$lang->program->stakeholderTypeList['inside'] = 'Inside';
$lang->program->stakeholderTypeList['outside'] = 'Outside';
+3 -3
View File
@@ -18,7 +18,7 @@
<span class='prefix label-id'><strong><?php echo $program->id;?></strong></span>
<?php echo isonlybody() ? ("<span title='$program->name'>" . $program->name . '</span>') : html::a($this->createLink('project', 'view', 'project=' . $program->id), $program->name, '_blank');?>
<?php if(!isonlybody()):?>
<small><?php echo $lang->arrow . $lang->project->start;?></small>
<small><?php echo $lang->arrow . $lang->program->start;?></small>
<?php endif;?>
</h2>
</div>
@@ -26,7 +26,7 @@
<table class='table table-form'>
<tbody>
<tr>
<th class='w-100px'><?php echo $lang->program->realBegan;?></th>
<th class='w-100px'><?php echo $lang->project->realBegan;?></th>
<td><?php echo html::input('realBegan', helper::today(), "class='form-control form-date'");?></td>
<td></td>
</tr>
@@ -36,7 +36,7 @@
</tr>
<tr>
<td colspan='3' class='text-center form-actions'>
<?php echo html::submitButton($lang->project->start);?>
<?php echo html::submitButton($lang->program->start);?>
</td>
</tr>
</tbody>
+3 -3
View File
@@ -36,7 +36,7 @@ $config->project->datatable->fieldList['id']['required'] = 'yes';
$config->project->datatable->fieldList['name']['title'] = 'name';
$config->project->datatable->fieldList['name']['fixed'] = 'left';
$config->project->datatable->fieldList['name']['width'] = 'auto';
$config->project->datatable->fieldList['name']['width'] = '180';
$config->project->datatable->fieldList['name']['required'] = 'yes';
$config->project->datatable->fieldList['name']['sort'] = 'no';
@@ -75,13 +75,13 @@ $config->project->datatable->fieldList['teamCount']['sort'] = 'no';
$config->project->datatable->fieldList['estimate']['title'] = 'estimate';
$config->project->datatable->fieldList['estimate']['fixed'] = 'no';
$config->project->datatable->fieldList['estimate']['width'] = '60';
$config->project->datatable->fieldList['estimate']['width'] = '50';
$config->project->datatable->fieldList['estimate']['required'] = 'no';
$config->project->datatable->fieldList['estimate']['sort'] = 'no';
$config->project->datatable->fieldList['consume']['title'] = 'consume';
$config->project->datatable->fieldList['consume']['fixed'] = 'no';
$config->project->datatable->fieldList['consume']['width'] = '60';
$config->project->datatable->fieldList['consume']['width'] = '50';
$config->project->datatable->fieldList['consume']['required'] = 'no';
$config->project->datatable->fieldList['consume']['sort'] = 'no';
+1 -1
View File
@@ -618,7 +618,7 @@ class project extends control
}
$period = $type == 'account' ? 'all' : $type;
$date = empty($date) ? '' : date('Y-m-d', $date);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', $projectID, $date, $direction);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', $projectID, 'all', $date, $direction);
/* The header and position. */
$project = $this->project->getByID($projectID);
+3 -2
View File
@@ -1018,12 +1018,13 @@ class projectModel extends model
* Start project.
*
* @param int $projectID
* @param string $type
* @access public
* @return array
*/
public function start($projectID)
public function start($projectID, $type = 'project')
{
$oldProject = $this->getById($projectID);
$oldProject = $this->getById($projectID, $type);
$now = helper::now();
$project = fixer::input('post')
+5 -4
View File
@@ -431,6 +431,7 @@ class repo extends control
* show repo log.
*
* @param int $repoID
* @param int $objectID
* @param string $entry
* @param string $revision
* @param string $type
@@ -440,7 +441,7 @@ class repo extends control
* @access public
* @return void
*/
public function log($repoID = 0, $entry = '', $revision = 'HEAD', $type = 'dir', $recTotal = 0, $recPerPage = 50, $pageID = 1)
public function log($repoID = 0, $objectID = 0, $entry = '', $revision = 'HEAD', $type = 'dir', $recTotal = 0, $recPerPage = 50, $pageID = 1)
{
if($this->get->repoPath) $entry = $this->get->repoPath;
$this->repo->setBackSession('log', $withOtherModule = true);
@@ -461,7 +462,7 @@ class repo extends control
$this->locate($this->repo->createLink('diff', "repoID=$repoID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision"));
}
$this->commonAction($repoID);
$this->commonAction($repoID, $objectID);
$this->scm->setEngine($repo);
$info = $this->scm->info($entry, $revision);
@@ -474,6 +475,7 @@ class repo extends control
$this->view->logs = $logs;
$this->view->revision = $revision;
$this->view->repoID = $repoID;
$this->view->objectID = $objectID;
$this->view->entry = urldecode($entry);
$this->view->path = urldecode($entry);
$this->view->file = urldecode($file);
@@ -503,7 +505,7 @@ class repo extends control
/* Save session. */
$this->session->set('revisionList', $this->app->getURI(true), 'repo');
$this->commonAction($repoID);
$this->commonAction($repoID, $objectID);
$this->scm->setEngine($repo);
$log = $this->scm->log('', $revision, $revision);
@@ -672,7 +674,6 @@ class repo extends control
$this->locate($this->repo->createLink('diff', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($entry) . "&oldrevision=$oldRevision&newRevision=$newRevision&showBug=&encoding=$encoding"));
}
$this->commonAction($repoID);
$this->scm->setEngine($repo);
$encoding = empty($encoding) ? $repo->encoding : $encoding;
$encoding = strtolower(str_replace('_', '-', $encoding));
+1 -1
View File
@@ -51,7 +51,7 @@ if(isset($entry)) $pathInfo .= '&type=file';
</table>
<div class='table-footer'>
<?php if(common::hasPriv('repo', 'diff')) echo html::submitButton($lang->repo->diff, '', count($revisions) < 2 ? 'disabled btn btn-primary' : 'btn btn-primary')?>
<?php echo html::a($this->repo->createLink('log', "repoID=$repoID&entry=" . $this->repo->encodePath($path) . "&revision=HEAD&type=$logType"), $lang->repo->allLog, '', "class='allLogs'");?>
<?php echo html::a($this->repo->createLink('log', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($path) . "&revision=HEAD&type=$logType"), $lang->repo->allLog, '', "class='allLogs' data-app='{$this->app->openApp}'");?>
<div class='pull-right'>
<div class='btn-group'>
<?php
+1 -1
View File
@@ -1081,7 +1081,7 @@ class user extends control
$sort = $this->loadModel('common')->appendOrder($orderBy);
$date = empty($date) ? '' : date('Y-m-d', $date);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', 'all', $date, $direction);
$actions = $this->loadModel('action')->getDynamic($account, $period, $sort, $pager, 'all', 'all', 'all', $date, $direction);
$this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->dynamic;
$this->view->position[] = $this->lang->user->dynamic;