* @package product * @version $Id: control.php 5144 2013-07-15 06:37:03Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ class product extends control { public $products = array(); /** * Construct function. * * @access public * @return void */ public function __construct($moduleName = '', $methodName = '') { parent::__construct($moduleName, $methodName); /* Load need modules. */ $this->loadModel('story'); $this->loadModel('release'); $this->loadModel('tree'); $this->loadModel('user'); /* Get all products, if no, goto the create page. */ $this->products = $this->product->getPairs('nocode'); if(empty($this->products) and strpos(',create,index,showerrornone,', $this->methodName) === false and $this->app->getViewType() != 'mhtml') $this->locate($this->createLink('product', 'create')); $this->view->products = $this->products; } /** * Index page, to browse. * * @param string $locate locate to browse page or not. If not, display all products. * @param int $productID * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function index($locate = 'auto', $productID = 0, $status = 'noclosed', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 10, $pageID = 1) { $this->lang->product->switcherMenu = $this->product->getSwitcher(); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); if($locate == 'yes') $this->locate($this->createLink($this->moduleName, 'browse')); if($this->app->getViewType() != 'mhtml') unset($this->lang->product->menu->index); $productID = $this->product->saveState($productID, $this->products); $branch = (int)$this->cookie->preBranch; //$this->product->setMenu($this->products, $productID, $branch); if(common::hasPriv('product', 'create')) $this->lang->TRActions = html::a($this->createLink('product', 'create'), " " . $this->lang->product->create, '', "class='btn btn-primary'"); $this->view->title = $this->lang->product->index; $this->view->position[] = $this->lang->product->index; $this->display(); } /** * The projects which linked the product. * * @param string $status * @param int $productID * @param int $branch * @param int $PRJMine * @access public * @return void */ public function project($status = 'all', $productID = 0, $branch = 0, $PRJMine = 0) { $this->product->setMenu($this->products, $productID, $branch); $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->app->loadLang('my'); $this->app->loadLang('program'); /* Get PM id list. */ $accounts = array(); $projectStats = $this->product->getProjectStatsByProduct($productID, $status, $branch, $PRJMine); foreach($projectStats as $project) { if(!empty($project->PM) and !in_array($project->PM, $accounts)) $accounts[] = $project->PM; } $PMList = $this->user->getListByAccounts($accounts, 'account'); $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->product->project; $this->view->position[] = $this->products[$productID]; $this->view->position[] = $this->lang->product->project; $this->view->projectStats = $projectStats; $this->view->PMList = $PMList; $this->view->productID = $productID; $this->view->status = $status; $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->display(); } /** * Browse a product. * * @param int $productID * @param int $branch * @param string $browseType * @param int $param * @param string $storyType requirement|story * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function browse($productID = 0, $branch = 0, $browseType = '', $param = 0, $storyType = 'story', $orderBy = '', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Lower browse type. */ $browseType = strtolower($browseType); /* Load datatable. */ $this->loadModel('datatable'); /* Set product, module and query. */ $productID = $this->product->saveState($productID, $this->products); $branch = ($branch === '') ? (int)$this->cookie->preBranch : (int)$branch; setcookie('preProductID', $productID, $this->config->cookieLife, $this->config->webRoot, '', false, true); setcookie('preBranch', (int)$branch, $this->config->cookieLife, $this->config->webRoot, '', false, true); if($this->cookie->preProductID != $productID or $this->cookie->preBranch != $branch or $browseType == 'bybranch') { $_COOKIE['storyModule'] = 0; setcookie('storyModule', 0, 0, $this->config->webRoot, '', false, false); } if($browseType == 'bymodule' or $browseType == '') { setcookie('storyModule', (int)$param, 0, $this->config->webRoot, '', false, false); $_COOKIE['storyBranch'] = 0; setcookie('storyBranch', 0, 0, $this->config->webRoot, '', false, false); if($browseType == '') setcookie('treeBranch', (int)$branch, 0, $this->config->webRoot, '', false, false); } if($browseType == 'bybranch') setcookie('storyBranch', (int)$branch, 0, $this->config->webRoot, '', false, false); $moduleID = ($browseType == 'bymodule') ? (int)$param : (($browseType == 'bysearch' or $browseType == 'bybranch') ? 0 : ($this->cookie->storyModule ? $this->cookie->storyModule : 0)); $queryID = ($browseType == 'bysearch') ? (int)$param : 0; /* Set menu. The projectstory module does not execute. */ if($this->app->rawModule == 'product') { /* Save session. */ $this->session->set('storyList', $this->app->getURI(true)); $this->session->set('productList', $this->app->getURI(true)); $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->product->getSwitcher($productID, "storyType=$storyType", $branch); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->product->setMenu($this->products, $productID, $branch); } /* Set moduleTree. */ $createModuleLink = $storyType == 'story' ? 'createStoryLink' : 'createRequirementLink'; if($browseType == '') { setcookie('treeBranch', (int)$branch, 0, $this->config->webRoot, '', false, false); $browseType = 'unclosed'; $moduleTree = $this->tree->getTreeMenu($productID, 'story', $startModuleID = 0, array('treeModel', $createModuleLink), '', $branch, "¶m=$param&storyType=$storyType"); } else { $moduleTree = $this->tree->getTreeMenu($productID, 'story', $startModuleID = 0, array('treeModel', $createModuleLink), '', (int)$this->cookie->treeBranch, "¶m=$param&storyType=$storyType"); } if($browseType != 'bymodule' and $browseType != 'bybranch') $this->session->set('storyBrowseType', $browseType); if(($browseType == 'bymodule' or $browseType == 'bybranch') and $this->session->storyBrowseType == 'bysearch') $this->session->set('storyBrowseType', 'unclosed'); /* Process the order by field. */ if(!$orderBy) $orderBy = $this->cookie->productStoryOrder ? $this->cookie->productStoryOrder : 'id_desc'; setcookie('productStoryOrder', $orderBy, 0, $this->config->webRoot, '', false, true); /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); /* Get stories. */ $stories = $this->product->getStories($productID, $branch, $browseType, $queryID, $moduleID, $storyType, $sort, $pager); if($this->app->rawModule == 'projectstory') { $projectProducts = $this->product->getProductsByProject($this->session->PRJ); $productPlans = $this->loadModel('project')->getPlans($projectProducts); if($browseType == 'bybranch') $param = $branch; $stories = $this->story->getProjectStories($this->session->PRJ, $sort, $browseType, $param, 'story', '', $pager, $productID, $branch); } /* Process the sql, get the conditon partion, save it to session. */ $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story', $browseType != 'bysearch' && $this->app->rawModule != 'projectstory'); /* Get related tasks, bugs, cases count of each story. */ $storyIdList = array(); foreach($stories as $story) { $storyIdList[$story->id] = $story->id; if(!empty($story->children)) { foreach($story->children as $child) $storyIdList[$child->id] = $child->id; } } $storyTasks = $this->loadModel('task')->getStoryTaskCounts($storyIdList); $storyBugs = $this->loadModel('bug')->getStoryBugCounts($storyIdList); $storyCases = $this->loadModel('testcase')->getStoryCaseCounts($storyIdList); /* Change for requirement story title. */ if($storyType == 'requirement') { $this->lang->story->title = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title); $this->lang->story->create = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->create); $this->config->product->search['fields']['title'] = $this->lang->story->title; } /* Build search form. */ $rawModule = $this->app->rawModule; $rawMethod = $this->app->rawMethod; $actionURL = $this->createLink($rawModule, $rawMethod, "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID&storyType=$storyType"); $this->config->product->search['onMenuBar'] = 'yes'; $this->product->buildSearchForm($productID, $this->products, $queryID, $actionURL); $showModule = !empty($this->config->datatable->productBrowse->showModule) ? $this->config->datatable->productBrowse->showModule : ''; $this->view->modulePairs = $showModule ? $this->tree->getModulePairs($productID, 'story', $showModule) : array(); /* Assign. */ $this->view->title = $this->products[$productID]. $this->lang->colon . $this->lang->product->browse; $this->view->position[] = $this->products[$productID]; $this->view->position[] = $this->lang->product->browse; $this->view->productID = $productID; $this->view->product = $this->product->getById($productID); $this->view->productName = $this->products[$productID]; $this->view->moduleID = $moduleID; $this->view->stories = $stories; $this->view->plans = $this->loadModel('productplan')->getPairs($productID, $branch, '', true); $this->view->productPlans = isset($productPlans) ? $productPlans : array(); $this->view->summary = $this->product->summary($stories, $storyType); $this->view->moduleTree = $moduleTree; $this->view->parentModules = $this->tree->getParents($moduleID); $this->view->pager = $pager; $this->view->users = $this->user->getPairs('noletter|pofirst|nodeleted'); $this->view->orderBy = $orderBy; $this->view->browseType = $browseType; $this->view->modules = $this->tree->getOptionMenu($productID, 'story', 0, $branch); $this->view->moduleID = $moduleID; $this->view->moduleName = $moduleID ? $this->tree->getById($moduleID)->name : $this->lang->tree->all; $this->view->branch = $branch; $this->view->branches = $this->loadModel('branch')->getPairs($productID); $this->view->storyStages = $this->product->batchGetStoryStage($stories); $this->view->setModule = true; $this->view->storyTasks = $storyTasks; $this->view->storyBugs = $storyBugs; $this->view->storyCases = $storyCases; $this->view->param = $param; $this->view->products = $this->products; $this->view->projectProducts = isset($projectProducts) ? $projectProducts : array(); $this->view->storyType = $storyType; $this->display(); } /** * Create a product. * * @param int $programID * @access public * @return void */ public function create($programID = 0) { $this->lang->product->switcherMenu = $this->product->getSwitcher(); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); if(!empty($_POST)) { $productID = $this->product->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action')->create('product', $productID, 'opened'); $this->executeHooks($productID); $moduleName = $programID ? 'program' : $this->moduleName; $methodName = $programID ? 'pgmproduct' : 'browse'; $param = $programID ? "programID=$programID" : "productID=$productID"; $locate = $this->createLink($moduleName, $methodName, $param); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate)); } if($programID) { $this->app->rawModule = 'program'; $this->app->rawMethod = 'pgmproduct'; $this->lang->navGroup->program = 'program'; $this->loadModel('program')->setPGMViewMenu($programID); $this->lang->program->switcherMenu = $this->program->getPGMSwitcher($programID, true); $this->lang->program->mainMenuAction = $this->program->getPGMMainAction(); } $this->loadModel('user'); $poUsers = $this->user->getPairs('nodeleted|pofirst|noclosed', '', $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["PO"] = $this->config->user->moreLink; $qdUsers = $this->user->getPairs('nodeleted|qdfirst|noclosed', '', $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["QD"] = $this->config->user->moreLink; $rdUsers = $this->user->getPairs('nodeleted|devfirst|noclosed', '', $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["RD"] = $this->config->user->moreLink; $this->view->title = $this->lang->product->create; $this->view->position[] = $this->view->title; $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->poUsers = $poUsers; $this->view->qdUsers = $qdUsers; $this->view->rdUsers = $rdUsers; $this->view->users = $this->user->getPairs('nodeleted|noclosed'); $this->view->programs = array('') + $this->loadModel('program')->getTopPGMPairs(); $this->view->lines = array('') + $this->loadModel('tree')->getLinePairs(); $this->view->URSRPairs = $this->loadModel('custom')->getURSRPairs(); unset($this->lang->product->typeList['']); $this->display(); } /** * Edit a product. * * @param int $productID * @param string $action * @param string $extra * @param int $programID * @access public * @return void */ public function edit($productID, $action = 'edit', $extra = '', $programID = 0) { /* Set menu. */ $this->app->loadLang('custom'); $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); /* Init vars. */ $product = $this->product->getById($productID); $notRemovePRJ = array(); $canChangePGM = true; $singleLinkProjects = array(); $multipleLinkProjects = array(); $linkStoriesProjects = array(); /* Link the projects stories under this product. */ $notRemovePRJ = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('product')->eq($productID)->fetchPairs('project', 'product'); if(!empty($notRemovePRJ)) $canChangePGM = false; /* Get the projects linked with this product. */ $projectPairs = $this->product->getProjectPairsByProduct($productID); if(!empty($projectPairs)) { foreach($projectPairs as $projectID => $projectName) { if($canChangePGM) { $products = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchPairs(); if(count($products) == 1) { $singleLinkProjects[$projectID] = $projectName; } if(count($products) > 1) { $multipleLinkProjects[$projectID] = $projectName; } } else { if(isset($notRemovePRJ[$projectID])) $linkStoriesProjects[$projectID] = $projectName; } } } if(!empty($_POST)) { $changes = $this->product->update($productID); /* Change the projects set of the program. */ if(($_POST['program'] != $product->program) and $singleLinkProjects or $multipleLinkProjects) { $this->product->updateProjects($productID, $singleLinkProjects, $multipleLinkProjects); } if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); if($action == 'undelete') { $this->loadModel('action'); $this->dao->update(TABLE_PRODUCT)->set('deleted')->eq(0)->where('id')->eq($productID)->exec(); $this->dao->update(TABLE_ACTION)->set('extra')->eq(ACTIONMODEL::BE_UNDELETED)->where('id')->eq($extra)->exec(); $this->action->create('product', $productID, 'undeleted'); } if($changes) { $actionID = $this->loadModel('action')->create('product', $productID, 'edited'); $this->action->logHistory($actionID, $changes); } $this->executeHooks($productID); $moduleName = $programID ? 'program' : 'product'; $methodName = $programID ? 'pgmproduct' : 'view'; $param = $programID ? "programID=$programID" : "product=$productID"; $locate = $this->createLink($moduleName, $methodName, $param); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate)); } $this->product->setMenu($this->products, $productID); $moduleIndex = array_search('product', $this->lang->noMenuModule); unset($this->lang->noMenuModule[$moduleIndex]); if($programID) { $this->app->rawModule = 'program'; $this->app->rawMethod = 'pgmproduct'; $this->lang->navGroup->program = 'program'; $this->loadModel('program')->setPGMViewMenu($programID); $this->lang->program->switcherMenu = $this->program->getPGMSwitcher($programID, true); $this->lang->program->mainMenuAction = $this->program->getPGMMainAction(); } /* Get the relevant person in charge. */ $this->loadModel('user'); $poUsers = $this->user->getPairs('nodeleted|pofirst', $product->PO, $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["PO"] = $this->config->user->moreLink; $qdUsers = $this->user->getPairs('nodeleted|qdfirst', $product->QD, $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["QD"] = $this->config->user->moreLink; $rdUsers = $this->user->getPairs('nodeleted|devfirst', $product->RD, $this->config->maxCount); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["RD"] = $this->config->user->moreLink; $this->view->title = $this->lang->product->edit . $this->lang->colon . $product->name; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name); $this->view->position[] = $this->lang->product->edit; $this->view->product = $product; $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->program = $this->loadModel('program')->getParentPairs(); $this->view->poUsers = $poUsers; $this->view->poUsers = $poUsers; $this->view->qdUsers = $qdUsers; $this->view->rdUsers = $rdUsers; $this->view->users = $this->user->getPairs('nodeleted|noclosed'); $this->view->programs = array('') + $this->loadModel('program')->getTopPGMPairs(); $this->view->lines = array('') + $this->loadModel('tree')->getLinePairs(); $this->view->URSRPairs = $this->loadModel('custom')->getURSRPairs(); $this->view->canChangePGM = $canChangePGM; $this->view->singleLinkProjects = $singleLinkProjects; $this->view->multipleLinkProjects = $multipleLinkProjects; $this->view->linkStoriesProjects = $linkStoriesProjects; unset($this->lang->product->typeList['']); $this->display(); } /** * Batch edit products. * * @param int $programID * @access public * @return void */ public function batchEdit($programID) { $this->lang->product->switcherMenu = ''; if($this->post->names) { $allChanges = $this->product->batchUpdate(); if(!empty($allChanges)) { foreach($allChanges as $productID => $changes) { if(empty($changes)) continue; $actionID = $this->loadModel('action')->create('product', $productID, 'Edited'); $this->action->logHistory($actionID, $changes); } } $locate = $this->createLink('program', 'pgmproduct', "programID=$programID"); die(js::locate($locate, 'parent')); } $productIDList = $this->post->productIDList ? $this->post->productIDList : die(js::locate($this->session->productList, 'parent')); /* Set custom. */ foreach(explode(',', $this->config->product->customBatchEditFields) as $field) $customFields[$field] = $this->lang->product->$field; $this->view->customFields = $customFields; $this->view->showFields = $this->config->product->custom->batchEditFields; $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in($productIDList)->fetchAll('id'); $appendPoUsers = $appendQdUsers = $appendRdUsers = array(); foreach($products as $product) { $appendPoUsers[$product->PO] = $product->PO; $appendQdUsers[$product->QD] = $product->QD; $appendRdUsers[$product->RD] = $product->RD; } /* Navigation remains under the program. */ $this->app->rawModule = 'program'; $this->app->rawMethod = 'pgmproduct'; $this->lang->navGroup->program = 'program'; $this->loadModel('program')->setPGMViewMenu($programID); $this->lang->program->switcherMenu = $this->program->getPGMSwitcher($programID, true); $this->lang->program->mainMenuAction = $this->program->getPGMMainAction(); $this->loadModel('user'); $poUsers = $this->user->getPairs('nodeleted|pofirst', $appendPoUsers); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["PO"] = $this->config->user->moreLink; $qdUsers = $this->user->getPairs('nodeleted|qdfirst', $appendQdUsers); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["QD"] = $this->config->user->moreLink; $rdUsers = $this->user->getPairs('nodeleted|devfirst', $appendRdUsers); if(!empty($this->config->user->moreLink)) $this->config->moreLinks["RD"] = $this->config->user->moreLink; $this->view->title = $this->lang->product->batchEdit; $this->view->position[] = $this->lang->product->batchEdit; $this->view->lines = array('') + $this->tree->getLinePairs(); $this->view->productIDList = $productIDList; $this->view->products = $products; $this->view->poUsers = $poUsers; $this->view->qdUsers = $qdUsers; $this->view->rdUsers = $rdUsers; unset($this->lang->product->typeList['']); $this->display(); } /** * Close product. * * @param int $productID * @access public * @return void */ public function close($productID) { $product = $this->product->getById($productID); $actions = $this->loadModel('action')->getList('product', $productID); if(!empty($_POST)) { $changes = $this->product->close($productID); if(dao::isError()) die(js::error(dao::getError())); if($this->post->comment != '' or !empty($changes)) { $actionID = $this->action->create('product', $productID, 'Closed', $this->post->comment); $this->action->logHistory($actionID, $changes); } $this->executeHooks($productID); die(js::reload('parent.parent')); } $this->product->setMenu($this->products, $productID); $this->view->product = $product; $this->view->title = $this->view->product->name . $this->lang->colon .$this->lang->close; $this->view->position[] = $this->lang->close; $this->view->actions = $actions; $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->display(); } /** * View a product. * * @param int $productID * @access public * @return void */ public function view($productID) { $product = $this->product->getStatByID($productID); if(!$product) die(js::error($this->lang->notFound) . js::locate('back')); $moduleIndex = array_search('product', $this->lang->noMenuModule); unset($this->lang->noMenuModule[$moduleIndex]); $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $product->desc = $this->loadModel('file')->setImgSize($product->desc); $this->product->setMenu($this->products, $productID); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = new pager(0, 30, 1); $this->executeHooks($productID); $this->view->title = $product->name . $this->lang->colon . $this->lang->product->view; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name); $this->view->position[] = $this->lang->product->view; $this->view->product = $product; $this->view->actions = $this->loadModel('action')->getList('product', $productID); $this->view->users = $this->user->getPairs('noletter'); $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->branches = $this->loadModel('branch')->getPairs($productID); $this->display(); } /** * Delete a product. * * @param int $productID * @param string $confirm yes|no * @access public * @return void */ public function delete($productID, $confirm = 'no') { if($confirm == 'no') { die(js::confirm($this->lang->product->confirmDelete, $this->createLink('product', 'delete', "productID=$productID&confirm=yes"))); } else { $this->product->delete(TABLE_PRODUCT, $productID); $this->dao->update(TABLE_DOCLIB)->set('deleted')->eq(1)->where('product')->eq($productID)->exec(); $this->session->set('product', ''); // 清除session。 $this->executeHooks($productID); die(js::locate($this->createLink('product', 'browse'), 'parent')); } } /** * Road map of a product. * * @param int $productID * @access public * @return void */ public function roadmap($productID, $branch = 0) { $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID, '', $branch); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->product->setMenu($this->products, $productID, $branch); $this->session->set('releaseList', $this->app->getURI(true)); $this->session->set('productPlanList', $this->app->getURI(true)); $product = $this->dao->findById($productID)->from(TABLE_PRODUCT)->fetch(); if(empty($product)) $this->locate($this->createLink('product', 'showErrorNone', 'fromModule=product')); $this->view->title = $product->name . $this->lang->colon . $this->lang->product->roadmap; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name); $this->view->position[] = $this->lang->product->roadmap; $this->view->product = $product; $this->view->roadmaps = $this->product->getRoadmap($productID, $branch); $this->view->branches = $product->type == 'normal' ? array(0 => '') : $this->loadModel('branch')->getPairs($productID); $this->display(); } /** * Product dynamic. * * @param int $productID * @param string $type * @param string $param * @param int $recTotal * @param string $date * @param string $direction next|pre * @access public * @return void */ public function dynamic($productID = 0, $type = 'today', $param = '', $recTotal = 0, $date = '', $direction = 'next') { /* Save session. */ $uri = $this->app->getURI(true); $this->session->set('productList', $uri); $this->session->set('productPlanList', $uri); $this->session->set('releaseList', $uri); $this->session->set('storyList', $uri); $this->session->set('projectList', $uri); $this->session->set('taskList', $uri); $this->session->set('buildList', $uri); $this->session->set('bugList', $uri); $this->session->set('caseList', $uri); $this->session->set('testtaskList', $uri); $this->product->setMenu($this->products, $productID); /* Append id for secend sort. */ $orderBy = $direction == 'next' ? 'date_desc' : 'date_asc'; $sort = $this->loadModel('common')->appendOrder($orderBy); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage = 50, $pageID = 1); /* Set the user and type. */ $account = 'all'; if($type == 'account') { $user = $this->loadModel('user')->getById((int)$param, 'id'); if($user) $account = $user->account; } $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); /* The header and position. */ $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->product->dynamic; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $this->products[$productID]); $this->view->position[] = $this->lang->product->dynamic; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID, $type); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->view->userIdPairs = $this->loadModel('user')->getPairs('noletter|nodeleted|noclosed|useid'); $this->view->accountPairs = $this->user->getPairs('noletter|nodeleted|noclosed'); /* Assign. */ $this->view->productID = $productID; $this->view->type = $type; $this->view->orderBy = $orderBy; $this->view->account = $account; $this->view->user = isset($user) ? $user : ''; $this->view->param = $param; $this->view->pager = $pager; $this->view->dateGroups = $this->action->buildDateGroup($actions, $direction, $type); $this->view->direction = $direction; $this->display(); } /** * Product dashboard. * * @param int $productID * @access public * @return void */ public function dashboard($productID = 0) { $productID = $this->product->saveState($productID, $this->products); $product = $this->product->getStatByID($productID); if(!$product) die(js::locate('product', 'all')); $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $product->desc = $this->loadModel('file')->setImgSize($product->desc); $this->product->setMenu($this->products, $productID); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = new pager(0, 30, 1); $this->executeHooks($productID); $this->view->title = $product->name . $this->lang->colon . $this->lang->product->view; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name); $this->view->position[] = $this->lang->product->view; $this->view->product = $product; $this->view->actions = $this->loadModel('action')->getList('product', $productID); $this->view->users = $this->user->getPairs('noletter'); $this->view->lines = array('') + $this->loadModel('tree')->getLinePairs(); $this->view->dynamics = $this->loadModel('action')->getDynamic('all', 'all', 'date_desc', $pager, $productID); $this->view->roadmaps = $this->product->getRoadmap($productID, 0, 6); $this->display(); } /** * AJAX: get projects of a product in html select. * * @param int $productID * @param int $projectID * @param string $number * @access public * @return void */ public function ajaxGetProjects($productID, $projectID = 0, $branch = 0, $number = '') { if($productID == 0) { $projects = array(0 => '') + $this->loadModel('project')->getExecutionPairs(); } else { $projects = $this->product->getExecutionPairsByProduct($productID, $branch ? "0,$branch" : $branch); } if($this->app->getViewType() == 'json') die(json_encode($projects)); if($number === '') { die(html::select('project', $projects, $projectID, "class='form-control' onchange='loadProjectRelated(this.value)'")); } else { $projectName = "projects[$number]"; $projects = empty($projects) ? array('' => '') : $projects; die(html::select($projectName, $projects, '', "class='form-control' onchange='loadProjectBuilds($productID, this.value, $number)'")); } } /** * AJAX: get plans of a product in html select. * * @param int $productID * @param int $planID * @param bool $needCreate * @param string $expired * @access public * @return void */ public function ajaxGetPlans($productID, $branch = 0, $planID = 0, $fieldID = '', $needCreate = false, $expired = '') { $plans = $this->loadModel('productplan')->getPairs($productID, $branch, $expired); $field = $fieldID ? "plans[$fieldID]" : 'plan'; $output = html::select($field, $plans, $planID, "class='form-control chosen'"); if(count($plans) == 1 and $needCreate) { $output .= "
"; $output .= html::a($this->createLink('productplan', 'create', "productID=$productID&branch=$branch", '', true), "", '', "class='btn btn-icon' data-toggle='modal' data-type='iframe' data-width='95%' title='{$this->lang->productplan->create}'"); $output .= '
'; $output .= "
"; $output .= html::a("javascript:void(0)", "", '', "class='btn btn-icon refresh' data-toggle='tooltip' title='{$this->lang->refresh}' onclick='loadProductPlans($productID)'"); $output .= '
'; } die($output); } /** * Drop menu page. * * @param int $productID * @param string $module * @param string $method * @param string $extra * @access public * @return void */ public function ajaxGetDropMenu($productID, $module, $method, $extra) { $inProduct = zget($this->lang->navGroup, $module) == 'product'; $products = $inProduct ? $this->product->getList() : $this->product->getProductsByProject($this->session->PRJ); $this->view->link = $this->product->getProductLink($module, $method, $extra); $this->view->productID = $productID; $this->view->module = $module; $this->view->method = $method; $this->view->extra = $extra; $this->view->products = $products; $this->view->projectID = $this->session->PRJ; $this->view->programs = $this->loadModel('program')->getPGMOption(); $this->display(); } /** * Update order. * * @access public * @return void */ public function updateOrder() { /* Init vars. */ $idList = explode(',', trim($this->post->products, ',')); $orderBy = $this->post->orderBy; if(strpos($orderBy, 'order') === false) return false; /* Remove programID. */ foreach($idList as $i => $id) { if(!is_numeric($id)) unset($idList[$i]); } /* Update order. */ $products = $this->dao->select('id,`order`')->from(TABLE_PRODUCT)->where('id')->in($idList)->orderBy($orderBy)->fetchPairs('order', 'id'); foreach($products as $order => $id) { $newID = array_shift($idList); if($id == $newID) continue; $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec(); } } /** * Show error no product when visit qa. * * @param string $fromModule * @access public * @return void */ public function showErrorNone($fromModule = 'bug') { if($fromModule != 'product') { $this->lang->navGroup->product = 'project'; $moduleIndex = array_search('product', $this->lang->noMenuModule); if($moduleIndex !== false) unset($this->lang->noMenuModule[$moduleIndex]); $this->view->project = $this->loadModel('program')->getPRJById($this->session->PRJ); } $this->loadModel($fromModule)->setMenu($this->products, key($this->products)); $this->lang->set('menugroup.product', 'qa'); $this->lang->product->menu = $this->lang->$fromModule->menu; $this->lang->product->menuOrder = $this->lang->$fromModule->menuOrder; $this->view->title = $this->lang->$fromModule->common; $this->view->fromModule = $fromModule; $this->display(); } /** * Products under project set. * * @param string $browseType * @param string $orderBy * @access public * @return void */ public function all($browseType = 'noclosed', $orderBy = 'order_asc') { $this->lang->product->mainMenuAction = html::a('javascript:history.go(-1);', ' ' . $this->lang->goback, '', "class='btn btn-link'"); /* Load module and set session. */ $this->loadModel('program'); $this->session->set('productList', $this->app->getURI(true)); /* Init vars. */ $programs = array(); $productStats = $this->product->getStats($orderBy, '', $browseType, '', 'story'); foreach($productStats as $product) { $programs[$product->program]->products[$product->id] = $product; if($product->program !== 0) $programs[$product->program]->name = $product->programName; } $this->view->title = $this->lang->product->common; $this->view->position[] = $this->lang->product->common; $this->view->recTotal = count($productStats); $this->view->productStats = $productStats; $this->view->programs = $programs; $this->view->orderBy = $orderBy; $this->view->browseType = $browseType; $this->display(); } /** * Get white list personnel. * * @param int $productID * @param string $module * @param string $objectType * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function whitelist($productID = 0, $module = 'product', $objectType = 'product', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID, '', 0); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->product->setMenu($this->products, $productID, 0); $this->lang->modulePageNav = ''; echo $this->fetch('personnel', 'whitelist', "objectID=$productID&module=product&browseType=$objectType&orderBy=$orderBy&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID"); } /** * Adding users to the white list. * * @param int $productID * @param int $deptID * @param string $branch * @access public * @return void */ public function addWhitelist($productID = 0, $deptID = 0, $branch = '') { $this->lang->product->menu = $this->lang->product->viewMenu; $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID, '', $branch); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); $this->product->setMenu($this->products, $productID, $branch); $moduleIndex = array_search('product', $this->lang->noMenuModule); if($moduleIndex !== false) unset($this->lang->noMenuModule[$moduleIndex]); $this->lang->modulePageNav = ''; echo $this->fetch('personnel', 'addWhitelist', "objectID=$productID&dept=$deptID&objectType=product&module=product"); } /* * Removing users from the white list. * * @param int $id * @param string $confirm * @access public * @return void */ public function unbindWhielist($id = 0, $confirm = 'no') { echo $this->fetch('personnel', 'unbindWhielist', "id=$id&confirm=$confirm"); } /** * Export product. * * @param string $status * @param string $orderBy * @access public * @return void */ public function export($status, $orderBy) { if($_POST) { $productLang = $this->lang->product; $productConfig = $this->config->product; /* Create field lists. */ $fields = $this->post->exportFields ? $this->post->exportFields : explode(',', $productConfig->list->exportFields); foreach($fields as $key => $fieldName) { $fieldName = trim($fieldName); $fields[$fieldName] = zget($productLang, $fieldName); unset($fields[$key]); } $lines = $this->loadModel('tree')->getLinePairs(); $productStats = $this->product->getStats($orderBy, null, $status); foreach($productStats as $i => $product) { $product->line = zget($lines, $product->line, ''); $product->activeStories = (int)$product->stories['active']; $product->changedStories = (int)$product->stories['changed']; $product->draftStories = (int)$product->stories['draft']; $product->closedStories = (int)$product->stories['closed']; $product->unResolvedBugs = (int)$product->unResolved; $product->assignToNullBugs = (int)$product->assignToNull; if($this->post->exportType == 'selected') { $checkedItem = $this->cookie->checkedItem; if(strpos(",$checkedItem,", ",{$product->id},") === false) unset($productStats[$i]); } } if(isset($this->config->bizVersion)) list($fields, $productStats) = $this->loadModel('workflowfield')->appendDataFromFlow($fields, $productStats); $this->post->set('fields', $fields); $this->post->set('rows', $productStats); $this->post->set('kind', 'product'); $this->fetch('file', 'export2' . $this->post->fileType, $_POST); } $this->display(); } /** * Doc for compatible. * * @param int $productID * @access public * @return void */ public function doc($productID) { $this->locate($this->createLink('doc', 'objectLibs', "type=product&objectID=$productID&from=product")); } /** * Build of product. * * @param int $productID * @access public * @return void */ public function build($productID = 0, $branch = 0) { $this->app->loadLang('build'); $this->session->set('productList', $this->app->getURI(true)); /* Get all product list. Locate to the create product page if there is no product. */ $this->products = $this->product->getPairs('', $this->session->PRJ); if(empty($this->products) and strpos('create|view', $this->methodName) === false) $this->locate($this->createLink('product', 'create')); /* Get current product. */ $productID = $this->product->saveState($productID, $this->products); $product = $this->product->getById($productID); $this->product->setMenu($this->products, $productID, $branch); /* Set menu.*/ $this->session->set('buildList', $this->app->getURI(true)); $this->view->title = $product->name . $this->lang->colon . $this->lang->product->build; $this->view->position[] = $this->lang->product->build; $this->view->products = $this->products; $this->view->product = $product; $this->view->builds = $this->dao->select('*')->from(TABLE_BUILD)->where('product')->eq($productID) ->beginIF($branch)->andWhere('branch')->eq($branch)->fi() ->andWhere('deleted')->eq(0) ->fetchAll(); $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->display(); } /** * Set product id to session in ajax * * @param int $productID * @access public * @return void */ public function ajaxSetState($productID) { $this->session->set('product', (int)$productID); $this->send(array('result' => 'success', 'productID' => $this->session->product)); } }