From 4c237e260175b7f796be22bf554446257bc8e136 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Wed, 24 Mar 2021 14:51:28 +0800 Subject: [PATCH] * Fix dynamic logic. --- module/action/model.php | 90 ++++++++++++++--------- module/company/control.php | 3 +- module/execution/control.php | 4 +- module/my/control.php | 2 +- module/product/control.php | 2 +- module/program/control.php | 2 +- module/program/lang/de.php | 1 + module/program/lang/fr.php | 1 + module/program/lang/vi.php | 1 + module/program/view/start.html.php | 6 +- module/project/config.php | 6 +- module/project/control.php | 2 +- module/project/model.php | 5 +- module/repo/control.php | 9 ++- module/repo/view/ajaxsidecommits.html.php | 2 +- module/user/control.php | 2 +- 16 files changed, 83 insertions(+), 55 deletions(-) diff --git a/module/action/model.php b/module/action/model.php index ac1f99b42a..abc486f7d7 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -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() diff --git a/module/company/control.php b/module/company/control.php index 2bd9d14868..503156f065 100644 --- a/module/company/control.php +++ b/module/company/control.php @@ -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 { diff --git a/module/execution/control.php b/module/execution/control.php index 577032ef5f..3a06f25f7c 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -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); diff --git a/module/my/control.php b/module/my/control.php index 91f79027d1..e028853305 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -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; diff --git a/module/product/control.php b/module/product/control.php index 595f290cc0..f4ac5ef0f0 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -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; diff --git a/module/program/control.php b/module/program/control.php index 78fb4f8f60..6943b64753 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -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)) diff --git a/module/program/lang/de.php b/module/program/lang/de.php index ae61763e88..c71e6b8c6f 100644 --- a/module/program/lang/de.php +++ b/module/program/lang/de.php @@ -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'; diff --git a/module/program/lang/fr.php b/module/program/lang/fr.php index ae61763e88..c71e6b8c6f 100644 --- a/module/program/lang/fr.php +++ b/module/program/lang/fr.php @@ -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'; diff --git a/module/program/lang/vi.php b/module/program/lang/vi.php index ddc3574630..522435301a 100644 --- a/module/program/lang/vi.php +++ b/module/program/lang/vi.php @@ -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'; diff --git a/module/program/view/start.html.php b/module/program/view/start.html.php index e6e826a4dd..4290dee056 100644 --- a/module/program/view/start.html.php +++ b/module/program/view/start.html.php @@ -18,7 +18,7 @@ id;?> name'>" . $program->name . '') : html::a($this->createLink('project', 'view', 'project=' . $program->id), $program->name, '_blank');?> - arrow . $lang->project->start;?> + arrow . $lang->program->start;?> @@ -26,7 +26,7 @@ - + @@ -36,7 +36,7 @@ diff --git a/module/project/config.php b/module/project/config.php index a0892f2c03..de06ba0ca8 100644 --- a/module/project/config.php +++ b/module/project/config.php @@ -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'; diff --git a/module/project/control.php b/module/project/control.php index 00990d11c4..4f90ab3089 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -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); diff --git a/module/project/model.php b/module/project/model.php index 1f689e5572..224ecf61cf 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -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') diff --git a/module/repo/control.php b/module/repo/control.php index 85d0845cf5..77b86515ab 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -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)); diff --git a/module/repo/view/ajaxsidecommits.html.php b/module/repo/view/ajaxsidecommits.html.php index 613b537b19..7c71b1d93d 100644 --- a/module/repo/view/ajaxsidecommits.html.php +++ b/module/repo/view/ajaxsidecommits.html.php @@ -51,7 +51,7 @@ if(isset($entry)) $pathInfo .= '&type=file';
program->realBegan;?>project->realBegan;?>
- project->start);?> + program->start);?>