browse.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. class product extends control
  3. {
  4. /**
  5. * @param int $productID
  6. * @param int $branch
  7. * @param string $browseType
  8. * @param int $param
  9. * @param string $storyType
  10. * @param string $orderBy
  11. * @param int $recTotal
  12. * @param int $recPerPage
  13. * @param int $pageID
  14. * @param int $projectID
  15. * @param string $from
  16. * @param int $blockID
  17. */
  18. public function browse($productID = 0, $branch = 0, $browseType = '', $param = 0, $storyType = 'story', $orderBy = '', $recTotal = 0, $recPerPage = 20, $pageID = 1, $projectID = 0, $from = 'product', $blockID = 0)
  19. {
  20. /* Load datatable and execution. */
  21. $this->loadModel('execution');
  22. $this->loadModel('user');
  23. $isProjectStory = $this->app->rawModule == 'projectstory';
  24. $projectProducts = $this->loadModel('product')->getProducts($projectID);
  25. $productPlans = $this->execution->getPlans(array_keys($projectProducts));
  26. $this->products = array();
  27. foreach($projectProducts as $productID => $product) $this->products[$productID] = $product->name;
  28. reset($projectProducts);
  29. if(empty($productID)) $productID = key($projectProducts);
  30. $product = $projectProducts[$productID];
  31. $showBranch = $this->loadModel('branch')->showBranch($productID, 0, $projectID);
  32. /* Set menu. */
  33. $this->loadModel('project')->setMenu($projectID);
  34. $branches = $this->loadModel('branch')->getList($productID, $projectID, 'all');
  35. $branch = ($this->cookie->preBranch and $branch === 0 and isset($branches[$this->cookie->preBranch])) ? $this->cookie->preBranch : $branch;
  36. $branchID = $branch;
  37. /* Lower browse type. */
  38. $browseType = strtolower($browseType);
  39. /* Set product, module and query. */
  40. setcookie('preProductID', $productID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
  41. setcookie('preBranch', $branch, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
  42. if($this->cookie->preProductID != $productID or $this->cookie->preBranch != $branch)
  43. {
  44. $_COOKIE['storyModule'] = 0;
  45. setcookie('storyModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  46. }
  47. if($browseType == 'bymodule' or $browseType == '')
  48. {
  49. setcookie('storyModule', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  50. if($this->app->tab == 'project') setcookie('storyModuleParam', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  51. $_COOKIE['storyBranch'] = 'all';
  52. setcookie('storyBranch', 'all', 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  53. if($browseType == '') setcookie('treeBranch', $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  54. }
  55. $cookieModule = $this->app->tab == 'project' ? $this->cookie->storyModuleParam : $this->cookie->storyModule;
  56. $moduleID = ($browseType == 'bymodule') ? (int)$param : (($browseType == 'bysearch') ? 0 : ($cookieModule ? $cookieModule : 0));
  57. $queryID = ($browseType == 'bysearch') ? (int)$param : 0;
  58. /* Set moduleTree. */
  59. $createModuleLink = $storyType == 'story' ? 'createStoryLink' : 'createRequirementLink';
  60. if($browseType == '')
  61. {
  62. setcookie('treeBranch', $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, false);
  63. $browseType = 'unclosed';
  64. }
  65. else
  66. {
  67. $branch = $this->cookie->treeBranch ? $this->cookie->treeBranch : 0;
  68. }
  69. /* Process the order by field. */
  70. if(!$orderBy) $orderBy = $this->cookie->productStoryOrder ? $this->cookie->productStoryOrder : 'id_desc';
  71. setcookie('productStoryOrder', $orderBy, 0, $this->config->webRoot, '', $this->config->cookieSecure, true);
  72. /* Load pager. */
  73. $this->app->loadClass('pager', $static = true);
  74. if($this->app->getViewType() == 'xhtml') $recPerPage = 10;
  75. $pager = new pager($recTotal, $recPerPage, $pageID);
  76. /* Display of branch label. */
  77. $showBranch = $this->loadModel('branch')->showBranch($productID);
  78. $product = $this->product->getById($productID);
  79. $project = $projectID ? $this->loadModel('project')->getByID($projectID) : null;
  80. /* Get stories. */
  81. $stories = $this->productZen->getStories($projectID, $productID, $branchID, $moduleID, $param, $storyType, $browseType, $orderBy, $pager);
  82. /* Process the sql, get the conditon partion, save it to session. */
  83. $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story', ($browseType != 'bysearch' and $browseType != 'reviewbyme' and $this->app->rawModule != 'projectstory'));
  84. /* Save session. */
  85. $this->productZen->saveSession4Browse($product, $browseType);
  86. /* Build search form. */
  87. $this->productZen->buildSearchFormForBrowse($project, $projectID, $productID, $branch, $param, $storyType, $browseType, $isProjectStory, '', $blockID);
  88. $showModule = !empty($this->config->datatable->productBrowse->showModule) ? $this->config->datatable->productBrowse->showModule : '';
  89. $productName = ($this->app->rawModule == 'projectstory' and empty($productID)) ? $this->lang->product->all : $this->products[$productID];
  90. /* Assign. */
  91. $this->view->title = $productName . $this->lang->hyphen . $this->lang->product->browse;
  92. $this->view->moduleID = $moduleID;
  93. $this->view->pager = $pager;
  94. $this->view->orderBy = $orderBy;
  95. $this->view->moduleTree = $this->productZen->getModuleTree($projectID, $productID, $branch, $param, $storyType, $browseType);
  96. $this->view->param = $param;
  97. $this->view->from = $from;
  98. $this->view->blockID = $blockID;
  99. $this->productZen->assignBrowseData($stories, $browseType, $storyType, $isProjectStory, $product, $project, $branch, $branchID);
  100. }
  101. }