riskkanban.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 创建执行风险看板列。
  4. * Create execution risk columns.
  5. *
  6. * @param int $laneID
  7. * @param string $type
  8. * @param int $executionID
  9. * @access public
  10. * @return void
  11. */
  12. public function createExecutionRiskColumns($laneID, $type, $executionID)
  13. {
  14. $columns = $this->lang->kanban->riskColumn;
  15. if(empty($columns)) return;
  16. foreach($columns as $colType => $name)
  17. {
  18. $data = new stdclass();
  19. $data->name = $name;
  20. $data->color = '#333';
  21. $data->type = $colType;
  22. $data->region = 0;
  23. $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec();
  24. $colID = $this->dao->lastInsertId();
  25. $this->addKanbanCell($executionID, $laneID, $colID, $type);
  26. }
  27. }
  28. /**
  29. * 向风险卡片中添加字段。
  30. * Append risk field to cardsData.
  31. *
  32. * @param array $cardsData
  33. * @param array $risks
  34. * @access public
  35. * @return array
  36. */
  37. public function appendRiskField($cardsData, $risks)
  38. {
  39. $this->loadModel('risk');
  40. $priLevel = array('high' => 1, 'middle' => 2, 'low' => 3);
  41. foreach($cardsData as $laneID => $dataGroup)
  42. {
  43. foreach($dataGroup as $groupID => $datas)
  44. {
  45. foreach($datas as $index => $data)
  46. {
  47. $data['priLevel'] = zget($priLevel, $data['pri'], 3);
  48. $data['pri'] = zget($this->lang->risk->priList, $data['pri'], $data['pri']);
  49. $strategy = $risks[$data['id']]->strategy;
  50. $data['strategy'] = $strategy ? ($this->lang->risk->strategy . ": " . zget($this->lang->risk->strategyList, $strategy)) : '';
  51. $datas[$index] = $data;
  52. }
  53. $dataGroup[$groupID] = $datas;
  54. }
  55. $cardsData[$laneID] = $dataGroup;
  56. }
  57. return $cardsData;
  58. }
  59. /**
  60. * 更新专业研发看板中的风险泳道上的卡片。
  61. * Update card of risk lane in RD kanban.
  62. *
  63. * @param array $cardPairs
  64. * @param int $executionID
  65. * @param string $otherCardList
  66. * @access public
  67. * @return array
  68. */
  69. public function refreshRiskCards($cardPairs, $executionID, $otherCardList)
  70. {
  71. $risks = $this->loadModel('risk')->getKanbanRisks($executionID, explode(',', $otherCardList));
  72. foreach($risks as $riskID => $risk)
  73. {
  74. foreach($this->config->kanban->riskColumnStatusList as $colType => $status)
  75. {
  76. if(!isset($cardPairs[$colType])) continue;
  77. if($risk->status != $status and strpos($cardPairs[$colType], ",$riskID,") !== false)
  78. {
  79. $cardPairs[$colType] = str_replace(",$riskID,", ',', $cardPairs[$colType]);
  80. }
  81. if(strpos(',active,track,', $colType) !== false) continue;
  82. if($risk->status == $status and strpos($cardPairs[$colType], ",$riskID,") === false)
  83. {
  84. $cardPairs[$colType] = empty($cardPairs[$colType]) ? ",$riskID," : ",$riskID". $cardPairs[$colType];
  85. }
  86. }
  87. if($risk->status == 'active' and strpos($cardPairs['active'], ",$riskID,") === false and strpos($cardPairs['track'], ",$riskID,") === false)
  88. {
  89. $cardPairs['active'] = empty($cardPairs['active']) ? ",$riskID," : ",$riskID" . $cardPairs['active'];
  90. }
  91. }
  92. return $cardPairs;
  93. }
  94. /**
  95. * Copy code from kanban control.php ajaxMoveCard function。
  96. *
  97. * @param array $outputs
  98. * @access public
  99. * @return void
  100. */
  101. public function moveRiskCard($outputs)
  102. {
  103. $cardID = (int)$outputs['objectID'];
  104. $executionID = (int)$outputs['execution'];
  105. $fromColID = (int)$outputs['fromColID'];
  106. $toColID = (int)$outputs['toColID'];
  107. $fromLaneID = $toLaneID = (int)$outputs['laneID'];
  108. $browseType = $outputs['browseType'];
  109. $groupBy = $outputs['groupBy'];
  110. $this->loadModel('kanban');
  111. $fromCell = $this->getExecutionFromCell($cardID, $executionID, $fromColID, $fromLaneID, $groupBy, $browseType);
  112. $toCell = $this->getExecutionToCell($executionID, $toColID, $toLaneID);
  113. $fromCards = str_replace(",$cardID,", ',', $fromCell->cards);
  114. $fromCards = $fromCards == ',' ? '' : $fromCards;
  115. $toCards = ',' . implode(',', array_unique(array_filter(explode(',', $toCell->cards)))) . ",$cardID,";
  116. $this->updateExecutionCell($executionID, $fromColID, $fromLaneID, $fromCards);
  117. $this->updateExecutionCell($executionID, $toColID, $toLaneID, $toCards);
  118. }
  119. /**
  120. * 获取执行下看板的来源看板Cell。
  121. * Get source kanban cell of execution.
  122. *
  123. * @param int $cardID
  124. * @param int $executionID
  125. * @param int $fromColID
  126. * @param int $fromLaneID
  127. * @param string $groupBy
  128. * @param string $browseType
  129. * @access public
  130. * @return object
  131. */
  132. protected function getExecutionFromCell($cardID, $executionID, $fromColID, $fromLaneID, $groupBy, $browseType)
  133. {
  134. return $this->dao->select('id, cards, lane')->from(TABLE_KANBANCELL)
  135. ->where('kanban')->eq($executionID)
  136. ->andWhere('`column`')->eq($fromColID)
  137. ->beginIF(!$groupBy or $groupBy == 'default')->andWhere('lane')->eq($fromLaneID)->fi()
  138. ->beginIF($groupBy and $groupBy != 'default')
  139. ->andWhere('type')->eq($browseType)
  140. ->andWhere('cards')->like("%,$cardID,%")
  141. ->fi()
  142. ->fetch();
  143. }
  144. /**
  145. * 获取执行下看板的目标看板Cell。
  146. * Get target kanban cell of execution.
  147. *
  148. * @param int $executionID
  149. * @param int $toColID
  150. * @param int $toLaneID
  151. * @access public
  152. * @return object
  153. */
  154. protected function getExecutionToCell($executionID, $toColID, $toLaneID)
  155. {
  156. return $this->dao->select('id, cards')->from(TABLE_KANBANCELL)
  157. ->where('kanban')->eq($executionID)
  158. ->andWhere('lane')->eq($toLaneID)
  159. ->andWhere('`column`')->eq($toColID)
  160. ->fetch();
  161. }