tao.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * The tao file of productplan module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Yanyi Cao <caoyanyi@easycorp.ltd>
  8. * @package productplan
  9. * @link https://www.zentao.net
  10. */
  11. class productplanTao extends productplanModel
  12. {
  13. /**
  14. * 获取产品计划列表。
  15. * Get plan list.
  16. *
  17. * @param array $productIdList
  18. * @param string $branch
  19. * @param string $browseType
  20. * @param string $param
  21. * @param string $orderBy
  22. * @param object $pager
  23. * @access protected
  24. * @return array
  25. */
  26. protected function getPlanList($productIdList, $branch = '', $browseType = '', $param = '', $orderBy = '', $pager = null)
  27. {
  28. return $this->dao->select('*')->from(TABLE_PRODUCTPLAN)
  29. ->where('deleted')->eq(0)
  30. ->andWhere('product')->in($productIdList)
  31. ->beginIF(!empty($branch) && $branch != 'all')->andWhere('branch')->eq($branch)->fi()
  32. ->beginIF(!in_array($browseType, array('all', 'undone', 'bySearch', 'review')))->andWhere('status')->eq($browseType)->fi()
  33. ->beginIF($browseType == 'undone')->andWhere('status')->in('wait,doing')->fi()
  34. ->beginIF($browseType == 'bySearch')->andWhere($this->session->productplanQuery)->fi()
  35. ->beginIF(strpos($param, 'skipparent') !== false)->andWhere('parent')->ne(-1)->fi()
  36. ->orderBy($orderBy)
  37. ->page($pager)
  38. ->fetchAll('id', false);
  39. }
  40. /**
  41. * 根据计划列表获取产品计划信息。
  42. * Get plan info by plan list.
  43. *
  44. * @param array $planID
  45. * @param int|null $productID
  46. * @access protected
  47. * @return array
  48. * @param mixed[] $planIdList
  49. */
  50. protected function getPlanProjects($planIdList, $productID = null)
  51. {
  52. if(empty($planIdList)) return [];
  53. $planProjects = [];
  54. $projects = $this->dao->select('t1.name, t2.project, t2.plan')->from(TABLE_PROJECT)->alias('t1')
  55. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id=t2.project')
  56. ->where('t1.deleted')->eq(0)
  57. ->andWhere('t1.type')->in('sprint,stage,kanban')
  58. ->beginIF(!is_null($productID))->andWhere('t2.product')->eq($productID)->fi()
  59. ->orderBy('project_desc')
  60. ->fetchAll();
  61. foreach($projects as $project)
  62. {
  63. if(empty($project->plan)) continue;
  64. $plans = array_filter(explode(',', $project->plan));
  65. foreach($plans as $planID) $planProjects[$planID][$project->project] = $project;
  66. }
  67. foreach($planIdList as $planID)
  68. {
  69. if(!isset($planProjects[$planID])) $planProjects[$planID] = [];
  70. }
  71. return $planProjects;
  72. }
  73. /**
  74. * 更新产品计划的关联信息。
  75. * Update plan related info.
  76. *
  77. * @param int $planID
  78. * @param array $storyIdList
  79. * @param bool $deleteOld
  80. * @access protected
  81. * @return bool
  82. */
  83. protected function syncLinkedStories($planID, $storyIdList, $deleteOld = true)
  84. {
  85. if($deleteOld) $this->dao->delete()->from(TABLE_PLANSTORY)->where('plan')->eq($planID)->exec();
  86. $order = 1;
  87. foreach($storyIdList as $storyID)
  88. {
  89. $order ++;
  90. $planStory = new stdclass();
  91. $planStory->plan = $planID;
  92. $planStory->story = $storyID;
  93. $planStory->order = $order;
  94. $this->dao->replace(TABLE_PLANSTORY)->data($planStory)->exec();
  95. }
  96. return !dao::isError();
  97. }
  98. }