diff --git a/module/kanban/model.php b/module/kanban/model.php index d80df97e96..70d0320758 100644 --- a/module/kanban/model.php +++ b/module/kanban/model.php @@ -31,6 +31,8 @@ class kanbanModel extends model if(empty($lanes)) return array(); + foreach($lanes as $lane) $this->updateCards($lane); + $columns = $this->dao->select('*')->from(TABLE_KANBANCOLUMN) ->where('deleted')->eq(0) ->andWhere('lane')->in(array_keys($lanes)) @@ -248,93 +250,97 @@ class kanbanModel extends model /** * Update column cards. * - * @param int $executionID - * @param string $objectType story|bug|task - * @param object $columns + * @param object $lane * @access public * @return void */ - public function updateCards($executionID, $objectType, $columns) + public function updateCards($lane) { - $objects = array(); - if($objectType == 'story') $objects = $this->loadModel('story')->getExecutionStories($executionID); - if($objectType == 'bug') $objects = $this->loadModel('bug')->getExecutionBugs($executionID); - if($objectType == 'task') $objects = $this->loadModel('execution')->getKanbanTasks($executionID); - if($objectType == 'story') + $laneType = $lane->type; + $executionID = $lane->exeuction; + $cardPairs = $this->dao->select('*')->from(TABLE_KANBANCOLUMN) + ->where('deleted')->eq(0) + ->andWhere('lane')->eq($lane->id) + ->fetchPairs('type' ,'cards'); + + if($laneType == 'story') { - $data = new stdClass(); - foreach($columns as $colID => $col) + $stories = $this->loadModel('story')->getExecutionStories($executionID); + foreach($stories as $storyID => $story) { - foreach($objects as $storyID => $story) + foreach($this->config->kanban->storyColumnStageList as $colType => $stage) { - if($col->type == 'backlog' and $story->status == 'active' and $story->stage == 'projected') $data->cards .= $storyID . ','; - - if($colType == 'closed' and $story->status == 'closed' and $story->stage == 'closed') $data->cards .= $storyID . ','; - - if($story->stage == $colType and strpos(',backlog,closed,', $colType) === false and $story->status == 'active') $data->cards .= $storyID . ','; - } - if(!empty($data->cards)) $data->cards = ',' . $data->cards; - } - - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - if($colType == 'develop') $devColumnID = $this->dao->lastInsertId(); - if($colType == 'test') $testColumnID = $this->dao->lastInsertId(); - } - elseif($type == 'bug') - { - foreach($this->lang->kanban->bugColumn as $colType => $name) - { - $data = new stdClass(); - $data->lane = $laneID; - $data->name = $name; - $data->type = $colType; - $data->cards = ''; - if(strpos(',fixing,fixed,', $colType) !== false) $data->parent = $resolvingColumnID; - if(strpos(',testing,tested,', $colType) !== false) $data->parent = $testColumnID; - if(strpos(',resolving,fixing,test,testing,tested,', $colType) === false) - { - foreach($objects as $bugID => $bug) + if(strpos(',ready,develop,test,', $colType) !== false) continue; + if($colType == 'backlog' and $story->stage == $stage and strpos($cardPairs['ready'], ",$storyID,") === false and strpos($cardPairs['backlog'], ",$storyID,") === false) { - if($colType == 'unconfirmed' and $bug->status == 'active' and $bug->confirmed == 0) $data->cards .= $bugID . ','; - - if($colType == 'confirmed' and $bug->status == 'active' and $bug->confirmed == 1) $data->cards .= $bugID . ','; - - if($colType == 'fixed' and $bug->status == 'resolved') $data->cards .= $bugID . ','; - - if($colType == 'closed' and $bug->status == 'closed') $data->cards .= $bugID . ','; + $cardPairs['backlog'] .= empty($cardPairs['backlog']) ? ',' . $storyID . ',' : $storyID . ','; + } + elseif($story->stage == $stage and strpos($cardPairs[$colType], ",$storyID,") === false) + { + $cardPairs[$colType] .= empty($cardPairs[$colType]) ? ',' . $storyID . ',' : $storyID . ','; + } + elseif($story->stage != $stage and strpos($cardPairs[$colType], ",$storyID,") !== false) + { + $cardPairs[$colType] = str_replace(",$storyID,", ',', $cardPairs[$colType]); } - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - if($colType == 'resolving') $resolvingColumnID = $this->dao->lastInsertId(); - if($colType == 'test') $testColumnID = $this->dao->lastInsertId(); } } } - elseif($type == 'task') + elseif($laneType == 'bug') { - foreach($this->lang->kanban->taskColumn as $colType => $name) + $bugs = $this->loadModel('bug')->getExecutionBugs($executionID); + foreach($bugs as $bugID => $bug) { - $data = new stdClass(); - $data->lane = $laneID; - $data->name = $name; - $data->type = $colType; - $data->cards = ''; - if(strpos(',developing,developed,', $colType) !== false) $data->parent = $devColumnID; - if(strpos(',develop,', $colType) === false) + foreach($this->config->kanban->bugColumnStatusList as $colType => $status) { - foreach($objects as $taskID => $task) + if(strpos(',resolving,fixing,test,testing,tested,', $colType) !== false) continue; + if($colType == 'unconfirmed' and $bug->status == $status and $bug->confirmed == 0 and strpos($cardPairs['unconfirmed'], ",$bugID,") === false and strpos($cardPairs['fixing'], ",$bugID,") === false) { - if($colType == 'developing' and $task->status == 'doing') $data->cards .= $taskID . ','; - - if($colType == 'developed' and $task->status == 'done') $data->cards .= $taskID . ','; - - if(strpos(',wait,pause,canceled,closed,', $colType) !== false and $task->status == $colType) $data->cards .= $taskID . ','; + $cardPairs['unconfirmed'] .= empty($cardPairs['unconfirmed']) ? ',' . $bugID . ',' : $bugID . ','; + } + elseif($colType == 'confirmed' and $bug->status == $status and $bug->confirmed == 1 and strpos($cardPairs['confirmed'], ",$bugID,") === false and strpos($cardPairs['fixing'], ",$bugID,") === false) + { + $cardPairs['confirmed'] .= empty($cardPairs['confirmed']) ? ',' . $bugID . ',' : $bugID . ','; + } + elseif($colType == 'fixed' and $bug->status == $status and strpos($cardPairs['fixed'], ",$bugID,") === false and strpos($cardPairs['testing'], ",$bugID,") === false and strpos($cardPairs['tested'], ",$bugID,") === false) + { + $cardPairs['confirmed'] .= empty($cardPairs['confirmed']) ? ',' . $bugID . ',' : $bugID . ','; + } + elseif($bug->status == $status and strpos($cardPairs[$colType], ",$bugID,") === false) + { + $cardPairs[$colType] .= empty($cardPairs[$colType]) ? ',' . $bugID . ',' : $bugID . ','; + } + elseif($bug->status != $status and strpos($cardPairs[$colType], ",$bugID,") !== false) + { + $cardPairs[$colType] = str_replace(",$bugID,", ',', $cardPairs[$colType]); } - - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - if($colType == 'develop') $devColumnID = $this->dao->lastInsertId(); } } } + elseif($laneType == 'task') + { + $tasks = $this->loadModel('execution')->getKanbanTasks($executionID); + foreach($tasks as $taskID => $task) + { + foreach($this->config->kanban->taskColumnStatusList as $colType => $status) + { + if($colType == 'develop') continue; + if($task->status == $status and strpos($cardPairs[$colType], ",$taskID,") === false) + { + $cardPairs[$colType] .= empty($cardPairs[$colType]) ? ',' . $taskID . ',' : $taskID . ','; + } + elseif($task->status != $status and strpos($cardPairs[$colType], ",$taskID,") !== false) + { + $cardPairs[$colType] = str_replace(",$taskID,", ',', $cardPairs[$colType]); + } + } + } + } + + foreach($cardPairs as $colType => $cards) + { + $this->dao->update(TABLE_KANBANCOLUMN)->set('cards')->eq($cards)->where('lane')->eq($lane->id)->andWhere('type')->eq($colType)->exec(); + } } /**