diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-02-18 13:38:51 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-02-18 13:38:51 -0500 |
commit | 49c8e5c1be15b9732023703473bb7e15864770f6 (patch) | |
tree | a4dcf83e0601fd734d44ad67e36299921959c3c2 /app/Model | |
parent | 948b7fbaaa58c0a825938f7e8bda9a07ec39239b (diff) |
Prevent people to remove swimlanes that contains tasks
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/ColumnModel.php | 4 | ||||
-rw-r--r-- | app/Model/ProjectModel.php | 2 | ||||
-rw-r--r-- | app/Model/SwimlaneModel.php | 34 |
3 files changed, 37 insertions, 3 deletions
diff --git a/app/Model/ColumnModel.php b/app/Model/ColumnModel.php index da5ea856..05f76fb9 100644 --- a/app/Model/ColumnModel.php +++ b/app/Model/ColumnModel.php @@ -121,13 +121,13 @@ class ColumnModel extends Base } /** - * Get all columns with tasks count + * Get all columns with task count * * @access public * @param integer $project_id Project id * @return array */ - public function getAllWithTasksCount($project_id) + public function getAllWithTaskCount($project_id) { return $this->db->table(self::TABLE) ->columns('id', 'title', 'position', 'task_limit', 'description', 'hide_in_dashboard', 'project_id') diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php index a4d75a0b..b88a8c8b 100644 --- a/app/Model/ProjectModel.php +++ b/app/Model/ProjectModel.php @@ -270,7 +270,7 @@ class ProjectModel extends Base */ public function getColumnStats(array &$project) { - $project['columns'] = $this->columnModel->getAllWithTasksCount($project['id']); + $project['columns'] = $this->columnModel->getAllWithTaskCount($project['id']); $project['nb_active_tasks'] = 0; foreach ($project['columns'] as $column) { diff --git a/app/Model/SwimlaneModel.php b/app/Model/SwimlaneModel.php index 30012096..2b3be912 100644 --- a/app/Model/SwimlaneModel.php +++ b/app/Model/SwimlaneModel.php @@ -164,6 +164,40 @@ class SwimlaneModel extends Base } /** + * Get all swimlanes with task count + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getAllWithTaskCount($project_id) + { + $result = array( + 'active' => array(), + 'inactive' => array(), + ); + + $swimlanes = $this->db->table(self::TABLE) + ->columns('id', 'name', 'description', 'project_id', 'position', 'is_active') + ->subquery("SELECT COUNT(*) FROM ".TaskModel::TABLE." WHERE swimlane_id=".self::TABLE.".id AND is_active='1'", 'nb_open_tasks') + ->subquery("SELECT COUNT(*) FROM ".TaskModel::TABLE." WHERE swimlane_id=".self::TABLE.".id AND is_active='0'", 'nb_closed_tasks') + ->eq('project_id', $project_id) + ->asc('position') + ->asc('name') + ->findAll(); + + foreach ($swimlanes as $swimlane) { + if ($swimlane['is_active']) { + $result['active'][] = $swimlane; + } else { + $result['inactive'][] = $swimlane; + } + } + + return $result; + } + + /** * Get list of all swimlanes * * @access public |