diff --git a/module/issue/control.php b/module/issue/control.php index c7aaa0703b..5a663800d3 100644 --- a/module/issue/control.php +++ b/module/issue/control.php @@ -362,7 +362,7 @@ class issue extends control { $this->loadModel('task'); $this->loadModel('tree'); - $this->loadModel('project')->getLimitedProject(); + $this->loadModel('project')->getLimitedExecution(); $projects = $this->project->getExecutionPairs($this->session->PRJ); $projectID = $this->session->project; diff --git a/module/program/model.php b/module/program/model.php index ec765b2bcd..90c632343d 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -818,12 +818,29 @@ class programModel extends model $project->executions = $this->project->getExecutionStats($projectID, $status, 0, 0, $itemCounts, $orderBy); $project->teamCount = isset($teams[$projectID]) ? $teams[$projectID]->count : 0; $project->estimate = isset($estimates[$projectID]) ? $estimates[$projectID]->estimate : 0; - $project->parentName = $this->project->getProjectParentName($project->parent); + $project->parentName = $this->getPRJParentName($project->parent); } return $projects; } + /** + * Gets the top-level project name. + * + * @access private + * @return void + */ + public function getPRJParentName($parentID = 0) + { + if($parentID == 0) return ''; + + static $parent; + $parent = $this->dao->select('id,parent,name')->from(TABLE_PROJECT)->where('id')->eq($parentID)->fetch(); + if($parent->parent) $this->getPRJParentName($parent->parent); + + return $parent->name; + } + /** * Get project overview for block. * diff --git a/module/programplan/model.php b/module/programplan/model.php index 414819dfb2..e336c03e13 100644 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -586,7 +586,7 @@ class programplanModel extends model $member->days = $data->days; $member->hours = $this->config->project->defaultWorkhours; $this->dao->insert(TABLE_TEAM)->data($member)->exec(); - $this->project->addProjectMembers($data->project, array($member)); + $this->project->addExecutionMembers($data->project, array($member)); $this->setTreePath($stageID); if($data->acl != 'open') $this->user->updateUserView($stageID, 'sprint'); diff --git a/module/project/control.php b/module/project/control.php index 33f8a0b88c..61e8deae01 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -79,7 +79,7 @@ class project extends control $projectID = $this->project->saveState($projectID, $this->projects); $project = $this->project->getById($projectID); $products = $this->project->getProducts($projectID); - $childProjects = $this->project->getChildProjects($projectID); + $childProjects = $this->project->getChildExecutions($projectID); $teamMembers = $this->project->getTeamMembers($projectID); $actions = $this->loadModel('action')->getList('project', $projectID); @@ -117,7 +117,7 @@ class project extends control if(common::hasPriv('project', 'create')) $this->lang->TRActions = html::a($this->createLink('project', 'create', ''), " " . $this->lang->project->create, '', "class='btn btn-primary'"); - $this->project->getLimitedProject(); + $this->project->getLimitedExecution(); /* Set browse type. */ $browseType = strtolower($status); @@ -443,7 +443,7 @@ class project extends control $project = $this->commonAction($toProject); $toProject = $project->id; - $branches = $this->project->getProjectBranches($toProject); + $branches = $this->project->getExecutionBranches($toProject); $tasks = $this->project->getTasks2Imported($toProject, $branches); $projects = $this->project->getProjectsToImport(array_keys($tasks)); unset($projects[$toProject]); @@ -644,7 +644,7 @@ class project extends control $this->loadModel('user'); $this->app->loadLang('testcase'); - $this->project->getLimitedProject(); + $this->project->getLimitedExecution(); $type = strtolower($type); setcookie('storyPreProjectID', $projectID, $this->config->cookieLife, $this->config->webRoot, '', false, true); @@ -1659,7 +1659,7 @@ class project extends control { $this->project->setMenu($this->projects, $projectID); $project = $this->loadModel('project')->getById($projectID); - $tree = $this->project->getProjectTree($projectID); + $tree = $this->project->getExecutionTree($projectID); /* Save to session. */ $uri = $this->app->getURI(true); @@ -2318,7 +2318,7 @@ class project extends control { $project = $this->project->getByID($projectID); - $this->view->link = $this->project->getProjectLink($module, $method, $extra); + $this->view->link = $this->project->getExecutionLink($module, $method, $extra); $this->view->projectID = $projectID; $this->view->module = $module; $this->view->method = $method; diff --git a/module/project/model.php b/module/project/model.php index c173791552..6ac3608722 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -383,7 +383,7 @@ class projectModel extends model $member->hours = $this->config->project->defaultWorkhours; $this->dao->insert(TABLE_TEAM)->data($member)->exec(); - $this->addProjectMembers($this->session->PRJ, array($member)); + $this->addExecutionMembers($this->session->PRJ, array($member)); } /* Create doc lib. */ @@ -1065,6 +1065,147 @@ class projectModel extends model return $parents; } + /** + * Create the link from module,method,extra + * + * @param string $module + * @param string $method + * @param mix $extra + * @access public + * @return void + */ + public function getExecutionLink($module, $method, $extra) + { + $link = ''; + if($module == 'task' and ($method == 'view' || $method == 'edit' || $method == 'batchedit')) + { + $module = 'project'; + $method = 'task'; + } + if($module == 'build' and ($method == 'edit' || $method= 'view')) + { + $module = 'project'; + $method = 'build'; + } + + if($module == 'project' and $method == 'create') return; + if($extra != '') + { + $link = helper::createLink($module, $method, "projectID=%s&type=$extra"); + } + elseif($module == 'project' && ($method == 'index' or $method == 'all')) + { + $link = helper::createLink($module, 'task', "projectID=%s"); + } + else + { + $link = helper::createLink($module, $method, "projectID=%s"); + } + + if($module == 'doc') $link = helper::createLink('doc', 'objectLibs', "type=project&objectID=%s&from=project"); + return $link; + } + + /** + * Get branches of execution. + * + * @param int $executionID + * @access public + * @return array + */ + public function getExecutionBranches($executionID) + { + $productBranchPairs = $this->dao->select('product, branch')->from(TABLE_PROJECTPRODUCT) + ->where('project')->eq($executionID) + ->fetchPairs(); + $branches = $this->loadModel('branch')->getByProducts(array_keys($productBranchPairs)); + foreach($productBranchPairs as $product => $branch) + { + if($branch == 0 and isset($branches[$product])) $productBranchPairs[$product] = join(',', array_keys($branches[$product])); + } + + return $productBranchPairs; + } + + /** + * Get executions tree data + * @param int $executionID + * @access public + * @return array + */ + public function getExecutionTree($executionID) + { + $fullTrees = $this->loadModel('tree')->getTaskStructure($executionID, 0); + array_unshift($fullTrees, array('id' => 0, 'name' => '/', 'type' => 'task', 'actions' => false, 'root' => $executionID)); + foreach($fullTrees as $i => $tree) + { + $tree = (object)$tree; + if($tree->type == 'product') array_unshift($tree->children, array('id' => 0, 'name' => '/', 'type' => 'story', 'actions' => false, 'root' => $tree->root)); + $fullTree = $this->fillTasksInTree($tree, $executionID); + if(empty($fullTree->children)) + { + unset($fullTrees[$i]); + } + else + { + $fullTrees[$i] = $fullTree; + } + } + if(isset($fullTrees[0]) and empty($fullTrees[0]->children)) array_shift($fullTrees); + return array_values($fullTrees); + } + + /** + * Get related executions + * + * @param int $executionID + * @access public + * @return array + */ + public function getRelatedExecutions($executionID) + { + $products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$executionID)->fetchAll('product'); + // $products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->fetchAll('product'); + if(!$products) return array(); + $products = array_keys($products); + return $this->dao->select('t1.id, t1.name')->from(TABLE_EXECUTION)->alias('t1') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2') + ->on('t1.id = t2.project') + ->where('t2.product')->in($products) + ->andWhere('t1.id')->ne((int)$executionID) + ->andWhere('t1.deleted')->eq(0) + ->orderBy('t1.id') + ->fetchPairs(); + } + + /** + * Get child executions. + * + * @param int $executionID + * @access public + * @return void + */ + public function getChildExecutions($executionID) + { + return $this->dao->select('id, name')->from(TABLE_EXECUTION)->where('parent')->eq((int)$executionID)->fetchPairs(); + } + + /** + * Check the privilege. + * + * @access public + * @return bool + */ + public function getLimitedExecution() + { + /* If is admin, return true. */ + if($this->app->user->admin) return true; + + /* Get all teams of all executions and group by executions, save it as static. */ + $executions = $this->dao->select('root, limited')->from(TABLE_TEAM)->where('type')->eq('project')->andWhere('account')->eq($this->app->user->account)->andWhere('limited')->eq('yes')->orderBy('root asc')->fetchPairs('root', 'root'); + $_SESSION['limitedProjects'] = join(',', $executions); + } + /** * Get projects lists grouped by product. * @@ -1448,29 +1589,6 @@ class projectModel extends model if($needUpdate) $this->user->updateUserView($needUpdate, 'product', $members); } - /** - * Get related projects - * - * @param int $projectID - * @access public - * @return array - */ - public function getRelatedProjects($projectID) - { - $products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$projectID)->fetchAll('product'); - // $products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->fetchAll('product'); - if(!$products) return array(); - $products = array_keys($products); - return $this->dao->select('t1.id, t1.name')->from(TABLE_PROJECT)->alias('t1') - ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2') - ->on('t1.id = t2.project') - ->where('t2.product')->in($products) - ->andWhere('t1.id')->ne((int)$projectID) - ->andWhere('t1.deleted')->eq(0) - ->orderBy('t1.id') - ->fetchPairs(); - } - /** * Get tasks can be imported. * @@ -1742,18 +1860,6 @@ class projectModel extends model return $mails; } - /** - * Get child projects. - * - * @param int $projectID - * @access public - * @return void - */ - public function getChildProjects($projectID) - { - return $this->dao->select('id, name')->from(TABLE_PROJECT)->where('parent')->eq((int)$projectID)->fetchPairs(); - } - /** * Update childs. * @@ -2069,23 +2175,23 @@ class projectModel extends model /* Add iteration or phase team members to the project team. */ if($projectType == 'stage' || $projectType == 'sprint') { - $this->addProjectMembers($project->project, $projectMember); + $this->addExecutionMembers($project->project, $projectMember); if($project->acl != 'open') $this->updateUserView($projectID, 'sprint', $changedAccounts); } } /** - * Add iteration or phase team members to the project team. + * Add iteration or phase team members to the execution team. * - * @param int $projectID + * @param int $executionID * @param array $members * @access public * @return void */ - public function addProjectMembers($projectID = 0, $members = array()) + public function addExecutionMembers($executionID = 0, $members = array()) { - $projectType = 'project'; - $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($projectID)->andWhere('type')->eq($projectType)->fetchPairs(); + $executionType = 'project'; + $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->fetchPairs(); $accounts = array(); foreach($members as $account => $member) @@ -2093,8 +2199,8 @@ class projectModel extends model if(isset($oldJoin[$member->account])) continue; $accounts[] = $member->account; - $member->root = $projectID; - $member->type = $projectType; + $member->root = $executionID; + $member->type = $executionType; $this->dao->insert(TABLE_TEAM)->data($member)->exec(); } @@ -2104,8 +2210,8 @@ class projectModel extends model $changedAccounts = array_merge($changedAccounts, array_diff($oldAccounts, $accounts)); $changedAccounts = array_unique($changedAccounts); - $this->loadModel('user')->updateUserView($projectID, $projectType, $changedAccounts); - $linkedProducts = $this->loadModel('product')->getProductPairsByProject($projectID); + $this->loadModel('user')->updateUserView($executionID, $executionType, $changedAccounts); + $linkedProducts = $this->loadModel('product')->getProductPairsByProject($executionID); if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts); } @@ -2479,47 +2585,6 @@ class projectModel extends model return true; } - /** - * Create the link from module,method,extra - * - * @param string $module - * @param string $method - * @param mix $extra - * @access public - * @return void - */ - public function getProjectLink($module, $method, $extra) - { - $link = ''; - if($module == 'task' and ($method == 'view' || $method == 'edit' || $method == 'batchedit')) - { - $module = 'project'; - $method = 'task'; - } - if($module == 'build' and ($method == 'edit' || $method= 'view')) - { - $module = 'project'; - $method = 'build'; - } - - if($module == 'project' and $method == 'create') return; - if($extra != '') - { - $link = helper::createLink($module, $method, "projectID=%s&type=$extra"); - } - elseif($module == 'project' && ($method == 'index' or $method == 'all')) - { - $link = helper::createLink($module, 'task', "projectID=%s"); - } - else - { - $link = helper::createLink($module, $method, "projectID=%s"); - } - - if($module == 'doc') $link = helper::createLink('doc', 'objectLibs', "type=project&objectID=%s&from=project"); - return $link; - } - /** * Get no weekend date * @@ -2573,23 +2638,6 @@ class projectModel extends model return round($estimate); } - /** - * Check the privilege. - * - * @param object $project - * @access public - * @return bool - */ - public function getLimitedProject() - { - /* If is admin, return true. */ - if($this->app->user->admin) return true; - - /* Get all teams of all projects and group by projects, save it as static. */ - $projects = $this->dao->select('root, limited')->from(TABLE_TEAM)->where('type')->eq('project')->andWhere('account')->eq($this->app->user->account)->andWhere('limited')->eq('yes')->orderBy('root asc')->fetchPairs('root', 'root'); - $_SESSION['limitedProjects'] = join(',', $projects); - } - /** * Fix order. * @@ -2610,27 +2658,6 @@ class projectModel extends model } } - /** - * Get branches of project. - * - * @param int $projectID - * @access public - * @return array - */ - public function getProjectBranches($projectID) - { - $productBranchPairs = $this->dao->select('product, branch')->from(TABLE_PROJECTPRODUCT) - ->where('project')->eq($projectID) - ->fetchPairs(); - $branches = $this->loadModel('branch')->getByProducts(array_keys($productBranchPairs)); - foreach($productBranchPairs as $product => $branch) - { - if($branch == 0 and isset($branches[$product])) $productBranchPairs[$product] = join(',', array_keys($branches[$product])); - } - - return $productBranchPairs; - } - /** * Build bug search form. * @@ -3023,23 +3050,6 @@ class projectModel extends model return $chartData; } - /** - * Gets the top-level project name. - * - * @access private - * @return void - */ - public function getProjectParentName($parentID = 0) - { - if($parentID == 0) return ''; - - static $parent; - $parent = $this->dao->select('id,parent,name')->from(TABLE_PROJECT)->where('id')->eq($parentID)->fetch(); - if($parent->parent) $this->getProjectParentName($parent->parent); - - return $parent->name; - } - /** * Fill tasks in tree. * @param object $tree @@ -3235,34 +3245,6 @@ class projectModel extends model return $taskItems; } - /** - * Get projects tree data - * @param int $projectID - * @access public - * @return array - */ - public function getProjectTree($projectID) - { - $fullTrees = $this->loadModel('tree')->getTaskStructure($projectID, 0); - array_unshift($fullTrees, array('id' => 0, 'name' => '/', 'type' => 'task', 'actions' => false, 'root' => $projectID)); - foreach($fullTrees as $i => $tree) - { - $tree = (object)$tree; - if($tree->type == 'product') array_unshift($tree->children, array('id' => 0, 'name' => '/', 'type' => 'story', 'actions' => false, 'root' => $tree->root)); - $fullTree = $this->fillTasksInTree($tree, $projectID); - if(empty($fullTree->children)) - { - unset($fullTrees[$i]); - } - else - { - $fullTrees[$i] = $fullTree; - } - } - if(isset($fullTrees[0]) and empty($fullTrees[0]->children)) array_shift($fullTrees); - return array_values($fullTrees); - } - /** * Get plans by $productID. * diff --git a/module/task/control.php b/module/task/control.php index c5703addfc..a039803465 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -41,7 +41,7 @@ class task extends control $projects = $this->project->getExecutionPairs($this->session->PRJ); $projectID = $this->project->saveState($projectID, $projects); - $this->project->getLimitedProject(); + $this->project->getLimitedExecution(); $limitedProjects = !empty($_SESSION['limitedProjects']) ? $_SESSION['limitedProjects'] : ''; if(strpos(",{$limitedProjects},", ",$projectID,") !== false) { @@ -236,7 +236,7 @@ class task extends control */ public function batchCreate($projectID = 0, $storyID = 0, $moduleID = 0, $taskID = 0, $iframe = 0) { - $this->project->getLimitedProject(); + $this->project->getLimitedExecution(); $limitedProjects = !empty($_SESSION['limitedProjects']) ? $_SESSION['limitedProjects'] : ''; if(strpos(",{$limitedProjects},", ",$projectID,") !== false) {